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