[Vimperator] hints old -> howto plugin...

calmar mac at calmar.ws
Fri Dec 28 01:21:37 PST 2007


hi Martin,

i made up this *quick* hack hm

http://www.calmar.ws/tmp/073-Fri-screen.png
this screenshot is taken with hintchars = abcdef  (in a row, and
all on the left hand)

well, it is like the new hitns, it just translates numbers to a
hintstring and vice-versa. (and according to the hintstrings
length, uses that base/radix).

and it disables that you can search for text etc. Tab would still
work. single-hitting links are possible with a timeout etc. hm.
well. Not sure if that is better cmp. to the old hints, cleaning
that up nicely, and it would be ok for me first of all ( as a
plugin).

there is actually the vimperator.events.onEvent call in events.js
what would have to be changed; so far I am already ;)

Would you have an idea, how to make that hints-special.js to work
as a plugin - so people having to use shift for every
number (or just not used to numbers) would have a nicer experience
with vimp (then again, they could also use 0.5.3 maybe, but
anyway), and even tweak/work on the plugins themselves (what is
easier/more handy, than working on the core, I guess)

Well, I guess/hope you're as satisfied with the 0.6 hints as I'm
too, so that could still be the default.

cheers
marco

-- 
   (o_  It rocks: LINUX + Command-Line-Interface
   //\
   V_/_                     http://www.calmar.ws
-------------- next part --------------
? hints_old.js
? test.diff
Index: hints.js
===================================================================
RCS file: /cvs/vimperator/src/content/hints.js,v
retrieving revision 1.42
diff -u -r1.42 hints.js
--- hints.js	18 Dec 2007 15:05:03 -0000	1.42
+++ hints.js	28 Dec 2007 09:20:53 -0000
@@ -41,10 +41,10 @@
     var hints = [];
     var validHints = []; // store the indices of the "hints" array with valid elements
 
-    var escapeNumbers = false; // escape mode for numbers. true -> treated as hint-text
     var activeTimeout = null;  // needed for hinttimeout > 0
     var canUpdate = false;
 
+    var hintchars = "abcdef";
     // keep track of the documents which we generated the hints for
     // docs = { doc: document, start: start_index in hints[], end: end_index in hints[] }
     var docs = [];
@@ -60,7 +60,6 @@
         validHints = [];
         canUpdate = false;
         docs = [];
-        escapeNumbers = false;
 
         if (activeTimeout)
             clearTimeout(activeTimeout);
@@ -69,7 +68,7 @@
 
     function updateStatusline()
     {
-        vimperator.statusline.updateInputBuffer((escapeNumbers ? vimperator.events.getMapLeader() + " ": "") + // sign for escapeNumbers
+        vimperator.statusline.updateInputBuffer(("") +
                 (hintString ? "\"" + hintString + "\"" : "") +
                 (hintNumber > 0 ? " <" + hintNumber + ">" : ""));
     }
@@ -329,7 +328,7 @@
                 if (!imgspan)
                     elem.style.backgroundColor = (activeHint == hintnum) ? "#88FF00" : "yellow";
                 elem.style.color = "black";
-                span.textContent = "" + (hintnum++);
+                span.textContent = number2hintchars(hintnum++); //XXXXXXXXXXX:
                 span.style.display = "inline";
                 validHints.push(elem);
             }
@@ -409,6 +408,38 @@
         reset();
     }
 
+    function hintchars2number(hintstr)
+    {
+        // convert into 'normal number then make it decimal-based
+
+        var conversion = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+        var converted = "";
+
+        // translate users hintchars into a number (conversion) 0 -> 0, 1 -> 1, ...
+        for (var i = 0; i < hintstr.length; i++)
+            converted += "" + conversion[hintchars.indexOf(hintstr[i])]; 
+
+        // add one, since hints begin with 0;
+        
+        return parseInt(converted, hintchars.length); // hintchars.length is the base/radix
+    }
+
+    function number2hintchars(nr)
+    {
+        var oldnr = nr;
+        var conversion = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+        var converted = "";
+        var tmp = "";
+
+        tmp = nr.toString(hintchars.length); // hintchars.length is the base/radix)
+
+        // translate numbers into users hintchars
+        for (var i = 0; i < tmp.length; i++)
+            converted += "" + hintchars[conversion.indexOf(tmp[i])]; 
+            
+        return converted;
+    }
+
     function processHints(followFirst)
     {
         if (validHints.length == 0)
@@ -536,7 +567,6 @@
         onEvent: function (event)
         {
             var key = vimperator.events.toString(event);
-            var followFirst = false;
 
             // clear any timeout which might be active after pressing a number
             if (activeTimeout)
@@ -548,12 +578,7 @@
             switch (key)
             {
                 case "<Return>":
-                    followFirst = true;
-                    break;
-
-                case "<Space>":
-                    hintString += " ";
-                    escapeNumbers = false;
+                    processHints(true);
                     break;
 
                 case "<Tab>":
@@ -577,15 +602,11 @@
                     return;
 
                 case "<BS>":
-                    if (hintNumber > 0 && !usedTabKey)
+                    if (hintNumber > 0)
                     {
-                        hintNumber = Math.floor(hintNumber / 10);
-                    }
-                    else if (hintString != "")
-                    {
-                        usedTabKey = false;
-                        hintNumber = 0;
+                        hintNumber = Math.floor(hintNumber / hintchars.length);
                         hintString = hintString.substr(0, hintString.length - 1);
+                        usedTabKey = false;
                     }
                     else
                     {
@@ -602,14 +623,6 @@
                     hintNumber = 0;
                     break;
 
-               case vimperator.events.getMapLeader():
-                   escapeNumbers = !escapeNumbers;
-                   if (escapeNumbers && usedTabKey) // hintNumber not used normally, but someone may wants to toggle
-                       hintNumber = 0;            // <tab>s ? reset. Prevent to show numbers not entered.
-
-                   updateStatusline();
-                   return;
-
                 default:
                     // pass any special or ctrl- etc. prefixed key back to the main vimperator loop
                     if (/^<./.test(key) || key == ":")
@@ -626,16 +639,16 @@
                         return;
                     }
 
-                    if (/^[0-9]$/.test(key) && !escapeNumbers)
+                    if (hintchars.indexOf(key) >= 0) // TODO: check if in hintchars
                     {
+                        hintString += key;
                         var oldHintNumber = hintNumber;
                         if (hintNumber == 0 || usedTabKey)
                         {
                             usedTabKey = false;
-                            hintNumber = parseInt(key, 10);
                         }
-                        else
-                            hintNumber = (hintNumber * 10) + parseInt(key, 10);
+
+                        hintNumber = hintchars2number(hintString);
 
                         updateStatusline();
 
@@ -657,7 +670,7 @@
 
                         // if we write a numeric part like 3, but we have 45 hints, only follow
                         // the hint after a timeout, as the user might have wanted to follow link 34
-                        if (hintNumber > 0 && hintNumber * 10 <= validHints.length)
+                        if (hintNumber > 0 && hintNumber * hintchars.length <= validHints.length)
                         {
                             var timeout = vimperator.options["hinttimeout"];
                             if (timeout > 0)
@@ -670,8 +683,7 @@
                         return;
                     }
 
-                    hintString += key;
-                    hintNumber = 0; // after some text input
+
                     if (usedTabKey)
                     {
                         usedTabKey = false;
@@ -681,14 +693,6 @@
 
             updateStatusline();
 
-            if (canUpdate)
-            {
-                if (docs.length == 0 && hintString.length > 0)
-                    generate();
-
-                showHints();
-                processHints(followFirst);
-            }
         }
 
     };


More information about the Vimperator mailing list