1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-03-04 17:05:46 +01:00

Hopefully remove some :abbrev silliiodocy.

This commit is contained in:
Kris Maglione
2010-10-18 00:07:19 -04:00
parent 1e3ce10290
commit 23a4bde382
4 changed files with 60 additions and 37 deletions

View File

@@ -72,16 +72,23 @@ const Abbreviations = Module("abbreviations", {
// TODO: Make keyword definition closer to Vim's default keyword // TODO: Make keyword definition closer to Vim's default keyword
// definition (which differs across platforms). // definition (which differs across platforms).
let nonkw = "\\s\"'"; let params = { // This is most definitely not Vim compatible.
let keyword = "[^" + nonkw + "]"; keyword: /[^\s"']/,
let nonkeyword = "[" + nonkw + "]"; nonkeyword: /[ "']/
};
let fullId = keyword + "+"; this._match = util.regexp(<><![CDATA[
let endId = nonkeyword + "+" + keyword; (^ | \s | <nonkeyword>) (<keyword>+ )$ | // full-id
let nonId = "\\S*" + nonkeyword; (^ | \s | <keyword> ) (<nonkeyword>+ <keyword>)$ | // end-id
(^ | \s ) (\S* <nonkeyword> )$ // non-id
// Used in add and expand ]]></>, "", params);
this._match = fullId + "|" + endId + "|" + nonId; this._check = util.regexp(<><![CDATA[
^ (?:
<keyword>+ | // full-id
<nonkeyword>+ <keyword> | // end-id
\S* <nonkeyword> // non-id
) $
]]></>, "", params);
}, },
/** /**
@@ -117,9 +124,9 @@ const Abbreviations = Module("abbreviations", {
* @returns {Abbreviation} * @returns {Abbreviation}
*/ */
match: function (mode, text) { match: function (mode, text) {
let match = text.match(RegExp('(' + abbreviations._match + ')$')); let match = this._match.exec(text);
if (match) if (match)
return abbreviations.get(mode, match[0]); return abbreviations.get(mode, match[2] || match[4] || match[6]);
return null; return null;
}, },
@@ -222,23 +229,20 @@ const Abbreviations = Module("abbreviations", {
modes.sort(); modes.sort();
modeDescription = modeDescription ? " in " + modeDescription + " mode" : ""; modeDescription = modeDescription ? " in " + modeDescription + " mode" : "";
// Why? --Kris
function splitAbbrev(abbrev) abbrev.match(RegExp("^(\\s*)($|" + abbreviations._match + ")(?:\\s*$|(\\s+)(.*))")) || [];
commands.add([ch ? ch + "a[bbrev]" : "ab[breviate]"], commands.add([ch ? ch + "a[bbrev]" : "ab[breviate]"],
"Abbreviate a key sequence" + modeDescription, "Abbreviate a key sequence" + modeDescription,
function (args) { function (args) {
let [,, lhs,, rhs] = splitAbbrev(args[0] || ""); let [lhs, rhs] = args;
dactyl.assert(lhs != null, "E474: Invalid argument"); dactyl.assert(!args.length || abbreviations._check.test(lhs),
"E474: Invalid argument");
if (rhs) { if (!rhs)
abbreviations.list(modes, lhs || "");
else {
if (args["-javascript"]) if (args["-javascript"])
rhs = Command.bindMacro({ literalArg: rhs }, "-javascript", ["editor"]); rhs = Command.bindMacro({ literalArg: rhs }, "-javascript", ["editor"]);
abbreviations.add(modes, lhs, rhs); abbreviations.add(modes, lhs, rhs);
} }
else {
abbreviations.list(modes, lhs || "");
}
}, { }, {
options: [ options: [
{ {
@@ -247,14 +251,12 @@ const Abbreviations = Module("abbreviations", {
} }
], ],
completer: function (context, args) { completer: function (context, args) {
let [, sp1, lhs, sp2, rhs] = splitAbbrev(args[0]); if (args.length == 1)
if (rhs == null)
return completion.abbreviation(context, args, modes) return completion.abbreviation(context, args, modes)
context.advance((sp1 + lhs + sp2).length); else if (args["-javascript"])
if (args["-javascript"])
return completion.javascript(context); return completion.javascript(context);
}, },
literal: 0, literal: 1,
serialize: function () [ serialize: function () [
{ {
command: this.name, command: this.name,

View File

@@ -164,14 +164,14 @@ const Highlights = Module("Highlight", {
this.set(k, null, true); this.set(k, null, true);
}, },
groupRegexp: RegExp(String.replace(<![CDATA[ groupRegexp: util.regexp(<![CDATA[
^ ^
(\s* (?:\S|\s\S)+ \s+) (\s* (?:\S|\s\S)+ \s+)
\{ ([^}]*) \} \{ ([^}]*) \}
\s* \s*
$ $
]]>, /\s*/g, ""), "gm"), ]]>, "gm"),
sheetRegexp: RegExp(String.replace(<![CDATA[ sheetRegexp: util.regexp(<![CDATA[
^\s* ^\s*
!? \*? !? \*?
( (?:[^;\s]|\s\S)+ ) ( (?:[^;\s]|\s\S)+ )
@@ -179,7 +179,7 @@ const Highlights = Module("Highlight", {
(?:; ( (?:[^ \s]|\s\S)+ ) )? (?:; ( (?:[^ \s]|\s\S)+ ) )?
\s* (.*) \s* (.*)
$ $
]]>, /\s*/g, "")), ]]>),
/** /**
* Bulk loads new CSS rules, in the format of, * Bulk loads new CSS rules, in the format of,

View File

@@ -258,9 +258,7 @@ const Styles = Module("Styles", {
}); });
}, },
propertyPattern: (function () { propertyPattern: util.regexp(<![CDATA[
const string = /(?:"(?:[^\\"]|\\.)*(?:"|$)|'(?:[^\\']|\\.)*(?:'|$))/.source;
return RegExp(String.replace(<![CDATA[
(?: (?:
(\s*) (\s*)
([-a-z]*) ([-a-z]*)
@@ -270,19 +268,18 @@ const Styles = Module("Styles", {
[-\w] [-\w]
(?: (?:
\s* \( \s* \s* \( \s*
(?: S | [^)]* ) (?: <string> | [^)]* )
\s* (?: \) | $) \s* (?: \) | $)
)? )?
\s* \s*
| \s* S \s* | [^;}]* | \s* <string> \s* | [^;}]*
)* )*
) )
)? )?
) )
(\s* (?: ; | $) ) (\s* (?: ; | $) )
]]>, /S/g, string).replace(/\s*/g, ""), ]]>, "gi",
"gi"); { string: /(?:"(?:[^\\"]|\\.)*(?:"|$)|'(?:[^\\']|\\.)*(?:'|$))/ })
})()
}, { }, {
commands: function (dactyl, modules, window) { commands: function (dactyl, modules, window) {
const commands = modules.commands; const commands = modules.commands;

View File

@@ -846,6 +846,30 @@ const Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
} }
}, },
/**
* Creates a new RegExp object based on the value of expr stripped
* of all white space and interpolated with the values from tokens.
* If tokens, any string in the form of <key> in expr is replaced
* with the value of the property, 'key', from tokens, if that
* property exists. If the property value is itself a RegExp, its
* source is substituted rather than its string value.
*
* Additionally, expr is stripped of all JavaScript comments.
*
* This is similar to Perl's extended regular expression format.
*
* @param {string|XML} expr The expression to compile into a RegExp.
* @param {string} flags Flags to apply to the new RegExp.
* @param {object} tokens The tokens to substitute. @optional
*/
regexp: function (expr, flags, tokens) {
if (tokens)
expr = String.replace(expr, /<(\w+)>/g, function (m, n1) set.has(tokens, n1) ? tokens[n1].source || tokens[n1] : m);
expr = String.replace(expr, /\/\/[^\n]*|\/\*[^]*?\*\//gm, "")
.replace(/\s+/g, "");
return RegExp(expr, flags);
},
maxErrors: 15, maxErrors: 15,
errors: Class.memoize(function () []), errors: Class.memoize(function () []),
reportError: function (error) { reportError: function (error) {