mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-03 11:15:46 +01:00
Allow \c/\C in regexp options and so forth.
This commit is contained in:
@@ -1276,7 +1276,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
let urls;
|
let urls;
|
||||||
|
|
||||||
if (options["urlseparator"])
|
if (options["urlseparator"])
|
||||||
urls = util.splitLiteral(str, RegExp("\\s*" + options["urlseparator"] + "\\s*"));
|
urls = util.splitLiteral(str, util.regexp("\\s*" + options["urlseparator"] + "\\s*"));
|
||||||
else
|
else
|
||||||
urls = [str];
|
urls = [str];
|
||||||
|
|
||||||
|
|||||||
@@ -300,6 +300,8 @@ var EventHive = Class("EventHive", Contexts.Hive, {
|
|||||||
* @param {function} callback The function to call when the event is received.
|
* @param {function} callback The function to call when the event is received.
|
||||||
* @param {boolean} capture When true, listen during the capture
|
* @param {boolean} capture When true, listen during the capture
|
||||||
* phase, otherwise during the bubbling phase.
|
* phase, otherwise during the bubbling phase.
|
||||||
|
* @param {boolean} allowUntrusted When true, allow capturing of
|
||||||
|
* untrusted events.
|
||||||
*/
|
*/
|
||||||
listen: function (target, event, callback, capture, allowUntrusted) {
|
listen: function (target, event, callback, capture, allowUntrusted) {
|
||||||
if (!isObject(event))
|
if (!isObject(event))
|
||||||
@@ -821,9 +823,7 @@ var Events = Module("events", {
|
|||||||
unknownOk = true;
|
unknownOk = true;
|
||||||
|
|
||||||
let out = [];
|
let out = [];
|
||||||
let re = RegExp("<.*?>?>|[^<]|<(?!.*>)", "g");
|
for (let match in util.regexp.iterate(/<.*?>?>|[^<]|<(?!.*>)/g, input)) {
|
||||||
let match;
|
|
||||||
while ((match = re.exec(input))) {
|
|
||||||
let evt_str = match[0];
|
let evt_str = match[0];
|
||||||
let evt_obj = { ctrlKey: false, shiftKey: false, altKey: false, metaKey: false,
|
let evt_obj = { ctrlKey: false, shiftKey: false, altKey: false, metaKey: false,
|
||||||
keyCode: 0, charCode: 0, type: "keypress" };
|
keyCode: 0, charCode: 0, type: "keypress" };
|
||||||
|
|||||||
@@ -847,8 +847,8 @@ var Hints = Module("hints", {
|
|||||||
* hints that match as above.
|
* hints that match as above.
|
||||||
*/
|
*/
|
||||||
function wordStartsWithMatcher(hintString, allowWordOverleaping) { //{{{
|
function wordStartsWithMatcher(hintString, allowWordOverleaping) { //{{{
|
||||||
let hintStrings = tokenize(/\s+/, hintString);
|
let hintStrings = tokenize(/\s+/, hintString);
|
||||||
let wordSplitRegexp = RegExp(options["wordseparators"]);
|
let wordSplitRegexp = util.regexp(options["wordseparators"]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Match a set of characters to the start of words.
|
* Match a set of characters to the start of words.
|
||||||
|
|||||||
@@ -15,10 +15,6 @@ defineModule("commands", {
|
|||||||
use: ["config", "messages", "options", "services", "template"]
|
use: ["config", "messages", "options", "services", "template"]
|
||||||
}, this);
|
}, 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.
|
* A structure representing the options available for a command.
|
||||||
*
|
*
|
||||||
@@ -692,7 +688,7 @@ var Commands = Module("commands", {
|
|||||||
repeat: null,
|
repeat: null,
|
||||||
|
|
||||||
add: function add() {
|
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.");
|
"User scripts may not add builtin commands. Please use group.commands.add instead.");
|
||||||
return this.builtin._add.apply(this.builtin, arguments);
|
return this.builtin._add.apply(this.builtin, arguments);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -903,7 +903,9 @@ var Completion = Module("completion", {
|
|||||||
url: function url(context, complete) {
|
url: function url(context, complete) {
|
||||||
|
|
||||||
if (this.options["urlseparator"])
|
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)
|
if (skip)
|
||||||
context.advance(skip[0].length);
|
context.advance(skip[0].length);
|
||||||
|
|
||||||
|
|||||||
@@ -406,12 +406,14 @@ var Highlights = Module("Highlight", {
|
|||||||
completion: function (dactyl, modules) {
|
completion: function (dactyl, modules) {
|
||||||
const { completion, config, io } = modules;
|
const { completion, config, io } = modules;
|
||||||
completion.colorScheme = function colorScheme(context) {
|
completion.colorScheme = function colorScheme(context) {
|
||||||
|
let extRe = RegExp("\\." + config.fileExtension + "$");
|
||||||
|
|
||||||
context.title = ["Color Scheme", "Runtime Path"];
|
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(
|
context.completions = array.flatten(
|
||||||
io.getRuntimeDirectories("colors").map(
|
io.getRuntimeDirectories("colors").map(
|
||||||
function (dir) dir.readDirectory().filter(
|
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 || "";
|
flags = this && this.regexpFlags || "";
|
||||||
|
|
||||||
let [, bang, val] = /^(!?)(.*)/.exec(value);
|
let [, bang, val] = /^(!?)(.*)/.exec(value);
|
||||||
let re = RegExp(Option.dequote(val), flags);
|
let re = util.regexp(Option.dequote(val), flags);
|
||||||
re.bang = bang;
|
re.bang = bang;
|
||||||
re.result = result !== undefined ? result : !bang;
|
re.result = result !== undefined ? result : !bang;
|
||||||
re.toString = function () Option.unparseRegexp(this, keepQuotes);
|
re.toString = function () Option.unparseRegexp(this, keepQuotes);
|
||||||
|
|||||||
@@ -413,7 +413,7 @@ var Styles = Module("Styles", {
|
|||||||
if (filter === "*")
|
if (filter === "*")
|
||||||
var test = function test(uri) true;
|
var test = function test(uri) true;
|
||||||
else if (!/^(?:[a-z-]+:|[a-z-.]+$)/.test(filter)) {
|
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);
|
test = function test(uri) re.test(uri.spec);
|
||||||
}
|
}
|
||||||
else if (/[*]$/.test(filter)) {
|
else if (/[*]$/.test(filter)) {
|
||||||
|
|||||||
@@ -177,20 +177,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
* @returns {RegExp}
|
* @returns {RegExp}
|
||||||
*/
|
*/
|
||||||
charListToRegexp: function charListToRegexp(list, accepted) {
|
charListToRegexp: function charListToRegexp(list, accepted) {
|
||||||
let list = list.replace(/\s+/g, "");
|
list = list.replace(/\s+/g, "");
|
||||||
|
|
||||||
// check for chars not in the accepted range
|
// check for chars not in the accepted range
|
||||||
this.assert(RegExp("^[" + accepted + "-]+$").test(list),
|
this.assert(RegExp("^[" + accepted + "-]+$").test(list),
|
||||||
"Character list outside the range " + accepted.quote());
|
"Character list outside the range " + accepted.quote());
|
||||||
|
|
||||||
// check for illegal ranges
|
// check for illegal ranges
|
||||||
let matches = list.match(RegExp("[" + accepted + "]-[" + accepted + "]", "g"));
|
for (let [match] in this.regexp.iterate(/.-./g, list))
|
||||||
if (matches) {
|
this.assert(match.charCodeAt(0) <= match.charCodeAt(2),
|
||||||
for (let match in values(matches))
|
"Invalid character range: " + list.slice(list.indexOf(match)))
|
||||||
this.assert(match[0] <= match[2],
|
|
||||||
"Invalid character range: " + list.match(match + ".*")[0]);
|
return RegExp("[" + util.regexp.escape(list) + "]");
|
||||||
}
|
|
||||||
return RegExp("[" + list + "]");
|
|
||||||
},
|
},
|
||||||
|
|
||||||
get chromePackages() {
|
get chromePackages() {
|
||||||
@@ -822,6 +820,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
bottom: Math.min(r1.bottom, r2.bottom)
|
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*.
|
* 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"]))
|
if (isinstance(expr, ["RegExp"]))
|
||||||
expr = expr.source;
|
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>.
|
// Replace replacement <tokens>.
|
||||||
if (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);
|
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