X-Git-Url: https://git.donarmstrong.com/?p=dactyl.git;a=blobdiff_plain;f=common%2Fmodules%2Fcommands.jsm;fp=common%2Fmodules%2Fcommands.jsm;h=0fab7bcbe4d4ecbe8160ecff6d6b949226e0c1f8;hp=0e0d58fc8b6468f2961eea1c7e50d6f96feef2e5;hb=247daf849abc85f4cfb10fa358c62c8daf8db95b;hpb=354a049cce8415487552ce405cce167b7071fe1f diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 0e0d58f..0fab7bc 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -1,6 +1,6 @@ // Copyright (c) 2006-2008 by Martin Stubenschrott // Copyright (c) 2007-2011 by Doug Kearns -// Copyright (c) 2008-2013 Kris Maglione +// Copyright (c) 2008-2014 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. @@ -155,7 +155,7 @@ var Command = Class("Command", { * @param {Args} args The Args object passed to {@link #action}. * @param {Object} modifiers Any modifiers to be passed to {@link #action}. */ - execute: function execute(args, modifiers = {}) { + execute: function execute(args, modifiers={}) { const { dactyl } = this.modules; let context = args.context; @@ -210,7 +210,7 @@ var Command = Class("Command", { extra: extra }), - complained: Class.Memoize(function () ({})), + complained: Class.Memoize(function () RealSet()), /** * @property {[string]} All of this command's name specs. e.g., "com[mand]" @@ -325,7 +325,8 @@ var Command = Class("Command", { explicitOpts: Class.Memoize(function () ({})), - has: function AP_has(opt) Set.has(this.explicitOpts, opt) || typeof opt === "number" && Set.has(this, opt), + has: function AP_has(opt) hasOwnProperty(this.explicitOpts, opt) + || typeof opt === "number" && hasOwnProperty(this, opt), get literalArg() this.command.literal != null && this[this.command.literal] || "", @@ -402,7 +403,9 @@ var Command = Class("Command", { warn: function warn(context, type, message) { let loc = !context ? "" : [context.file, context.line, " "].join(":"); - if (!Set.add(this.complained, type + ":" + (context ? context.file : "[Command Line]"))) + let key = type + ":" + (context ? context.file : "[Command Line]"); + + if (!this.complained.add(key)) this.modules.dactyl.warn(loc + message); } }, { @@ -498,22 +501,21 @@ var CommandHive = Class("CommandHive", Contexts.Hive, { */ cache: function cache() { - let self = this; let { cache } = this.modules; this.cached = true; - let cached = cache.get(this.cacheKey, function () { - self.cached = false; + let cached = cache.get(this.cacheKey, () => { + this.cached = false; this.modules.moduleManager.initDependencies("commands"); let map = {}; - for (let [name, cmd] in Iterator(self._map)) + for (let [name, cmd] in Iterator(this._map)) if (cmd.sourceModule) map[name] = { sourceModule: cmd.sourceModule, isPlaceholder: true }; let specs = []; - for (let cmd in values(self._list)) - for each (let spec in cmd.parsedSpecs) + for (let cmd of this._list) + for (let spec of cmd.parsedSpecs) specs.push(spec.concat(cmd.name)); return { map: map, specs: specs }; @@ -553,7 +555,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, { * @param {boolean} replace Replace an existing command of the same name. * @optional */ - add: function add(specs, description, action, extra = {}, replace = false) { + add: function add(specs, description, action, extra={}, replace=false) { const { commands, contexts } = this.modules; if (!extra.definedAt) @@ -592,7 +594,7 @@ var CommandHive = Class("CommandHive", Contexts.Hive, { return name; }, - _add: function _add(names, description, action, extra = {}, replace = false) { + _add: function _add(names, description, action, extra={}, replace=false) { const { contexts } = this.modules; extra.definedAt = contexts.getCaller(Components.stack.caller.caller); return this.add.apply(this, arguments); @@ -619,11 +621,12 @@ var CommandHive = Class("CommandHive", Contexts.Hive, { */ get: function get(name, full) { let cmd = this._map[name] - || !full && array.nth(this._list, cmd => cmd.hasName(name), 0) + || !full && this._list.find(cmd => cmd.hasName(name)) || null; if (!cmd && full) { - let name = array.nth(this.specs, spec => Command.hasName(spec, name), 0); + // Hrm. This is wrong. -Kris + let name = this._specs.find(spec => Command.hasName(spec, name)); return name && this.get(name); } @@ -756,11 +759,11 @@ var Commands = Module("commands", { const { commandline, completion } = this.modules; function completerToString(completer) { if (completer) - return [k for ([k, v] in Iterator(config.completers)) if (completer == completion.closure[v])][0] || "custom"; + return [k for ([k, v] in Iterator(config.completers)) if (completer == completion.bound[v])][0] || "custom"; return ""; } // TODO: allow matching of aliases? - function cmds(hive) hive._list.filter(cmd => cmd.name.indexOf(filter || "") == 0) + function cmds(hive) hive._list.filter(cmd => cmd.name.startsWith(filter || "")) let hives = (hives || this.userHives).map(h => [h, cmds(h)]) .filter(([h, c]) => c.length); @@ -828,9 +831,9 @@ var Commands = Module("commands", { return group._add.apply(group, arguments); }, - addUserCommand: deprecated("group.commands.add", { get: function addUserCommand() this.user.closure._add }), + addUserCommand: deprecated("group.commands.add", { get: function addUserCommand() this.user.bound._add }), getUserCommands: deprecated("iter(group.commands)", function getUserCommands() iter(this.user).toArray()), - removeUserCommand: deprecated("group.commands.remove", { get: function removeUserCommand() this.user.closure.remove }), + removeUserCommand: deprecated("group.commands.remove", { get: function removeUserCommand() this.user.bound.remove }), /** * Returns the specified command invocation object serialized to @@ -880,7 +883,7 @@ var Commands = Module("commands", { * @returns {Command} */ get: function get(name, full) iter(this.hives).map(([i, hive]) => hive.get(name, full)) - .nth(util.identity, 0), + .find(util.identity), /** * Returns true if a command invocation contains a URL referring to the @@ -964,7 +967,7 @@ var Commands = Module("commands", { * Args object. * @returns {Args} */ - parseArgs: function parseArgs(str, params = {}) { + parseArgs: function parseArgs(str, params={}) { const self = this; function getNextArg(str, _keepQuotes=keepQuotes) { @@ -1011,7 +1014,7 @@ var Commands = Module("commands", { let matchOpts = function matchOpts(arg) { // Push possible option matches into completions if (complete && !onlyArgumentsRemaining) - completeOpts = options.filter(opt => (opt.multiple || !Set.has(args, opt.names[0]))); + completeOpts = options.filter(opt => (opt.multiple || !hasOwnProperty(args, opt.names[0]))); }; let resetCompletions = function resetCompletions() { completeOpts = null; @@ -1063,7 +1066,7 @@ var Commands = Module("commands", { if (!onlyArgumentsRemaining) { for (let [, opt] in Iterator(options)) { for (let [, optname] in Iterator(opt.names)) { - if (sub.indexOf(optname) == 0) { + if (sub.startsWith(optname)) { let count = 0; let invalid = false; let arg, quote, quoted; @@ -1110,7 +1113,7 @@ var Commands = Module("commands", { if (arg == null || (typeof arg == "number" && isNaN(arg))) { if (!complete || orig != "" || args.completeStart != str.length) - fail(_("command.invalidOptTypeArg", opt.type.description, optname, argString)); + fail(_("command.invalidOptTypeArg", opt.type.description, optname, quoted)); if (complete) complete.highlight(args.completeStart, count - 1, "SPELLCHECK"); } @@ -1119,7 +1122,7 @@ var Commands = Module("commands", { // we have a validator function if (typeof opt.validator == "function") { if (opt.validator(arg, quoted) == false && (arg || !complete)) { - fail(_("command.invalidOptArg", optname, argString)); + fail(_("command.invalidOptArg", optname, quoted)); if (complete) // Always true. complete.highlight(args.completeStart, count - 1, "SPELLCHECK"); } @@ -1543,7 +1546,7 @@ var Commands = Module("commands", { function (args) { let cmd = args[0]; - util.assert(!cmd || cmd.split(",").every(commands.validName.closure.test), + util.assert(!cmd || cmd.split(",").every(commands.validName.bound.test), _("command.invalidName", cmd)); if (args.length <= 1) @@ -1573,7 +1576,7 @@ var Commands = Module("commands", { }; } else - completerFunc = context => modules.completion.closure[config.completers[completer]](context); + completerFunc = context => modules.completion.bound[config.completers[completer]](context); } let added = args["-group"].add(cmd.split(","), @@ -1721,7 +1724,7 @@ var Commands = Module("commands", { ] })), iterateIndex: function (args) let (tags = help.tags) - this.iterate(args).filter(cmd => (cmd.hive === commands.builtin || Set.has(tags, cmd.helpTag))), + this.iterate(args).filter(cmd => (cmd.hive === commands.builtin || hasOwnProperty(tags, cmd.helpTag))), format: { headings: ["Command", "Group", "Description"], description: function (cmd) template.linkifyHelp(cmd.description + (cmd.replacementText ? ": " + cmd.action : "")), @@ -1772,7 +1775,7 @@ var Commands = Module("commands", { } }); -let quote = function quote(q, list, map = Commands.quoteMap) { +let quote = function quote(q, list, map=Commands.quoteMap) { let re = RegExp("[" + list + "]", "g"); function quote(str) (q + String.replace(str, re, $0 => ($0 in map ? map[$0] : ("\\" + $0))) + q);