From b50c8a673ee944b31c453e79f61e6b24fd883870 Mon Sep 17 00:00:00 2001
From: suVene
Date: Wed, 27 Jul 2011 20:07:39 +0900
Subject: add してよかったんだっけ?
htttp://vimperator.g.hatena.ne.jp/voidy21/20100125/1264450264
---
char-hints-mod2.js | 311 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 311 insertions(+)
create mode 100644 char-hints-mod2.js
(limited to 'char-hints-mod2.js')
diff --git a/char-hints-mod2.js b/char-hints-mod2.js
new file mode 100644
index 0000000..fbb39a0
--- /dev/null
+++ b/char-hints-mod2.js
@@ -0,0 +1,311 @@
+// PLUGIN_INFO//{{{
+var PLUGIN_INFO =
+
+ {NAME}
+ character hint mode.
+ hogelog
+ 0.3.2
+ 2.3pre 2010/01/26
+ 2.4pre
+ http://github.com/vimpr/vimperator-plugins/blob/master/char-hints-mod2.js
+
+
+;
+//}}}
+
+(function () {
+ (function(){
+ //override _showHints
+ const key = "Hints.prototype._showHints";
+ let conf = userContext[key],original;
+ if(conf) original = conf;
+ else original = userContext[key] = Hints.prototype._showHints;
+
+ const target = "String(hintnum).indexOf(String(activeHint)) == 0";
+
+ let source = original.toSource();
+ if(source.indexOf(target)>=0){
+ source = source.replace(target,
+ "num2chars(hintnum).indexOf(num2chars(activeHint)) == 0");
+ Hints.prototype._showHints = eval("(function() "+source+")()");
+ }else{
+ liberator.echoerr(new Error("_showHints override failed!"));
+ }
+ })()
+ ;
+ (function(){
+ const source = Hints.prototype._checkUnique.toSource();
+ if(source.indexOf("10")<0) return;
+ Hints.prototype._checkUnique = eval("(function() "+source.replace("10",<>hintchars.length>)+")()");
+ })()
+ ;
+
+ const DEFAULT_HINTCHARS = "HJKLASDFGYUIOPQWERTNMZXCVB";
+ const hintContext = modules.hints;
+
+ let hintchars = DEFAULT_HINTCHARS;
+ let inputCase = function(str) str.toUpperCase();
+ let inputRegex = /[A-Z]/;
+ let showCase = function(str) str.toUpperCase();
+ let getStartCount = function() 0;
+
+ let timer = null;
+
+ function chars2num(chars) //{{{
+ {
+ let num = 0;
+ hintchars = inputCase(hintchars);
+ let base = hintchars.length;
+ for(let i=0,l=chars.length;i0);
+
+ return chars;
+ } //}}}
+ function getAdjustStartCount(base, count) //{{{
+ {
+ if(count < base) {
+ return 0;
+ } else if(count >= Math.pow(base, 2)) {
+ return base;
+ }
+ var start = Math.floor(count / base);
+ var adjust = count + start;
+ var next_start;
+ while(start != (next_start = Math.floor(adjust / base))) {
+ adjust += start;
+ start = next_start;
+ }
+ return start;
+ } //}}}
+ function getCharHints(win) //{{{
+ {
+ let hints = [];
+ (function (win) {
+ let elems = [elem for(elem in util.evaluateXPath('//*[@liberator:highlight="Hint" and @number]', win.document))];
+ hints = hints.concat(elems);
+ Array.forEach(win.frames, arguments.callee);
+ })(win);
+ return hints;
+ } //}}}
+ function showCharHints(hints) //{{{
+ {
+ let start = getStartCount(hintchars.length, hints.length);
+ for(let i=0,len=hints.length;i0) processHintInput(hintInput, hints);
+ }, //}}}
+ onEvent: function (event) //{{{
+ {
+ if(/^\d$/.test(events.toString(event))) {
+ charhints.onInput(event);
+ } else {
+ charhints.original.onEvent.apply(hintContext,arguments);
+ clearOriginalTimeout();
+ statusline.updateInputBuffer(hintInput);
+ }
+ }, //}}}
+ processHints: function (followFirst) //{{{
+ {
+ // don't followFirst if processHints call from
+ // charhints.original.onEvent(alt) in processHintInput
+ let caller = arguments.callee.caller;
+ if(caller == charhints.original.onEvent && caller.caller == processHintInput)
+ return charhints.original.processHints.apply(hintContext,[false]);
+
+ return charhints.original.processHints.apply(hintContext,arguments);
+ }, //}}}
+ };
+
+ if(!charhints.original) {
+ charhints.original = {
+ show: hints.show,
+ onInput: hints._onInput,
+ onEvent: hints.onEvent,
+ processHints: hints._processHints,
+ };
+
+ charhints.install = function () //{{{
+ {
+ hints.show = charhints.show;
+ hints.onEvent = charhints.onEvent;
+ liberator.eval("_onInput = liberator.plugins.charhints.onInput", hintContext);
+ liberator.eval("_processHints = liberator.plugins.charhints.processHints", hintContext);
+
+ liberator.execute(":hi Hint::after content: attr(hintchar)", true, true);
+ if(liberator.globalVariables.hintsio) {
+ let hintsio = liberator.globalVariables.hintsio;
+ Array.forEach(hintsio, setIOType);
+ }
+ if(liberator.globalVariables.hintchars) {
+ hintchars = liberator.globalVariables.hintchars;
+ }
+ if(liberator.globalVariables.hintlabeling) {
+ switch(liberator.globalVariables.hintlabeling) {
+ default:
+ case "s":
+ getStartCount = function() 0;
+ break;
+ case "a":
+ getStartCount = getAdjustStartCount;
+ break;
+ }
+ }
+ }; //}}}
+ charhints.uninstall = function () //{{{
+ {
+ hints.show = charhints.original.show;
+ hints.onEvent = charhints.original.onEvent;
+ liberator.eval("_onInput = liberator.plugins.charhints.original.onInput", hintContext);
+ liberator.eval("_processHints = liberator.plugins.charhints.original.processHints", hintContext);
+
+ liberator.execute(":hi Hint::after content: attr(number)", true, true);
+ }; //}}}
+ }
+ charhints.install();
+})();
+
+// vim: set fdm=marker sw=4 ts=4 et fenc=utf-8:
--
cgit v1.2.3