mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 09:27:58 +01:00
Automagical macro command completion.
This commit is contained in:
@@ -35,7 +35,7 @@ var Editor = Module("editor", {
|
|||||||
return controllers.getControllerForCommand(cmd || "cmd_beginLine");
|
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 isCaret() modes.getStack(1).main == modes.CARET,
|
||||||
get isTextEdit() modes.getStack(1).main == modes.TEXT_EDIT,
|
get isTextEdit() modes.getStack(1).main == modes.TEXT_EDIT,
|
||||||
|
|||||||
@@ -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) {
|
completion.userCommand = function userCommand(context, group) {
|
||||||
context.title = ["User Command", "Definition"];
|
context.title = ["User Command", "Definition"];
|
||||||
context.keys = { text: "name", description: "replacementText" };
|
context.keys = { text: "name", description: "replacementText" };
|
||||||
@@ -1431,7 +1466,7 @@ var Commands = Module("commands", {
|
|||||||
_("group.cantChangeBuiltin", _("command.commands")));
|
_("group.cantChangeBuiltin", _("command.commands")));
|
||||||
|
|
||||||
let completer = args["-complete"];
|
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 (completer) {
|
||||||
if (/^custom,/.test(completer)) {
|
if (/^custom,/.test(completer)) {
|
||||||
@@ -1460,7 +1495,7 @@ var Commands = Module("commands", {
|
|||||||
function makeParams(args, modifiers) ({
|
function makeParams(args, modifiers) ({
|
||||||
args: {
|
args: {
|
||||||
__proto__: args,
|
__proto__: args,
|
||||||
toString: function () this.string,
|
toString: function () this.string
|
||||||
},
|
},
|
||||||
bang: this.bang && args.bang ? "!" : "",
|
bang: this.bang && args.bang ? "!" : "",
|
||||||
count: this.count && args.count
|
count: this.count && args.count
|
||||||
|
|||||||
@@ -378,6 +378,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
|||||||
if (Set.has(defaults, name))
|
if (Set.has(defaults, name))
|
||||||
stack.top.elements.push(quote(defaults[name]));
|
stack.top.elements.push(quote(defaults[name]));
|
||||||
else {
|
else {
|
||||||
|
let index = idx;
|
||||||
if (idx) {
|
if (idx) {
|
||||||
idx = Number(idx) - 1;
|
idx = Number(idx) - 1;
|
||||||
stack.top.elements.push(update(
|
stack.top.elements.push(update(
|
||||||
|
|||||||
Reference in New Issue
Block a user