1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-28 07:12:27 +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]))
res = array.iterItems(obj);
else if (Ci.nsIDOMNamedNodeMap && obj instanceof Ci.nsIDOMNamedNodeMap ||
Ci.nsIDOMMozNamedNodeMap && obj instanceof Ci.nsIDOMMozNamedNodeMap)
Ci.nsIDOMMozNamedAttrMap && obj instanceof Ci.nsIDOMMozNamedAttrMap)
res = (function () {
for (let i = 0; i < obj.length; i++)
yield [obj.name, obj];

View File

@@ -109,6 +109,7 @@ update(CommandOption, {
* @param {function} action The action invoked by this command when executed.
* @param {Object} extraInfo An optional extra configuration hash. The
* following properties are supported.
* always - see {@link Command#always}
* argCount - see {@link Command#argCount}
* bang - see {@link Command#bang}
* completer - see {@link Command#completer}
@@ -243,28 +244,41 @@ var Command = Class("Command", {
* @property {function (Args)} The function called to execute this command.
*/
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.
* @see Commands#parseArguments
*/
argCount: 0,
/**
* @property {function (CompletionContext, Args)} This command's completer.
* @see CompletionContext
*/
completer: null,
/** @property {boolean} Whether this command accepts a here document. */
hereDoc: false,
/**
* @property {boolean} Whether this command may be called with a bang,
* e.g., :com!
*/
bang: false,
/**
* @property {boolean} Whether this command may be called with a count,
* e.g., :12bdel
*/
count: false,
/**
* @property {function(args)} A function which should return a list
* of domains referenced in the given args. Used in determining
@@ -272,6 +286,7 @@ var Command = Class("Command", {
* private data.
*/
domains: function (args) [],
/**
* @property {boolean} At what index this command's literal arguments
* 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.
*/
literal: null,
/**
* @property {Array} The options this command takes.
* @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 = {
"\n": "\\n",
"\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.quoteMap = {
"\n": "\\n",
"\t": "\\t",
};
Commands.quoteArg = {
'"': quote('"', '\n\t"\\\\'),
"'": quote("'", "'", { "'": "''" }),
"": quote("", "|\\\\\\s'\"")
};
Commands.complQuote = {
'"': ['"', quote("", Commands.quoteArg['"'].list), '"'],
"'": ["'", quote("", Commands.quoteArg["'"].list), "'"],
"": ["", Commands.quoteArg[""], ""]
};
Commands.quoteArg = {
'"': quote('"', '\n\t"\\\\'),
"'": quote("'", "'", { "'": "''" }),
"": quote("", "|\\\\\\s'\"")
};
Commands.complQuote = {
'"': ['"', quote("", Commands.quoteArg['"'].list), '"'],
"'": ["'", quote("", Commands.quoteArg["'"].list), "'"],
"": ["", Commands.quoteArg[""], ""]
};
Commands.parseBool = function (arg) {
if (/^(true|1|on)$/i.test(arg))
return true;
if (/^(false|0|off)$/i.test(arg))
return false;
return NaN;
};
})();
Commands.parseBool = function (arg) {
if (/^(true|1|on)$/i.test(arg))
return true;
if (/^(false|0|off)$/i.test(arg))
return false;
return NaN;
};
endModule();

View File

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