mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-02-13 07:25:45 +01:00
Allow \c/\C in regexp options and so forth.
This commit is contained in:
@@ -15,10 +15,6 @@ defineModule("commands", {
|
||||
use: ["config", "messages", "options", "services", "template"]
|
||||
}, this);
|
||||
|
||||
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
|
||||
let re = RegExp("^(resource://dactyl|" + base + ")\\S+( -> resource://dactyl(?!-content/eval.js)\\S+)?$");
|
||||
let isDactyl = function isDactyl(frame) re.test(frame.filename);
|
||||
|
||||
/**
|
||||
* A structure representing the options available for a command.
|
||||
*
|
||||
@@ -692,7 +688,7 @@ var Commands = Module("commands", {
|
||||
repeat: null,
|
||||
|
||||
add: function add() {
|
||||
util.assert(isDactyl(Components.stack.caller),
|
||||
util.assert(util.isDactyl(Components.stack.caller),
|
||||
"User scripts may not add builtin commands. Please use group.commands.add instead.");
|
||||
return this.builtin._add.apply(this.builtin, arguments);
|
||||
},
|
||||
|
||||
@@ -903,7 +903,9 @@ var Completion = Module("completion", {
|
||||
url: function url(context, complete) {
|
||||
|
||||
if (this.options["urlseparator"])
|
||||
var skip = RegExp("^.*" + this.options["urlseparator"] + "\\s*").exec(context.filter);
|
||||
var skip = util.regexp("^.*" + this.options["urlseparator"] + "\\s*")
|
||||
.exec(context.filter);
|
||||
|
||||
if (skip)
|
||||
context.advance(skip[0].length);
|
||||
|
||||
|
||||
@@ -406,12 +406,14 @@ var Highlights = Module("Highlight", {
|
||||
completion: function (dactyl, modules) {
|
||||
const { completion, config, io } = modules;
|
||||
completion.colorScheme = function colorScheme(context) {
|
||||
let extRe = RegExp("\\." + config.fileExtension + "$");
|
||||
|
||||
context.title = ["Color Scheme", "Runtime Path"];
|
||||
context.keys = { text: function (f) f.leafName.replace(RegExp("\\." + config.fileExtension + "$"), ""), description: ".parent.path" };
|
||||
context.keys = { text: function (f) f.leafName.replace(extRe, ""), description: ".parent.path" };
|
||||
context.completions = array.flatten(
|
||||
io.getRuntimeDirectories("colors").map(
|
||||
function (dir) dir.readDirectory().filter(
|
||||
function (file) RegExp("\\." + config.fileExtension + "$").test(file.leafName))));
|
||||
function (file) extRe.test(file.leafName))));
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -425,7 +425,7 @@ var Option = Class("Option", {
|
||||
flags = this && this.regexpFlags || "";
|
||||
|
||||
let [, bang, val] = /^(!?)(.*)/.exec(value);
|
||||
let re = RegExp(Option.dequote(val), flags);
|
||||
let re = util.regexp(Option.dequote(val), flags);
|
||||
re.bang = bang;
|
||||
re.result = result !== undefined ? result : !bang;
|
||||
re.toString = function () Option.unparseRegexp(this, keepQuotes);
|
||||
|
||||
@@ -413,7 +413,7 @@ var Styles = Module("Styles", {
|
||||
if (filter === "*")
|
||||
var test = function test(uri) true;
|
||||
else if (!/^(?:[a-z-]+:|[a-z-.]+$)/.test(filter)) {
|
||||
let re = RegExp(filter);
|
||||
let re = util.regexp(filter);
|
||||
test = function test(uri) re.test(uri.spec);
|
||||
}
|
||||
else if (/[*]$/.test(filter)) {
|
||||
|
||||
@@ -177,20 +177,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
* @returns {RegExp}
|
||||
*/
|
||||
charListToRegexp: function charListToRegexp(list, accepted) {
|
||||
let list = list.replace(/\s+/g, "");
|
||||
list = list.replace(/\s+/g, "");
|
||||
|
||||
// check for chars not in the accepted range
|
||||
this.assert(RegExp("^[" + accepted + "-]+$").test(list),
|
||||
"Character list outside the range " + accepted.quote());
|
||||
"Character list outside the range " + accepted.quote());
|
||||
|
||||
// check for illegal ranges
|
||||
let matches = list.match(RegExp("[" + accepted + "]-[" + accepted + "]", "g"));
|
||||
if (matches) {
|
||||
for (let match in values(matches))
|
||||
this.assert(match[0] <= match[2],
|
||||
"Invalid character range: " + list.match(match + ".*")[0]);
|
||||
}
|
||||
return RegExp("[" + list + "]");
|
||||
for (let [match] in this.regexp.iterate(/.-./g, list))
|
||||
this.assert(match.charCodeAt(0) <= match.charCodeAt(2),
|
||||
"Invalid character range: " + list.slice(list.indexOf(match)))
|
||||
|
||||
return RegExp("[" + util.regexp.escape(list) + "]");
|
||||
},
|
||||
|
||||
get chromePackages() {
|
||||
@@ -822,6 +820,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
bottom: Math.min(r1.bottom, r2.bottom)
|
||||
}),
|
||||
|
||||
/**
|
||||
* Returns true if the given stack frame resides in Dactyl code.
|
||||
*
|
||||
* @param {nsIStackFrame} frame
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isDactyl: Class.memoize(function () {
|
||||
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
|
||||
let re = RegExp("^(resource://dactyl|" + base + ")\\S+( -> resource://dactyl(?!-content/eval.js)\\S+)?$");
|
||||
return function isDactyl(frame) re.test(frame.filename);
|
||||
}),
|
||||
|
||||
/**
|
||||
* Returns true if *url* is in the domain *domain*.
|
||||
*
|
||||
@@ -1340,6 +1350,16 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
if (isinstance(expr, ["RegExp"]))
|
||||
expr = expr.source;
|
||||
|
||||
expr = String.replace(expr, /\\(.)/, function (m, m1) {
|
||||
if (m1 === "c")
|
||||
flags = flags.replace(/i/g, "") + "i";
|
||||
else if (m === "C")
|
||||
flags = flags.replace(/i/g, "");
|
||||
else
|
||||
return m;
|
||||
return "";
|
||||
});
|
||||
|
||||
// Replace replacement <tokens>.
|
||||
if (tokens)
|
||||
expr = String.replace(expr, /(\(?P)?<(\w+)>/g, function (m, n1, n2) !n1 && set.has(tokens, n2) ? tokens[n2].dactylSource || tokens[n2].source || tokens[n2] : m);
|
||||
|
||||
Reference in New Issue
Block a user