mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-23 16:33:33 +01:00
Allow multiple patterns for :autocommands.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
/** @scope modules */
|
/** @scope modules */
|
||||||
|
|
||||||
var AutoCommand = Struct("event", "pattern", "command");
|
var AutoCommand = Struct("event", "patterns", "command");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @instance autocommands
|
* @instance autocommands
|
||||||
@@ -31,7 +31,7 @@ var AutoCommands = Module("autocommands", {
|
|||||||
*/
|
*/
|
||||||
add: function (events, regexp, cmd) {
|
add: function (events, regexp, cmd) {
|
||||||
events.forEach(function (event) {
|
events.forEach(function (event) {
|
||||||
this._store.push(AutoCommand(event, Option.parseRegexp(regexp), cmd));
|
this._store.push(AutoCommand(event, Option.parse.regexplist(regexp), cmd));
|
||||||
}, this);
|
}, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ var AutoCommands = Module("autocommands", {
|
|||||||
+
|
+
|
||||||
template.map(items, function (item)
|
template.map(items, function (item)
|
||||||
<tr>
|
<tr>
|
||||||
<td> {util.regexp.getSource(item.pattern)}</td>
|
<td> {item.patterns}</td>
|
||||||
<td>{item.command}</td>
|
<td>{item.command}</td>
|
||||||
</tr>))
|
</tr>))
|
||||||
}
|
}
|
||||||
@@ -112,11 +112,11 @@ var AutoCommands = Module("autocommands", {
|
|||||||
let url = args.url || "";
|
let url = args.url || "";
|
||||||
|
|
||||||
for (let [, autoCmd] in Iterator(autoCmds)) {
|
for (let [, autoCmd] in Iterator(autoCmds)) {
|
||||||
if (autoCmd.pattern.test(url) ^ !autoCmd.pattern.result) {
|
if (autoCmd.patterns.some(function (re) re.test(url) ^ !re.result)) {
|
||||||
if (!lastPattern || lastPattern.source != autoCmd.pattern.source)
|
if (!lastPattern || String(lastPattern) != String(autoCmd.patterns))
|
||||||
dactyl.echomsg("Executing " + event + " Auto commands for " + util.regexp.getSource(autoCmd.pattern).quote(), 8);
|
dactyl.echomsg("Executing " + event + " Auto commands for " + autoCmd.patterns, 8);
|
||||||
|
|
||||||
lastPattern = autoCmd.pattern;
|
lastPattern = autoCmd.patterns;
|
||||||
dactyl.echomsg("autocommand " + autoCmd.command, 9);
|
dactyl.echomsg("autocommand " + autoCmd.command, 9);
|
||||||
|
|
||||||
dactyl.trapErrors(autoCmd.command, autoCmd, args);
|
dactyl.trapErrors(autoCmd.command, autoCmd, args);
|
||||||
@@ -125,7 +125,7 @@ var AutoCommands = Module("autocommands", {
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
matchAutoCmd: function (autoCmd, event, regexp) {
|
matchAutoCmd: function (autoCmd, event, regexp) {
|
||||||
return (!event || autoCmd.event == event) && (!regexp || String(autoCmd.pattern) == regexp);
|
return (!event || autoCmd.event == event) && (!regexp || String(autoCmd.patterns) == regexp);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
commands: function () {
|
commands: function () {
|
||||||
@@ -136,7 +136,8 @@ var AutoCommands = Module("autocommands", {
|
|||||||
let events = [];
|
let events = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Option.parseRegexp(regexp);
|
if (args.length > 1)
|
||||||
|
Option.parse.regexplist(regexp);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
dactyl.assert(false, "E475: Invalid argument: " + regexp);
|
dactyl.assert(false, "E475: Invalid argument: " + regexp);
|
||||||
@@ -211,11 +212,11 @@ var AutoCommands = Module("autocommands", {
|
|||||||
|
|
||||||
// TODO: add command validators
|
// TODO: add command validators
|
||||||
dactyl.assert(event != "*",
|
dactyl.assert(event != "*",
|
||||||
"E217: Can't execute autocommands for ALL events");
|
"E217: Can't execute autocommands for ALL events");
|
||||||
dactyl.assert(validEvents.indexOf(event) >= 0,
|
dactyl.assert(validEvents.indexOf(event) >= 0,
|
||||||
"E216: No such group or event: " + args);
|
"E216: No such group or event: " + args);
|
||||||
dactyl.assert(autocommands.get(event).some(function (c) c.pattern.test(defaultURL)),
|
dactyl.assert(autocommands.get(event).some(function (c) c.patterns.some(function (re) re.test(defaultURL) ^ !re.result)),
|
||||||
"No matching autocommands");
|
"No matching autocommands");
|
||||||
|
|
||||||
if (this.name == "doautoall" && dactyl.has("tabs")) {
|
if (this.name == "doautoall" && dactyl.has("tabs")) {
|
||||||
let current = tabs.index();
|
let current = tabs.index();
|
||||||
|
|||||||
Reference in New Issue
Block a user