1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 02:27:58 +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
// should be disabled E.g. backslash without having to resort to
// 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
// elsewhere, as type Args rather than simply Object makes sense,
// especially since it is further augmented for use in

View File

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