diff --git a/common/content/editor.js b/common/content/editor.js index 7e83fd65..4dc001b0 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -35,7 +35,7 @@ var Editor = Module("editor", { return controllers.getControllerForCommand(cmd || "cmd_beginLine"); }, - get selection() this.editor && this.editor.selection, + get selection() this.editor && this.editor.selection || null, get isCaret() modes.getStack(1).main == modes.CARET, get isTextEdit() modes.getStack(1).main == modes.TEXT_EDIT, diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index d9fbe68e..9cb254b4 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -1399,6 +1399,41 @@ var Commands = Module("commands", { } }; + completion.exMacro = function exMacro(context, args, cmd) { + util.dump(cmd.action.macro, cmd.action); + if (!cmd.action.macro) + return; + let { macro } = cmd.action; + + let start = "«%-d-]'", end = "'[-d-%»"; + + let n = /^\d+$/.test(cmd.argCount) ? parseInt(argCount) : 12; + for (let i = args.completeArg; i < n; i++) + args[i] = start + i + end; + + let params = { + args: { __proto__: args, toString: function () this.join(" ") }, + bang: args.bang ? "!" : "", + count: args.count + }; + + if (!macro.valid(params)) + return; + + let str = macro(params); + let idx = str.indexOf(start); + if (!~idx || !/^(')?(\d+)'/.test(str.substr(idx + start.length)) + || RegExp.$2 != args.completeArg) + return; + + let quote = RegExp.$2; + context.quote = null; + context.offset -= idx; + context.filter = str.substr(0, idx) + (quote ? Option.quote : util.identity)(context.filter); + + context.fork("ex", 0, completion, "ex"); + }; + completion.userCommand = function userCommand(context, group) { context.title = ["User Command", "Definition"]; context.keys = { text: "name", description: "replacementText" }; @@ -1431,7 +1466,7 @@ var Commands = Module("commands", { _("group.cantChangeBuiltin", _("command.commands"))); let completer = args["-complete"]; - let completerFunc = null; // default to no completion for user commands + let completerFunc = function (context, args) modules.completion.exMacro(context, args, this); if (completer) { if (/^custom,/.test(completer)) { @@ -1460,7 +1495,7 @@ var Commands = Module("commands", { function makeParams(args, modifiers) ({ args: { __proto__: args, - toString: function () this.string, + toString: function () this.string }, bang: this.bang && args.bang ? "!" : "", count: this.count && args.count diff --git a/common/modules/util.jsm b/common/modules/util.jsm index af2d0897..a2e7b994 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -378,6 +378,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), if (Set.has(defaults, name)) stack.top.elements.push(quote(defaults[name])); else { + let index = idx; if (idx) { idx = Number(idx) - 1; stack.top.elements.push(update(