[Vimperator] macro.patch
calmar
mac at calmar.ws
Wed Dec 12 19:59:17 PST 2007
On Mon, Dec 10, 2007 at 05:55:01PM +0100, Martin Stubenschrott wrote:
> I personally would change toggleRecording to startRecording(register) which is
> issued after pressing q<arg>. And stopping is done inside onKeyPress
> (hardcoded) when q is pressed and v.modes.isRecording == true.
>
not yet done....
but:
so
http://www.calmar.ws/tmp/macro.patch (or attached)
+ if (!vimperator.mappings.hasMap(vimperator.mode ,
vimperator.input.buffer + key))
+ recordMacros[recordRegister] += key;
+ }
I din't see any other possibility, I with limited knowledge etc <-
with that it about works so far.
but i had to hardcode @q
does not work nicely with the ARGUMENT flag in a similar way it
did not nicely with with that on the q.
e.g. I make a @q to execute the q macro. I then call the @ <-
for any key what is in the macro again. mostly with: no such
macro/register defined.
it should be possible to say: ok. we got ONE argument, it's
finished now. Maye a one liner even...
it might/would be possible to get q + ARGUMENT possible with
adding: at the position where it checks if that flag exists for
the mapping, to additionaly check if the macro-counter is >1 or
similar .etc. maybe. would still not solve the @ thing.
for the @ what feeds lot of stuff (and for every thing it gets
called itself again, since the ARGUMENT keeps true for the @
(does taht make sense??? not really)) .. about another flag in
the mapping what limits ...
anyway... any hint appreciated.
then the thing with the waiting for the site. what again to use
there?
There is the progress-bar, so vimperator must know in some way
when a site has loaded?
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 03:32:08 -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,30 @@
if (!key)
return true;
+ ////////////////////// FIXME: the whole if (isRe...) block
+ 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;
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 03:32:10 -0000
@@ -1290,7 +1290,44 @@
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.",
+ }
+ ));
+ // FIXME: seems to call itself always for each key what it again puts into feedkeys()..
+ addDefaultMap(new vimperator.Map([vimperator.modes.NORMAL], ["@q"],
+ //function (arg)
+ function ()
+ {
+ var arg = "q";
+ 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