From cd208af2712ff1e0dfbb904b7bb91f737dfb87ad Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 17 Feb 2011 16:03:42 -0500 Subject: [PATCH] Allow specifying a group: prefix for Ex commands. --- common/modules/commands.jsm | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 39ed4c0f..0152310e 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -1129,7 +1129,9 @@ var Commands = Module("commands", { (?P (?P [:\s]*) (?P (?:\d+ | %)? ) - (?P (?: | !)? ) + (?P + (?: (?P ) : )? + (?P (?: | !)? )) (?P !?) (?P \s*) ) @@ -1164,7 +1166,7 @@ var Commands = Module("commands", { if (!matches) return []; - let [, spec, prespace, count, cmd, bang, space, args] = matches; + let { spec, count, group, cmd, bang, space, args } = matches; if (!cmd && bang) [cmd, bang] = [bang, cmd]; @@ -1177,13 +1179,17 @@ var Commands = Module("commands", { else count = this.COUNT_NONE; - return [count, cmd, !!bang, args || "", spec.length]; + return [count, cmd, !!bang, args || "", spec.length, group]; }, parseCommands: function (str, complete) { + const { contexts } = this.modules; do { - let [count, cmd, bang, args, len] = commands.parseCommand(str); - let command = this.get(cmd || ""); + let [count, cmd, bang, args, len, group] = commands.parseCommand(str); + if (!group) + var command = this.get(cmd || ""); + else if (group = contexts.getGroup(group, "commands")) + command = group.get(cmd || ""); if (command == null) { yield [null, { commandString: str }]; @@ -1274,12 +1280,15 @@ var Commands = Module("commands", { : ""](str) }, { completion: function initCompletion(dactyl, modules, window) { - const { completion } = modules; + const { completion, contexts } = modules; - completion.command = function command(context) { + completion.command = function command(context, group) { context.title = ["Command"]; context.keys = { text: "longNames", description: "description" }; - context.generate = function () modules.commands.hives.map(function (h) h._list).flatten(); + if (group) + context.generate = function () group._list; + else + context.generate = function () modules.commands.hives.map(function (h) h._list).flatten(); }; // provides completions for ex commands, including their arguments @@ -1298,9 +1307,12 @@ var Commands = Module("commands", { if (!match) return; + if (match.group) + context.advance(match.group.length + 1); + context.advance(match.prespace.length + match.count.length); if (!(match.bang || match.space)) { - context.fork("", 0, this, "command"); + context.fork("", 0, this, "command", match.group && contexts.getGroup(match.group, "commands")); return; } @@ -1312,7 +1324,7 @@ var Commands = Module("commands", { return; } - let cmdContext = context.fork(command.name, match.cmd.length + match.bang.length + match.space.length); + let cmdContext = context.fork(command.name, match.fullCmd.length + match.bang.length + match.space.length); try { if (!cmdContext.waitingForTab) { if (!args.completeOpt && command.completer && args.completeStart != null) {