1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 04:07:59 +01:00

Fix :doautoall.

This commit is contained in:
Doug Kearns
2009-08-27 01:01:58 +10:00
parent b6a898a5fa
commit 1a3394d1a0
2 changed files with 46 additions and 40 deletions

View File

@@ -562,6 +562,9 @@ function Commands() //{{{
// : it might be nice to be able to specify that certain quoting // : it might be nice to be able to specify that certain quoting
// should be disabled E.g. backslash without having to resort to // should be disabled E.g. backslash without having to resort to
// using literal etc. // using literal etc.
// : error messages should be configurable or else we can ditch
// Vim compatibility but it actually gives useful messages
// sometimes rather than just "Invalid arg"
// : I'm not sure documenting the returned object here, and // : I'm not sure documenting the returned object here, and
// elsewhere, as type Args rather than simply Object makes sense, // elsewhere, as type Args rather than simply Object makes sense,
// especially since it is further augmented for use in // especially since it is further augmented for use in

View File

@@ -122,55 +122,58 @@ function AutoCommands() //{{{
options: [[["-javascript", "-js"], commands.OPTION_NOARG]] options: [[["-javascript", "-js"], commands.OPTION_NOARG]]
}); });
// TODO: expand target to all buffers [
commands.add(["doauto[all]"],
"Apply the autocommands matching the specified URL pattern to all buffers",
function (args)
{ {
commands.get("doautocmd").action.call(this, args); name: "do[autocmd]",
description: "Apply the autocommands matching the specified URL pattern to the current buffer"
}, },
{ {
completer: function (context) completion.autocmdEvent(context), name: "doautoa[ll]",
literal: 0 description: "Apply the autocommands matching the specified URL pattern to all buffers"
} }
); ].forEach(function (command) {
commands.add([command.name],
// TODO: restrict target to current buffer command.description,
commands.add(["do[autocmd]"], // TODO: Perhaps this should take -args to pass to the command?
"Apply the autocommands matching the specified URL pattern to the current buffer",
function (args) function (args)
{ {
args = args.string; // Vim compatible
if (/^\s*$/.test(args)) if (args.length == 0)
{ return void liberator.echomsg("No matching autocommands");
liberator.echomsg("No matching autocommands");
return;
}
let [, event, url] = args.match(/^(\S+)(?:\s+(\S+))?$/);
url = url || buffer.URL;
let [event, url] = args;
let defaultURL = url || buffer.URL;
let validEvents = config.autocommands.map(function (e) e[0]); let validEvents = config.autocommands.map(function (e) e[0]);
// TODO: add command validators
if (event == "*") if (event == "*")
liberator.echoerr("E217: Can't execute autocommands for ALL events"); return void liberator.echoerr("E217: Can't execute autocommands for ALL events");
else if (validEvents.indexOf(event) == -1) else if (validEvents.indexOf(event) == -1)
liberator.echoerr("E216: No such group or event: " + args); return void liberator.echoerr("E216: No such group or event: " + args);
else else if (!autocommands.get(event).some(function (c) c.pattern.test(defaultURL)))
return void liberator.echomsg("No matching autocommands");
if (this.name == "doautoall" && liberator.has("tabs"))
{ {
// TODO: perhaps trigger could return the number of autocmds triggered let current = tabs.index();
// TODO: Perhaps this should take -args to pass to the command?
if (!autocommands.get(event).some(function (c) c.pattern.test(url))) for (let i = 0; i < tabs.count; i++)
liberator.echomsg("No matching autocommands"); {
else tabs.select(i);
autocommands.trigger(event, { url: url }); // if no url arg is specified use the current buffer's URL
autocommands.trigger(event, { url: url || buffer.URL });
} }
tabs.select(current);
}
else
autocommands.trigger(event, { url: defaultURL });
}, },
{ {
completer: function (context) completion.autocmdEvent(context), argCount: "*", // FIXME: kludged for proper error message should be "1".
literal: 0 completer: function (context) completion.autocmdEvent(context)
} });
); });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMPLETIONS ///////////////////////////////////////////// ////////////////////// COMPLETIONS /////////////////////////////////////////////