1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 07:28:00 +01:00

Automagical macro command completion.

This commit is contained in:
Kris Maglione
2011-10-04 08:16:05 -04:00
parent a96716c2d8
commit a69eedc980
3 changed files with 39 additions and 3 deletions

View File

@@ -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,

View File

@@ -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

View File

@@ -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(