[Vimperator] macro.patch (solved partly)

calmar mac at calmar.ws
Wed Dec 12 20:57:04 PST 2007


On Thu, Dec 13, 2007 at 05:10:21AM +0100, calmar wrote:

http://www.calmar.ws/tmp/macro.patch

so, it works now with the @ + ARGUMENT

i hope it does not break other stuff. may please test, I think I'm
not used to such mappings (or am i?), so I can't test it nicely.

the thing I did was:

+                var tmpMap = vimperator.input.pendingArgMap;
+                vimperator.input.pendingArgMap = null;


i set it to null before it executed the thing..

hm.

So in the hope that's better now and other stuff still works
nicely... it's about to have the 'wait the page until loaded'
thing..

cheers
marco

-- 
   (o_  It rocks: LINUX + Command-Line-Interface
   //\
   V_/_                     http://www.calmar.ws
-------------- next part --------------
? macro.patch
Index: events.js
===================================================================
RCS file: /cvs/vimperator/src/content/events.js,v
retrieving revision 1.36
diff -u -r1.36 events.js
--- events.js	12 Dec 2007 06:00:38 -0000	1.36
+++ events.js	13 Dec 2007 04:51:27 -0000
@@ -245,12 +245,43 @@
         }
     }
 
+    var isRecording = false;
+    var recordCount, recordRegister; 
+    var recordMacros = {};
+
     /////////////////////////////////////////////////////////////////////////////}}}
     ////////////////////// PUBLIC SECTION //////////////////////////////////////////
     /////////////////////////////////////////////////////////////////////////////{{{
 
     var eventManager = {
 
+        recordToggle: function ()
+        {
+            isRecording = !isRecording;
+            if (isRecording) // initialise
+            {
+                recordStart = true;
+                recordCount = 0;
+                recordRegister = reg;
+            }
+            else
+            {
+                // XXX: assumes record is mapped to a single key -> strip -1 since recording ended
+                recordMacros[recordRegister] = recordMacros[recordRegister].slice(0, -1); 
+            }
+            return isRecording;
+        },
+
+        recordResult: function ()
+        {
+            return [recordRegister, recordMacros[recordRegister]];
+        },
+
+        recordResultReg: function (reg)
+        {
+            return recordMacros[reg] || null;
+        },
+
         wantsModeReset: true, // used in onFocusChange since Firefox is so buggy here
 
         destroy: function ()
@@ -570,6 +601,29 @@
             if (!key)
                  return true;
 
+            if (isRecording)
+            {
+                if (++recordCount == 1)
+                {
+                    if (!/^[a-zA-Z0-9]$/.test(key))
+                    {
+                        vimperator.echoerr("Register [a-zA-Z0-9] required");
+                        isRecording = false;
+                    }
+                    else
+                    {
+                        recordRegister = key;
+                        recordMacros[recordRegister] = "";
+                        vimperator.echo("record into register " + recordRegister + "...");
+                    }
+                    event.preventDefault(); // XXX: or howto stop that key beeing processed?
+                    event.stopPropagation();
+                    return true;
+                }
+                if (!vimperator.mappings.hasMap(vimperator.mode , vimperator.input.buffer + key))
+                    recordMacros[recordRegister] += key;
+            } 
+
             var stop = true; // set to false if we should NOT consume this event but let also firefox handle it
 
             var win =  document.commandDispatcher.focusedWindow;
@@ -673,11 +727,11 @@
             else if (vimperator.input.pendingArgMap)
             {
                 vimperator.input.buffer = "";
-
+                var tmpMap = vimperator.input.pendingArgMap;
+                vimperator.input.pendingArgMap = null;
                 if (key != "<Esc>" && key != "<C-[>")
-                    vimperator.input.pendingArgMap.execute(null, vimperator.input.count, key);
+                    tmpMap.execute(null, vimperator.input.count, key);
 
-                vimperator.input.pendingArgMap = null;
             }
             else if (map)
             {
Index: mappings.js
===================================================================
RCS file: /cvs/vimperator/src/content/mappings.js,v
retrieving revision 1.64
diff -u -r1.64 mappings.js
--- mappings.js	12 Dec 2007 05:27:11 -0000	1.64
+++ mappings.js	13 Dec 2007 04:51:29 -0000
@@ -1290,7 +1290,41 @@
             help: "Repeat the last search 1 time (until count is supported) in the opposite direction."
         }
     ));
-
+    addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["q"],
+        function () 
+        { 
+            var reg, macro;
+            if (!vimperator.events.recordToggle())
+            {
+                [reg, macro] = vimperator.events.recordResult();
+                vimperator.echo("Register '" + reg + " recorded: " + macro);
+            } 
+        },
+        {
+            shortHelp: "record a macro into a register",
+            help: "record a macro; the following letter [a-zA-Z0-9] are valid registers<br />" +
+                  ":mkvimperatorrc will same then into configuration file.",
+        }
+    ));
+    addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["@"], 
+        function (arg) 
+        { 
+            var  macro = vimperator.events.recordResultReg(arg);
+            if (!macro)
+            {
+                vimperator.echoerr("Register '" + arg + " not set");
+                return false; //XXX: or no return at all?
+            }
+            else
+            {
+                vimperator.events.feedkeys(macro, true);  // true -> noremap
+            }
+        },
+        {
+            shortHelp: "execute a register/macro",
+            flags: vimperator.Mappings.flags.ARGUMENT
+        }
+    ));
     // }}}
     // HINTS mode
     // {{{


More information about the Vimperator mailing list