1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-09 05:34:11 +01:00

Better option list filtering.

This commit is contained in:
Kris Maglione
2013-04-04 23:53:00 -07:00
parent e973f91e3d
commit 0a31fa5cab
3 changed files with 50 additions and 36 deletions

View File

@@ -1377,7 +1377,7 @@ function iter(obj, iface) {
else if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList])) else if (isinstance(obj, [Ci.nsIDOMHTMLCollection, Ci.nsIDOMNodeList]))
res = array.iterItems(obj); res = array.iterItems(obj);
else if (Ci.nsIDOMNamedNodeMap && obj instanceof Ci.nsIDOMNamedNodeMap || else if (Ci.nsIDOMNamedNodeMap && obj instanceof Ci.nsIDOMNamedNodeMap ||
Ci.nsIDOMMozNamedNodeMap && obj instanceof Ci.nsIDOMMozNamedNodeMap) Ci.nsIDOMMozNamedAttrMap && obj instanceof Ci.nsIDOMMozNamedAttrMap)
res = (function () { res = (function () {
for (let i = 0; i < obj.length; i++) for (let i = 0; i < obj.length; i++)
yield [obj.name, obj]; yield [obj.name, obj];

View File

@@ -109,6 +109,7 @@ update(CommandOption, {
* @param {function} action The action invoked by this command when executed. * @param {function} action The action invoked by this command when executed.
* @param {Object} extraInfo An optional extra configuration hash. The * @param {Object} extraInfo An optional extra configuration hash. The
* following properties are supported. * following properties are supported.
* always - see {@link Command#always}
* argCount - see {@link Command#argCount} * argCount - see {@link Command#argCount}
* bang - see {@link Command#bang} * bang - see {@link Command#bang}
* completer - see {@link Command#completer} * completer - see {@link Command#completer}
@@ -243,28 +244,41 @@ var Command = Class("Command", {
* @property {function (Args)} The function called to execute this command. * @property {function (Args)} The function called to execute this command.
*/ */
action: null, action: null,
/**
* @property {function (Args)} A function which is called when this
* command is encountered, even if we are ignoring commands. Used to
* implement control structures.
*/
always: null,
/** /**
* @property {string} This command's argument count spec. * @property {string} This command's argument count spec.
* @see Commands#parseArguments * @see Commands#parseArguments
*/ */
argCount: 0, argCount: 0,
/** /**
* @property {function (CompletionContext, Args)} This command's completer. * @property {function (CompletionContext, Args)} This command's completer.
* @see CompletionContext * @see CompletionContext
*/ */
completer: null, completer: null,
/** @property {boolean} Whether this command accepts a here document. */ /** @property {boolean} Whether this command accepts a here document. */
hereDoc: false, hereDoc: false,
/** /**
* @property {boolean} Whether this command may be called with a bang, * @property {boolean} Whether this command may be called with a bang,
* e.g., :com! * e.g., :com!
*/ */
bang: false, bang: false,
/** /**
* @property {boolean} Whether this command may be called with a count, * @property {boolean} Whether this command may be called with a count,
* e.g., :12bdel * e.g., :12bdel
*/ */
count: false, count: false,
/** /**
* @property {function(args)} A function which should return a list * @property {function(args)} A function which should return a list
* of domains referenced in the given args. Used in determining * of domains referenced in the given args. Used in determining
@@ -272,6 +286,7 @@ var Command = Class("Command", {
* private data. * private data.
*/ */
domains: function (args) [], domains: function (args) [],
/** /**
* @property {boolean} At what index this command's literal arguments * @property {boolean} At what index this command's literal arguments
* begin. For instance, with a value of 2, all arguments starting with * begin. For instance, with a value of 2, all arguments starting with
@@ -280,6 +295,7 @@ var Command = Class("Command", {
* key mappings or Ex command lines as arguments. * key mappings or Ex command lines as arguments.
*/ */
literal: null, literal: null,
/** /**
* @property {Array} The options this command takes. * @property {Array} The options this command takes.
* @see Commands@parseArguments * @see Commands@parseArguments
@@ -1760,39 +1776,37 @@ var Commands = Module("commands", {
} }
}); });
(function () { let quote = function quote(q, list, map) {
map = map || Commands.quoteMap;
let re = RegExp("[" + list + "]", "g");
function quote(str) q + String.replace(str, re, function ($0) $0 in map ? map[$0] : ("\\" + $0)) + q;
quote.list = list;
return quote;
};
Commands.quoteMap = { Commands.quoteMap = {
"\n": "\\n", "\n": "\\n",
"\t": "\\t", "\t": "\\t",
}; };
function quote(q, list, map) {
map = map || Commands.quoteMap;
let re = RegExp("[" + list + "]", "g");
function quote(str) q + String.replace(str, re, function ($0) $0 in map ? map[$0] : ("\\" + $0)) + q;
quote.list = list;
return quote;
};
Commands.quoteArg = { Commands.quoteArg = {
'"': quote('"', '\n\t"\\\\'), '"': quote('"', '\n\t"\\\\'),
"'": quote("'", "'", { "'": "''" }), "'": quote("'", "'", { "'": "''" }),
"": quote("", "|\\\\\\s'\"") "": quote("", "|\\\\\\s'\"")
}; };
Commands.complQuote = { Commands.complQuote = {
'"': ['"', quote("", Commands.quoteArg['"'].list), '"'], '"': ['"', quote("", Commands.quoteArg['"'].list), '"'],
"'": ["'", quote("", Commands.quoteArg["'"].list), "'"], "'": ["'", quote("", Commands.quoteArg["'"].list), "'"],
"": ["", Commands.quoteArg[""], ""] "": ["", Commands.quoteArg[""], ""]
}; };
Commands.parseBool = function (arg) { Commands.parseBool = function (arg) {
if (/^(true|1|on)$/i.test(arg)) if (/^(true|1|on)$/i.test(arg))
return true; return true;
if (/^(false|0|off)$/i.test(arg)) if (/^(false|0|off)$/i.test(arg))
return false; return false;
return NaN; return NaN;
}; };
})();
endModule(); endModule();

View File

@@ -854,6 +854,11 @@ var Options = Module("options", {
function opts(opt) { function opts(opt) {
for (let opt in Iterator(this)) { for (let opt in Iterator(this)) {
if (filter && !filter(opt))
continue;
if (!(opt.scope & scope))
continue;
let option = { let option = {
__proto__: opt, __proto__: opt,
isDefault: opt.isDefault, isDefault: opt.isDefault,
@@ -862,11 +867,6 @@ var Options = Module("options", {
value: [] value: []
}; };
if (filter && !filter(opt))
continue;
if (!(opt.scope & scope))
continue;
if (opt.type == "boolean") { if (opt.type == "boolean") {
if (!opt.value) if (!opt.value)
option.pre = "no"; option.pre = "no";