mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 17:27:58 +01:00
Allow negating the regular expression in :autocmd.
This commit is contained in:
@@ -36,7 +36,7 @@ const AutoCommands = Module("autocommands", {
|
||||
dactyl.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names");
|
||||
}
|
||||
events.forEach(function (event) {
|
||||
this._store.push(AutoCommand(event, RegExp(regex), cmd));
|
||||
this._store.push(AutoCommand(event, Option.parseRegex(regex), cmd));
|
||||
}, this);
|
||||
},
|
||||
|
||||
@@ -121,7 +121,7 @@ const AutoCommands = Module("autocommands", {
|
||||
let url = args.url || "";
|
||||
|
||||
for (let [, autoCmd] in Iterator(autoCmds)) {
|
||||
if (autoCmd.pattern.test(url)) {
|
||||
if (autoCmd.pattern.test(url) ^ !autoCmd.pattern.result) {
|
||||
if (!lastPattern || lastPattern.source != autoCmd.pattern.source)
|
||||
dactyl.echomsg("Executing " + event + " Auto commands for " + autoCmd.pattern.source.quote(), 8);
|
||||
|
||||
@@ -143,7 +143,7 @@ const AutoCommands = Module("autocommands", {
|
||||
}
|
||||
}, {
|
||||
matchAutoCmd: function (autoCmd, event, regex) {
|
||||
return (!event || autoCmd.event == event) && (!regex || autoCmd.pattern.source == regex);
|
||||
return (!event || autoCmd.event == event) && (!regex || String(autoCmd.pattern) == regex);
|
||||
}
|
||||
}, {
|
||||
commands: function () {
|
||||
@@ -154,7 +154,7 @@ const AutoCommands = Module("autocommands", {
|
||||
let events = [];
|
||||
|
||||
try {
|
||||
RegExp(regex);
|
||||
Option.parseRegex(regex);
|
||||
}
|
||||
catch (e) {
|
||||
dactyl.assert(false, "E475: Invalid argument: " + regex);
|
||||
@@ -170,7 +170,7 @@ const AutoCommands = Module("autocommands", {
|
||||
"E216: No such group or event: " + event);
|
||||
}
|
||||
|
||||
if (cmd) { // add new command, possibly removing all others with the same event/pattern
|
||||
if (args.length > 2) { // add new command, possibly removing all others with the same event/pattern
|
||||
if (args.bang)
|
||||
autocommands.remove(event, regex);
|
||||
if (args["-javascript"])
|
||||
@@ -183,7 +183,7 @@ const AutoCommands = Module("autocommands", {
|
||||
|
||||
if (args.bang) {
|
||||
// TODO: "*" only appears to work in Vim when there is a {group} specified
|
||||
if (args[0] != "*" || regex)
|
||||
if (args[0] != "*" || args.length > 1)
|
||||
autocommands.remove(event, regex); // remove all
|
||||
}
|
||||
else
|
||||
@@ -252,7 +252,8 @@ const AutoCommands = Module("autocommands", {
|
||||
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),
|
||||
keepQuotes: true
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
@@ -913,7 +913,7 @@ const Commands = Module("commands", {
|
||||
if ((res = re2.exec(str)))
|
||||
arg += keepQuotes ? res[0] : res[2].replace(/\\(.)/g, "$1");
|
||||
else if ((res = /^(")((?:[^\\"]|\\.)*)("?)/.exec(str)))
|
||||
arg += keepQuotes ? res[0] : eval(res[0] + (res[3] ? "" : '"'));
|
||||
arg += keepQuotes ? res[0] : window.eval(res[0] + (res[3] ? "" : '"'));
|
||||
else if ((res = /^(')((?:[^']|'')*)('?)/.exec(str)))
|
||||
arg += keepQuotes ? res[0] : res[2].replace("''", "'", "g");
|
||||
else
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
__proto__: jsmodules,
|
||||
get content() window.content,
|
||||
jsmodules: jsmodules,
|
||||
newContext: newContext,
|
||||
window: window
|
||||
newContext: newContext
|
||||
};
|
||||
modules.modules = modules;
|
||||
|
||||
|
||||
@@ -478,7 +478,7 @@ const JavaScript = Module("javascript", {
|
||||
let string = this._str.substring(this._get(-1).offset + 1, this._lastIdx);
|
||||
// This is definitely a properly quoted string.
|
||||
// Just eval it normally.
|
||||
string = eval(this._last + string + this._last);
|
||||
string = window.eval(this._last + string + this._last);
|
||||
|
||||
// Is this an object accessor?
|
||||
if (this._get(-2).char == "[") { // Are we inside of []?
|
||||
@@ -536,7 +536,7 @@ const JavaScript = Module("javascript", {
|
||||
args.push(key + string);
|
||||
|
||||
let compl = function (context, obj) {
|
||||
let res = completer.call(self, context, funcName, obj, args);
|
||||
let res = completer.call(this, context, funcName, obj, args);
|
||||
if (res)
|
||||
context.completions = res;
|
||||
};
|
||||
|
||||
@@ -30,13 +30,14 @@
|
||||
</p>
|
||||
|
||||
<p>
|
||||
When <oa>cmd</oa> is given, add it to the list of
|
||||
commands to be executed when <oa>events</oa> occur for
|
||||
pages matching the regular expression <oa>pat</oa>. If
|
||||
the <em>-javascript</em> (short name <em>-js</em>)
|
||||
option is given, <oa>cmd</oa> is interpreted as
|
||||
JavaScript code. Otherwise, it is interpreted as an ex
|
||||
command.
|
||||
When <oa>cmd</oa> is given, add it to the list of commands to be
|
||||
executed when <oa>events</oa> occur for pages matching the regular
|
||||
expression <oa>pat</oa>. If <oa>pat</oa> is preceded by an
|
||||
unquoted <em>!</em>, then the autocommand is executed only for
|
||||
pages not matching the following regular expression. If the
|
||||
<em>-javascript</em> (short name <em>-js</em>) option is given,
|
||||
<oa>cmd</oa> is interpreted as JavaScript code. Otherwise, it is
|
||||
interpreted as an ex command.
|
||||
</p>
|
||||
|
||||
<note>
|
||||
|
||||
Reference in New Issue
Block a user