1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 16:17:59 +01:00

Normalise regex -> regexp.

This is what JS uses and using both is confusing.
This commit is contained in:
Doug Kearns
2010-10-22 12:03:03 +11:00
parent 5a42002243
commit 4f14857d66
14 changed files with 92 additions and 92 deletions

View File

@@ -22,52 +22,52 @@ const AutoCommands = Module("autocommands", {
/**
* Adds a new autocommand. *cmd* will be executed when one of the specified
* *events* occurs and the URL of the applicable buffer matches *regex*.
* *events* occurs and the URL of the applicable buffer matches *regexp*.
*
* @param {Array} events The array of event names for which this
* autocommand should be executed.
* @param {string} regex The URL pattern to match against the buffer URL.
* @param {string} regexp The URL pattern to match against the buffer URL.
* @param {string} cmd The Ex command to run.
*/
add: function (events, regex, cmd) {
add: function (events, regexp, cmd) {
events.forEach(function (event) {
this._store.push(AutoCommand(event, Option.parseRegex(regex), cmd));
this._store.push(AutoCommand(event, Option.parseRegexp(regexp), cmd));
}, this);
},
/**
* Returns all autocommands with a matching *event* and *regex*.
* Returns all autocommands with a matching *event* and *regexp*.
*
* @param {string} event The event name filter.
* @param {string} regex The URL pattern filter.
* @param {string} regexp The URL pattern filter.
* @returns {AutoCommand[]}
*/
get: function (event, regex) {
return this._store.filter(function (autoCmd) AutoCommands.matchAutoCmd(autoCmd, event, regex));
get: function (event, regexp) {
return this._store.filter(function (autoCmd) AutoCommands.matchAutoCmd(autoCmd, event, regexp));
},
/**
* Deletes all autocommands with a matching *event* and *regex*.
* Deletes all autocommands with a matching *event* and *regexp*.
*
* @param {string} event The event name filter.
* @param {string} regex The URL pattern filter.
* @param {string} regexp The URL pattern filter.
*/
remove: function (event, regex) {
this._store = this._store.filter(function (autoCmd) !AutoCommands.matchAutoCmd(autoCmd, event, regex));
remove: function (event, regexp) {
this._store = this._store.filter(function (autoCmd) !AutoCommands.matchAutoCmd(autoCmd, event, regexp));
},
/**
* Lists all autocommands with a matching *event* and *regex*.
* Lists all autocommands with a matching *event* and *regexp*.
*
* @param {string} event The event name filter.
* @param {string} regex The URL pattern filter.
* @param {string} regexp The URL pattern filter.
*/
list: function (event, regex) {
list: function (event, regexp) {
let cmds = {};
// XXX
this._store.forEach(function (autoCmd) {
if (AutoCommands.matchAutoCmd(autoCmd, event, regex)) {
if (AutoCommands.matchAutoCmd(autoCmd, event, regexp)) {
cmds[autoCmd.event] = cmds[autoCmd.event] || [];
cmds[autoCmd.event].push(autoCmd);
}
@@ -124,22 +124,22 @@ const AutoCommands = Module("autocommands", {
}
}
}, {
matchAutoCmd: function (autoCmd, event, regex) {
return (!event || autoCmd.event == event) && (!regex || String(autoCmd.pattern) == regex);
matchAutoCmd: function (autoCmd, event, regexp) {
return (!event || autoCmd.event == event) && (!regexp || String(autoCmd.pattern) == regexp);
}
}, {
commands: function () {
commands.add(["au[tocmd]"],
"Execute commands automatically on events",
function (args) {
let [event, regex, cmd] = args;
let [event, regexp, cmd] = args;
let events = [];
try {
Option.parseRegex(regex);
Option.parseRegexp(regexp);
}
catch (e) {
dactyl.assert(false, "E475: Invalid argument: " + regex);
dactyl.assert(false, "E475: Invalid argument: " + regexp);
}
if (event) {
@@ -154,7 +154,7 @@ const AutoCommands = Module("autocommands", {
if (args.length > 2) { // add new command, possibly removing all others with the same event/pattern
if (args.bang)
autocommands.remove(event, regex);
autocommands.remove(event, regexp);
if (args["-javascript"]) {
cmd = dactyl.userFunc("args", "with(args) {" + cmd + "}");
cmd.toString = function toString() "-javascript " + cmd.source;
@@ -165,7 +165,7 @@ const AutoCommands = Module("autocommands", {
cmd.toString = function toString() cmd.source;
}
cmd.source = args[2];
autocommands.add(events, regex, cmd);
autocommands.add(events, regexp, cmd);
}
else {
if (event == "*")
@@ -174,10 +174,10 @@ const AutoCommands = Module("autocommands", {
if (args.bang) {
// TODO: "*" only appears to work in Vim when there is a {group} specified
if (args[0] != "*" || args.length > 1)
autocommands.remove(event, regex); // remove all
autocommands.remove(event, regexp); // remove all
}
else
autocommands.list(event, regex); // list all
autocommands.list(event, regexp); // list all
}
}, {
bang: true,

View File

@@ -567,11 +567,11 @@ const Buffer = Module("buffer", {
yield elem;
let res = util.evaluateXPath(path, frame.document);
for (let regex in values(regexps)) {
for (let regexp in values(regexps)) {
for (let i in util.range(res.snapshotLength, 0, -1)) {
let elem = res.snapshotItem(i);
if (regex.test(elem.textContent) === regex.result || regex.test(elem.title) === regex.result ||
Array.some(elem.childNodes, function (child) regex.test(child.alt) === regex.result))
if (regexp.test(elem.textContent) === regexp.result || regexp.test(elem.title) === regexp.result ||
Array.some(elem.childNodes, function (child) regexp.test(child.alt) === regexp.result))
yield elem;
}
}
@@ -1745,13 +1745,13 @@ const Buffer = Module("buffer", {
options: function () {
options.add(["nextpattern"],
"Patterns to use when guessing the 'next' page in a document sequence",
"regexlist", UTF8("'\\bnext\\b',^>$,^(>>|»)$,^(>|»),(>|»)$,'\\bmore\\b'"),
{ regexFlags: "i" });
"regexplist", UTF8("'\\bnext\\b',^>$,^(>>|»)$,^(>|»),(>|»)$,'\\bmore\\b'"),
{ regexpFlags: "i" });
options.add(["previouspattern"],
"Patterns to use when guessing the 'previous' page in a document sequence",
"regexlist", UTF8("'\\bprev|previous\\b',^<$,^(<<|«)$,^(<|«),(<|«)$"),
{ regexFlags: "i" });
"regexplist", UTF8("'\\bprev|previous\\b',^<$,^(<<|«)$,^(<|«),(<|«)$"),
{ regexpFlags: "i" });
options.add(["pageinfo", "pa"],
"Desired info in the :pageinfo output",

View File

@@ -1657,7 +1657,7 @@ const CommandLine = Module("commandline", {
// At the moment, adding "<Tab>" breaks tab completion. Adding
// "<CR>" has no effect.
// TODO: Make non-keyword recognition smarter so that there need not
// be two lists of the same characters (one here and a regex in
// be two lists of the same characters (one here and a regexp in
// mappings.js)
mappings.add(myModes,
["<Space>", '"', "'"], "Expand command line abbreviation",

View File

@@ -833,7 +833,7 @@ const Completion = Module("completion", {
function (tok) contains(item.url, tok) ||
contains(item.title, tok)));
let re = RegExp(tokens.filter(util.identity).map(util.escapeRegex).join("|"), "g");
let re = RegExp(tokens.filter(util.identity).map(util.escapeRegexp).join("|"), "g");
function highlight(item, text, i) process[i].call(this, item, template.highlightRegexp(text, re));
let process = context.process;
context.process = [
@@ -895,7 +895,7 @@ const Completion = Module("completion", {
options.add(["autocomplete", "au"],
"Automatically update the completion list on any key press",
"regexlist", ".*");
"regexplist", ".*");
options.add(["complete", "cpt"],
"Items which are completed at the :open prompts",
@@ -906,11 +906,11 @@ const Completion = Module("completion", {
options.add(["wildanchor", "wia"],
"Regexp list defining which contexts require matches anchored to the beginning of the result",
"regexlist", "!/ex/(back|buffer|ext|forward|help|undo)");
"regexplist", "!/ex/(back|buffer|ext|forward|help|undo)");
options.add(["wildcase", "wic"],
"Completion case matching mode",
"regexmap", ".?:smart",
"regexpmap", ".?:smart",
{
completer: function () [
["smart", "Case is significant when capital letters are typed"],
@@ -926,7 +926,7 @@ const Completion = Module("completion", {
options.add(["wildsort", "wis"],
"Regexp list of which contexts to sort",
"regexlist", ".*");
"regexplist", ".*");
}
});

View File

@@ -1211,8 +1211,8 @@ const Dactyl = Module("dactyl", {
"string", "intro");
options.add(["loadplugins", "lpl"],
"A regex list that defines which plugins are loaded at startup and via :loadplugins",
"regexlist", "'\\.(js|" + config.fileExtension + ")$'");
"A regexp list that defines which plugins are loaded at startup and via :loadplugins",
"regexplist", "'\\.(js|" + config.fileExtension + ")$'");
options.add(["titlestring"],
"Change the title of the window",
@@ -1221,7 +1221,7 @@ const Dactyl = Module("dactyl", {
setter: function (value) {
let win = document.documentElement;
function updateTitle(old, current) {
document.title = document.title.replace(RegExp("(.*)" + util.escapeRegex(old)), "$1" + current);
document.title = document.title.replace(RegExp("(.*)" + util.escapeRegexp(old)), "$1" + current);
}
// TODO: remove this FF3.5 test when we no longer support 3.0
@@ -1247,7 +1247,7 @@ const Dactyl = Module("dactyl", {
});
options.add(["urlseparator", "us"],
"Set the separator regex used to separate multiple URL args",
"Set the separator regexp used to separate multiple URL args",
"string", "\\|");
options.add(["verbose", "vbs"],

View File

@@ -27,7 +27,7 @@ const RangeFinder = Module("rangefinder", {
let highlighted = this.rangeFind && this.rangeFind.highlighted;
let selections = this.rangeFind && this.rangeFind.selections;
let regex = false;
let regexp = false;
let matchCase = !(options["ignorecase"] || options["smartcase"] && !/[A-Z]/.test(str));
let linksOnly = options["linksearch"];
@@ -41,9 +41,9 @@ const RangeFinder = Module("rangefinder", {
else if (n1 == "L")
linksOnly = false;
else if (n1 == "r")
regex = true;
regexp = true;
else if (n1 == "R")
regex = false;
regexp = false;
else
return m;
return "";
@@ -54,13 +54,13 @@ const RangeFinder = Module("rangefinder", {
if (!this.rangeFind
|| this.rangeFind.window.get() != window
|| linksOnly != !!this.rangeFind.elementPath
|| regex != this.rangeFind.regex
|| regexp != this.rangeFind.regex
|| matchCase != this.rangeFind.matchCase
|| !!backward != this.rangeFind.reverse) {
if (this.rangeFind)
this.rangeFind.cancel();
this.rangeFind = RangeFind(matchCase, backward, linksOnly && options["hinttags"], regex);
this.rangeFind = RangeFind(matchCase, backward, linksOnly && options["hinttags"], regexp);
this.rangeFind.highlighted = highlighted;
this.rangeFind.selections = selections;
}
@@ -259,14 +259,14 @@ const RangeFinder = Module("rangefinder", {
* large amounts of data are concerned (e.g., for API documents).
*/
const RangeFind = Class("RangeFind", {
init: function (matchCase, backward, elementPath, regex) {
init: function (matchCase, backward, elementPath, regexp) {
this.window = Cu.getWeakReference(window);
this.elementPath = elementPath || null;
this.reverse = Boolean(backward);
this.finder = services.create("find");
this.matchCase = Boolean(matchCase);
this.regex = Boolean(regex);
this.regexp = Boolean(regexp);
this.ranges = this.makeFrameList(window.content);
@@ -282,8 +282,8 @@ const RangeFind = Class("RangeFind", {
get matchCase() this.finder.caseSensitive,
set matchCase(val) this.finder.caseSensitive = Boolean(val),
get regex() this.finder.regularExpression || false,
set regex(val) {
get regexp() this.finder.regularExpression || false,
set regexp(val) {
try {
return this.finder.regularExpression = Boolean(val);
}

View File

@@ -630,7 +630,7 @@ const Hints = Module("hints", {
*/
function wordStartsWithMatcher(hintString, allowWordOverleaping) { //{{{
let hintStrings = tokenize(/\s+/, hintString);
let wordSplitRegex = RegExp(options["wordseparators"]);
let wordSplitRegexp = RegExp(options["wordseparators"]);
/**
* Match a set of characters to the start of words.
@@ -728,7 +728,7 @@ const Hints = Module("hints", {
if (hintStrings.length == 1 && hintStrings[0].length == 0)
return true;
let words = tokenize(wordSplitRegex, linkText);
let words = tokenize(wordSplitRegexp, linkText);
if (hintStrings.length == 1)
return charsAtBeginningOfWords(hintStrings[0], words, allowWordOverleaping);
else
@@ -1119,7 +1119,7 @@ const Hints = Module("hints", {
options.add(["extendedhinttags", "eht"],
"XPath string of hintable elements activated by ';'",
"regexmap", "[iI]:" + Option.quote(util.makeXPath(["img"])) +
"regexpmap", "[iI]:" + Option.quote(util.makeXPath(["img"])) +
",[OTivVWy]:" + Option.quote(util.makeXPath(
["{a,area}[@href]", "{img,iframe}[@src]"])) +
",[S]:" + Option.quote(util.makeXPath(

View File

@@ -761,7 +761,7 @@ lookup:
options.add(["wildignore", "wig"],
"List of file patterns to ignore when completing files",
"regexlist", "");
"regexplist", "");
}
});

View File

@@ -255,9 +255,9 @@ const Option = Class("Option", {
* "number" - Integer, e.g., 1
* "string" - String, e.g., "Pentadactyl"
* "charlist" - Character list, e.g., "rb"
* "regexlist" - Regex list, e.g., "^foo,bar$"
* "regexplist" - Regexp list, e.g., "^foo,bar$"
* "stringmap" - String map, e.g., "key:v,foo:bar"
* "regexmap" - Regex map, e.g., "^key:v,foo$:bar"
* "regexpmap" - Regexp map, e.g., "^key:v,foo$:bar"
*/
type: null,
@@ -384,28 +384,28 @@ const Option = Class("Option", {
toggleAll: function toggleAll() toggleAll.supercall(this, "all") ^ !!toggleAll.superapply(this, arguments),
},
parseRegex: function (value, result, flags) {
parseRegexp: function (value, result, flags) {
let [, bang, val] = /^(!?)(.*)/.exec(value);
let re = RegExp(Option.dequote(val), flags);
re.bang = bang;
re.result = result !== undefined ? result : !bang;
re.toString = function () Option.unparseRegex(this);
re.toString = function () Option.unparseRegexp(this);
return re;
},
unparseRegex: function (re) re.bang + Option.quote(re.source.replace(/\\(.)/g, function (m, n1) n1 == "/" ? n1 : m), /^!|:/) +
unparseRegexp: function (re) re.bang + Option.quote(re.source.replace(/\\(.)/g, function (m, n1) n1 == "/" ? n1 : m), /^!|:/) +
(typeof re.result === "string" ? ":" + Option.quote(re.result) : ""),
getKey: {
stringlist: function (k) this.value.indexOf(k) >= 0,
get charlist() this.stringlist,
regexlist: function (k, default_) {
regexplist: function (k, default_) {
for (let re in values(this.value))
if (re.test(k))
return re.result;
return arguments.length > 1 ? default_ : null;
},
get regexmap() this.regexlist
get regexpmap() this.regexplist
},
stringify: {
@@ -415,8 +415,8 @@ const Option = Class("Option", {
stringmap: function (vals) [Option.quote(k, /:/) + ":" + Option.quote(v) for ([k, v] in Iterator(vals))].join(","),
regexlist: function (vals) vals.join(","),
get regexmap() this.regexlist
regexplist: function (vals) vals.join(","),
get regexpmap() this.regexplist
},
parse: {
@@ -428,9 +428,9 @@ const Option = Class("Option", {
stringlist: function (value) (value === "") ? [] : Option.splitList(value),
regexlist: function (value) (value === "") ? [] :
regexplist: function (value) (value === "") ? [] :
Option.splitList(value, true)
.map(function (re) Option.parseRegex(re, undefined, this.regexFlags), this),
.map(function (re) Option.parseRegexp(re, undefined, this.regexpFlags), this),
stringmap: function (value) array.toObject(
Option.splitList(value, true).map(function (v) {
@@ -438,18 +438,18 @@ const Option = Class("Option", {
return [key, Option.dequote(v.substr(count + 1))]
})),
regexmap: function (value)
regexpmap: function (value)
Option.splitList(value, true).map(function (v) {
let [count, re, quote] = Commands.parseArg(v, /:/, true);
v = Option.dequote(v.substr(count + 1));
if (count === v.length)
[v, re] = [re, ".?"];
return Option.parseRegex(re, v, this.regexFlags);
return Option.parseRegexp(re, v, this.regexpFlags);
}, this)
},
testValues: {
regexmap: function (vals, validator) vals.every(function (re) validator(re.result)),
regexpmap: function (vals, validator) vals.every(function (re) validator(re.result)),
stringlist: function (vals, validator) vals.every(validator, this),
stringmap: function (vals, validator) array(values(vals)).every(validator, this)
},
@@ -557,8 +557,8 @@ const Option = Class("Option", {
return null;
},
get charlist() this.stringlist,
get regexlist() this.stringlist,
get regexmap() this.stringlist,
get regexplist() this.stringlist,
get regexpmap() this.stringlist,
string: function (operator, values, scope, invert) {
switch (operator) {
@@ -593,7 +593,7 @@ const Option = Class("Option", {
let res = context.fork("", 0, this, this.completer);
if (!res)
res = context.allItems.items.map(function (item) [item.text]);
if (this.type == "regexmap")
if (this.type == "regexpmap")
return Array.concat(values).every(function (re) res.some(function (item) item[0] == re.result));
return Array.concat(values).every(function (value) res.some(function (item) item[0] == value));
},
@@ -1168,13 +1168,13 @@ const Options = Module("options", {
if (!completer)
completer = function () [["true", ""], ["false", ""]];
break;
case "regexlist":
case "regexplist":
newValues = Option.splitList(context.filter);
// Fallthrough
case "stringlist":
break;
case "stringmap":
case "regexmap":
case "regexpmap":
let vals = Option.splitList(context.filter);
let target = vals.pop() || "";
let [count, key, quote] = Commands.parseArg(target, /:/, true);

View File

@@ -424,7 +424,7 @@ This file contains a list of all available commands, mappings and options.
<dt><o>strictfocus</o></dt> <dd>Prevent scripts from focusing input elements without user intervention</dd>
<dt><o>suggestengines</o></dt> <dd>Engine Alias which has a feature of suggest</dd>
<dt><o>titlestring</o></dt> <dd>Change the title of the window</dd>
<dt><o>urlseparator</o></dt> <dd>Set the separator regex used to separate multiple URL args</dd>
<dt><o>urlseparator</o></dt> <dd>Set the separator regexp used to separate multiple URL args</dd>
<dt><o>usermode</o></dt> <dd>Show current website with a minimal style sheet to make it easily accessible</dd>
<dt><o>verbose</o></dt> <dd>Define which info messages are displayed</dd>
<dt><o>visualbell</o></dt> <dd>Use visual bell instead of beeping on errors</dd>

View File

@@ -46,8 +46,8 @@
<dt>stringmap</dt>
<dd>A comma-separated list of key-value pairs, e.g., <str delim="">key:val,foo:bar</str></dd>
<dt/><dd tag="regexlist"/>
<dt>regexlist</dt>
<dt/><dd tag="regexplist"/>
<dt>regexplist</dt>
<dd>
A comma-separated list of regular expressions. Expressions may be
prefixed with a <em>!</em>, in which case the match will be negated. A
@@ -58,10 +58,10 @@
<em>\</em>, will not be treated as an item separator.
</dd>
<dt/><dd tag="regexmap"/>
<dt>regexmap</dt>
<dt/><dd tag="regexpmap"/>
<dt>regexpmap</dt>
<dd>
A combination of a <em>stringmap</em> and a <em>regexlist</em>. Each key
A combination of a <em>stringmap</em> and a <em>regexplist</em>. Each key
in the <a>key</a>:<a>value</a> pair is a regexp. If the regexp begins with a
<em>!</em>, the sense of the match is negated, such that a non-matching
expression will be considered a match and <html:i>vice versa</html:i>.
@@ -360,7 +360,7 @@
<item>
<tags>'au' 'autocomplete'</tags>
<spec>'autocomplete' 'au'</spec>
<type>regexlist</type>
<type>regexplist</type>
<default>.*</default>
<description>
<p>
@@ -602,7 +602,7 @@
<tags>'eht' 'extendedhinttags'</tags>
<spec>'extendedhinttags' 'eht'</spec>
<strut/>
<type>regexmap</type>
<type>regexpmap</type>
<default>[iI]:'//img | //xhtml:img',
[OTivVWy]:'//a[@href] | //xhtml:a[@href] |
//area[@href] | //xhtml:area[@href] |
@@ -947,7 +947,7 @@
<tags>'nolpl' 'lpl'</tags>
<tags>'noloadplugins' 'loadplugins'</tags>
<spec>'loadplugins' 'lpl'</spec>
<type>regexlist</type>
<type>regexplist</type>
<default>'\.(js|&dactyl.fileExt;)$'</default>
<description>
<p>
@@ -974,7 +974,7 @@
<p>
Note that in the first expression of the latter example you don't
need parentheses, as the <em>!</em> negates the whole of the
following expression (cf. <t>regexlist</t>).
following expression (cf. <t>regexplist</t>).
</p>
<p>
See also <ex>:runtime</ex>.
@@ -1459,7 +1459,7 @@
<item>
<tags>'wia' 'wildanchor'</tags>
<spec>'wildanchor' 'wia'</spec>
<type>regexlist</type>
<type>regexplist</type>
<default>!'/ex/(back|buffer|ext|forward|help|undo)'</default>
<description>
<p>
@@ -1477,12 +1477,12 @@
<item>
<tags>'wic' 'wildcase'</tags>
<spec>'wildcase' 'wic'</spec>
<type>regexmap</type>
<type>regexpmap</type>
<default>.?:smart</default>
<description>
<p>
Defines how completions are matched with regard to character case.
Keys in the <t>regexmap</t> refer to completion context names (see
Keys in the <t>regexpmap</t> refer to completion context names (see
<ex>:contexts</ex>) for which the value applies. Possible values
are:
</p>
@@ -1498,7 +1498,7 @@
<item>
<tags>'wildignore' 'wig'</tags>
<spec>'wildignore' 'wig'</spec>
<type>regexlist</type>
<type>regexplist</type>
<default></default>
<description>
<p>
@@ -1553,7 +1553,7 @@
<item>
<tags>'wis' 'wildsort'</tags>
<spec>'wildsort' 'wis'</spec>
<type>regexlist</type>
<type>regexplist</type>
<default>.*</default>
<description>
<p>

View File

@@ -64,7 +64,7 @@
<description>
<p>
List recorded macros matching the optional regular expression
<oa>pat</oa>. If no regex is given, list all macros.
<oa>pat</oa>. If no regexp is given, list all macros.
</p>
</description>
</item>

View File

@@ -511,7 +511,7 @@ const File = Class("File", {
// expand ~
// Yuck.
if (!relative && RegExp("~(?:$|[/" + util.escapeRegex(File.PATH_SEP) + "])").test(path)) {
if (!relative && RegExp("~(?:$|[/" + util.escapeRegexp(File.PATH_SEP) + "])").test(path)) {
// Try $HOME first, on all systems
let home = services.get("environment").get("HOME");

View File

@@ -330,7 +330,7 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
* @param {string} str
* @returns {string}
*/
escapeRegex: function escapeRegex(str) {
escapeRegexp: function escapeRegexp(str) {
return str.replace(/([\\{}()[\].?*+])/g, "\\$1");
},