From c747734f1ea808f4e4649a16fe335f23d4a2172a Mon Sep 17 00:00:00 2001
From: Kris Maglione
Date: Mon, 4 Oct 2010 23:48:19 -0400
Subject: [PATCH] Allow negating the regular expression in :autocmd.
---
common/content/autocommands.js | 15 ++++++++-------
common/content/commands.js | 2 +-
common/content/dactyl-overlay.js | 3 +--
common/content/javascript.js | 4 ++--
common/locale/en-US/autocommands.xml | 15 ++++++++-------
5 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/common/content/autocommands.js b/common/content/autocommands.js
index 894bc67d..65b083ec 100644
--- a/common/content/autocommands.js
+++ b/common/content/autocommands.js
@@ -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
});
});
},
diff --git a/common/content/commands.js b/common/content/commands.js
index 88575384..5a0183a8 100644
--- a/common/content/commands.js
+++ b/common/content/commands.js
@@ -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
diff --git a/common/content/dactyl-overlay.js b/common/content/dactyl-overlay.js
index 936c1028..df020682 100644
--- a/common/content/dactyl-overlay.js
+++ b/common/content/dactyl-overlay.js
@@ -20,8 +20,7 @@
__proto__: jsmodules,
get content() window.content,
jsmodules: jsmodules,
- newContext: newContext,
- window: window
+ newContext: newContext
};
modules.modules = modules;
diff --git a/common/content/javascript.js b/common/content/javascript.js
index 9bb0fe10..e9ef529d 100644
--- a/common/content/javascript.js
+++ b/common/content/javascript.js
@@ -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;
};
diff --git a/common/locale/en-US/autocommands.xml b/common/locale/en-US/autocommands.xml
index 05fc99cc..3de965dc 100644
--- a/common/locale/en-US/autocommands.xml
+++ b/common/locale/en-US/autocommands.xml
@@ -30,13 +30,14 @@
- When cmd is given, add it to the list of
- commands to be executed when events occur for
- pages matching the regular expression pat. If
- the -javascript (short name -js)
- option is given, cmd is interpreted as
- JavaScript code. Otherwise, it is interpreted as an ex
- command.
+ When cmd is given, add it to the list of commands to be
+ executed when events occur for pages matching the regular
+ expression pat. If pat is preceded by an
+ unquoted !, then the autocommand is executed only for
+ pages not matching the following regular expression. If the
+ -javascript (short name -js) option is given,
+ cmd is interpreted as JavaScript code. Otherwise, it is
+ interpreted as an ex command.