[Vimperator] patch autocommands
Martin Stubenschrott
stubenschrott at gmx.net
Tue Dec 18 07:18:40 PST 2007
On Tue, Dec 18, 2007 at 08:04:38AM +0100, calmar wrote:
> initial patch for autocommands.
Hurray :)
0.6 is becoming soooo feature packed now :), maybe we should stop after
:autocommands and fix remaining bugs before adding new stuff so that 0.6
can finally be released?
> I'm wondering why there is the ba[ck] command in the diff?
> I didn't add it really, did I? What made I wrong. maybe a new
> fresh checkout and adding the autocommands stuff?
Hmm, strange, but as told on IRC, you'll have to cvs up and merge
changes anyway :( (really sorry for that).
> + function deleteAutoCommands(auEvent, regs) // args are filters
> + function printAutoCommands(auEvent, regs) // args are filters
Both look fine, but I would make an vimperator.AutoCommands class (but
still in events.js as they are so closely related).
this would/could look like:
vimperator.AutoCommands = function()
{
// private things like var autocommands = {};
// public interface like:
add: function(...);
remove: ...;
list: ...;
trigger: ...
};
and initialized in vimperator.js as vimperator.autocommands;
in onPageLoad, you just do:
vimperator.autocommands.trigger("PageLoad", doc);
the trigger function itself then checks if the url/title of the doc is ok, and
calls the autocommand function.
> + commandManager.add(new vimperator.Command(["au[tocmd]"],
> + // TODO: completer function for events?
Would be awesome :) But quite hard, could be left for later.
> + help: ":au[tocmd] {event} {pat} {cmd}<br/>" +
> + "Add {cmd} to the list of commands Vimperator will execute on {event}<br/><br/>" +
> + "autocmd[!] {events} {pat} list/remove autocommands filtered be {events} and {pat}<br/>" +
> + "autocmd[!] {events} list/remove autocommands matching {events}<br/>" +
> + "autocmd[!] * {pat} list/remove autocommands matching {pat}<br/>" +
> + "autocmd[!] list/remove all autocommands"
Great help!
> @@ -1498,6 +1656,13 @@
> for (var abbrCmd in vimperator.editor.abbreviations)
> line += abbrCmd;
>
> + line += "\n\" Auto-Commands\n";
> + for (var item in vimperator.events.autoCommands)
> + for (var i = 0; i < vimperator.events.autoCommands[item].length; i++)
> + line += "autocmd " + item + " " + vimperator.events.autoCommands[item][i][0] +
> + " " + vimperator.events.autoCommands[item][i][1] + "\n";
Hmm, why is that code here? thought that printAutoCommands handles that?
> + if (vimperator.events.autoCommands["onPageLoad"]) // XXX: or this.autoCommands[...] ?
Definitly this.autoCommands
> + for (var i = 0; i < vimperator.events.autoCommands["onPageLoad"].length; i++)
> + {
> + var regex = new RegExp(vimperator.events.autoCommands["onPageLoad"][i][0]);
> + if (regex.test(url))
Also test against title? I don't know yet, maybe not.
But patch looks very good for an initial patch, adding more autocommands
is the easier part than having the framework! Looking forward for the
next iteration of the patch :)
--
Martin
More information about the Vimperator
mailing list