1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 23:17: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;
if (/^\s*$/.test(args))
{ {
liberator.echomsg("No matching autocommands"); // Vim compatible
return; if (args.length == 0)
} return void liberator.echomsg("No matching autocommands");
let [, event, url] = args.match(/^(\S+)(?:\s+(\S+))?$/); let [event, url] = args;
url = url || buffer.URL; 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 == "*")
return void liberator.echoerr("E217: Can't execute autocommands for ALL events");
else if (validEvents.indexOf(event) == -1)
return void liberator.echoerr("E216: No such group or event: " + args);
else if (!autocommands.get(event).some(function (c) c.pattern.test(defaultURL)))
return void liberator.echomsg("No matching autocommands");
if (event == "*") if (this.name == "doautoall" && liberator.has("tabs"))
liberator.echoerr("E217: Can't execute autocommands for ALL events"); {
else if (validEvents.indexOf(event) == -1) let current = tabs.index();
liberator.echoerr("E216: No such group or event: " + args);
else for (let i = 0; i < tabs.count; i++)
{ {
// TODO: perhaps trigger could return the number of autocmds triggered tabs.select(i);
// TODO: Perhaps this should take -args to pass to the command? // if no url arg is specified use the current buffer's URL
if (!autocommands.get(event).some(function (c) c.pattern.test(url))) autocommands.trigger(event, { url: url || buffer.URL });
liberator.echomsg("No matching autocommands"); }
tabs.select(current);
}
else else
autocommands.trigger(event, { url: url }); autocommands.trigger(event, { url: defaultURL });
} },
}, {
{ argCount: "*", // FIXME: kludged for proper error message should be "1".
completer: function (context) completion.autocmdEvent(context), completer: function (context) completion.autocmdEvent(context)
literal: 0 });
} });
);
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// COMPLETIONS ///////////////////////////////////////////// ////////////////////// COMPLETIONS /////////////////////////////////////////////