// Copyright (c) 2006-2008 by Martin Stubenschrott <stubenschrott@vimperator.org>
// Copyright (c) 2007-2011 by Doug Kearns <dougkearns@gmail.com>
-// Copyright (c) 2008-2013 Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
* @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;
extra: extra
}),
- complained: Class.Memoize(function () ({})),
+ complained: Class.Memoize(function () RealSet()),
/**
* @property {[string]} All of this command's name specs. e.g., "com[mand]"
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] || "",
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);
}
}, {
*/
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 };
* @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)
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);
*/
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);
}
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);
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
* @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
* Args object.
* @returns {Args}
*/
- parseArgs: function parseArgs(str, params = {}) {
+ parseArgs: function parseArgs(str, params={}) {
const self = this;
function getNextArg(str, _keepQuotes=keepQuotes) {
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;
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;
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");
}
// 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");
}
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)
};
}
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(","),
]
})),
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 : "")),
}
});
-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);