mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 20:52:26 +01:00
initial crack at :command -complete - YALNS
This commit is contained in:
2
NEWS
2
NEWS
@@ -27,7 +27,7 @@
|
|||||||
* add . mapping
|
* add . mapping
|
||||||
* add N% normal mode command
|
* add N% normal mode command
|
||||||
* add interpolation for items such as <url> to autocommands
|
* add interpolation for items such as <url> to autocommands
|
||||||
* add -nargs, -bang, and -count attribute support to :command
|
* add -nargs, -complete, -bang, and -count attribute support to :command
|
||||||
* much improved completion support, including javascript, option, and search keyword
|
* much improved completion support, including javascript, option, and search keyword
|
||||||
* add <PageUp>/<S-Up> and <PageDown>/<S-Down> command-line mappings for
|
* add <PageUp>/<S-Up> and <PageDown>/<S-Down> command-line mappings for
|
||||||
selecting the previous and next history items
|
selecting the previous and next history items
|
||||||
|
|||||||
@@ -668,6 +668,11 @@ function Commands() //{{{
|
|||||||
liberator.execute(commands.replaceTokens(this.replacementText, tokens));
|
liberator.execute(commands.replaceTokens(this.replacementText, tokens));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add dir, highlight, menu, option completers
|
||||||
|
var completeOptionMap = { url: "url", buffer: "buffer", bookmark: "bookmark", command: "ex",
|
||||||
|
environment: "environment", event: "autocmdEvent", file: "file", shellcmd: "shellCommand",
|
||||||
|
javascript: "javascript", help: "help", mapping: "userMapping" };
|
||||||
|
|
||||||
// TODO: Vim allows commands to be defined without {rep} if there are {attr}s
|
// TODO: Vim allows commands to be defined without {rep} if there are {attr}s
|
||||||
// specified - useful?
|
// specified - useful?
|
||||||
commandManager.add(["com[mand]"],
|
commandManager.add(["com[mand]"],
|
||||||
@@ -684,9 +689,24 @@ function Commands() //{{{
|
|||||||
|
|
||||||
if (args.literalArg)
|
if (args.literalArg)
|
||||||
{
|
{
|
||||||
let nargsOpt = args["-nargs"] || "0";
|
let nargsOpt = args["-nargs"] || "0";
|
||||||
let bangOpt = "-bang" in args;
|
let bangOpt = "-bang" in args;
|
||||||
let countOpt = "-count" in args;
|
let countOpt = "-count" in args;
|
||||||
|
let completeOpt = args["-complete"];
|
||||||
|
|
||||||
|
let completeFunc = null; // default to no completion for user commands
|
||||||
|
|
||||||
|
if (completeOpt)
|
||||||
|
{
|
||||||
|
let func;
|
||||||
|
|
||||||
|
if (/^custom,/.test(completeOpt))
|
||||||
|
func = completeOpt.replace("custom,", "");
|
||||||
|
else
|
||||||
|
func = "completion." + completeOptionMap[completeOpt];
|
||||||
|
|
||||||
|
completeFunc = eval(func);
|
||||||
|
}
|
||||||
|
|
||||||
if (!commands.addUserCommand(
|
if (!commands.addUserCommand(
|
||||||
[cmd],
|
[cmd],
|
||||||
@@ -696,6 +716,7 @@ function Commands() //{{{
|
|||||||
argCount: nargsOpt,
|
argCount: nargsOpt,
|
||||||
bang: bangOpt,
|
bang: bangOpt,
|
||||||
count: countOpt,
|
count: countOpt,
|
||||||
|
completer: completeFunc,
|
||||||
replacementText: args.literalArg
|
replacementText: args.literalArg
|
||||||
},
|
},
|
||||||
special)
|
special)
|
||||||
@@ -706,17 +727,27 @@ function Commands() //{{{
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
function completerToString(completer)
|
||||||
|
{
|
||||||
|
if (completer)
|
||||||
|
return [k for ([k, v] in Iterator(completeOptionMap))
|
||||||
|
if (v == completer.name)][0] || "custom";
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: using an array comprehension here generates flakey results across repeated calls
|
// TODO: using an array comprehension here generates flakey results across repeated calls
|
||||||
// : perhaps we shouldn't allow options in a list call but just ignore them for now
|
// : perhaps we shouldn't allow options in a list call but just ignore them for now
|
||||||
let cmds = exCommands.filter(function (c) c.isUserCommand && (!cmd || c.name.match("^" + cmd)));
|
let cmds = exCommands.filter(function (c) c.isUserCommand && (!cmd || c.name.match("^" + cmd)));
|
||||||
|
|
||||||
if (cmds.length > 0)
|
if (cmds.length > 0)
|
||||||
{
|
{
|
||||||
let str = template.tabular(["", "Name", "Args", "Range", "Definition"], ["padding-right: 2em;"],
|
let str = template.tabular(["", "Name", "Args", "Range", "Complete", "Definition"], ["padding-right: 2em;"],
|
||||||
([cmd.bang ? "!" : " ",
|
([cmd.bang ? "!" : " ",
|
||||||
cmd.name,
|
cmd.name,
|
||||||
cmd.argCount,
|
cmd.argCount,
|
||||||
cmd.count ? "0c" : "",
|
cmd.count ? "0c" : "",
|
||||||
|
completerToString(cmd.completer),
|
||||||
cmd.replacementText || "function () { ... }"] for each (cmd in cmds)));
|
cmd.replacementText || "function () { ... }"] for each (cmd in cmds)));
|
||||||
|
|
||||||
commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
|
||||||
@@ -732,9 +763,12 @@ function Commands() //{{{
|
|||||||
bang: true,
|
bang: true,
|
||||||
completer: function (filter) completion.userCommand(filter),
|
completer: function (filter) completion.userCommand(filter),
|
||||||
options: [
|
options: [
|
||||||
[["-nargs"], commandManager.OPTION_STRING, function (arg) /^[01*?+]$/.test(arg), ["0", "1", "*", "?", "+"]],
|
[["-nargs"], commandManager.OPTION_STRING,
|
||||||
[["-bang"], commandManager.OPTION_NOARG],
|
function (arg) /^[01*?+]$/.test(arg), ["0", "1", "*", "?", "+"]],
|
||||||
|
[["-bang"], commandManager.OPTION_NOARG],
|
||||||
[["-count"], commandManager.OPTION_NOARG],
|
[["-count"], commandManager.OPTION_NOARG],
|
||||||
|
[["-complete"], commandManager.OPTION_STRING,
|
||||||
|
function (arg) arg in completeOptionMap || /custom,\w+/.test(arg)]
|
||||||
],
|
],
|
||||||
literal: true,
|
literal: true,
|
||||||
serial: function () [
|
serial: function () [
|
||||||
|
|||||||
@@ -923,7 +923,7 @@ function Completion() //{{{
|
|||||||
return [0, this.filter(vars, filter)];
|
return [0, this.filter(vars, filter)];
|
||||||
},
|
},
|
||||||
|
|
||||||
event: function event(filter) [0, this.filter(config.autocommands, filter)],
|
autocmdEvent: function autocmdEvent(filter) [0, this.filter(config.autocommands, filter)],
|
||||||
|
|
||||||
// provides completions for ex commands, including their arguments
|
// provides completions for ex commands, including their arguments
|
||||||
ex: function ex(str)
|
ex: function ex(str)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ function AutoCommands() //{{{
|
|||||||
{
|
{
|
||||||
let values = value.split(",");
|
let values = value.split(",");
|
||||||
let events = config.autocommands.map(function (event) event[0]);
|
let events = config.autocommands.map(function (event) event[0]);
|
||||||
|
|
||||||
events.push("all");
|
events.push("all");
|
||||||
|
|
||||||
return values.every(function (event) events.indexOf(event) >= 0);
|
return values.every(function (event) events.indexOf(event) >= 0);
|
||||||
@@ -113,7 +114,7 @@ function AutoCommands() //{{{
|
|||||||
{
|
{
|
||||||
argCount: "3",
|
argCount: "3",
|
||||||
bang: true,
|
bang: true,
|
||||||
completer: function (filter) completion.event(filter),
|
completer: function (filter) completion.autocmdEvent(filter),
|
||||||
literal: true
|
literal: true
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -126,7 +127,7 @@ function AutoCommands() //{{{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
argCount: "+",
|
argCount: "+",
|
||||||
completer: function (filter) completion.event(filter)
|
completer: function (filter) completion.autocmdEvent(filter)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ function AutoCommands() //{{{
|
|||||||
{
|
{
|
||||||
// TODO: Vim actually just displays "No matching autocommands" when no arg is specified
|
// TODO: Vim actually just displays "No matching autocommands" when no arg is specified
|
||||||
argCount: "+",
|
argCount: "+",
|
||||||
completer: function (filter) completion.event(filter)
|
completer: function (filter) completion.autocmdEvent(filter)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -286,6 +286,40 @@ The valid values are:
|
|||||||
*-nargs=+* One or more argument is allowd
|
*-nargs=+* One or more argument is allowd
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|E180| |E181| |:command-complete| +
|
||||||
|
Argument completion
|
||||||
|
|
||||||
|
Completion for arguments to user defined commands is not available by default.
|
||||||
|
Completion can be enabled by specifying one of the following arguments to the
|
||||||
|
-complete option when defining the command.
|
||||||
|
`----------------`--------------------------------------------------------------
|
||||||
|
*bookmark* bookmarks
|
||||||
|
*buffer* buffers
|
||||||
|
*command* Ex commands
|
||||||
|
*environment* environment variables
|
||||||
|
*event* autocommand events
|
||||||
|
*file* files
|
||||||
|
*help* help tags
|
||||||
|
*javascript* javascript
|
||||||
|
*mapping* user mappings
|
||||||
|
*shellcmd* shell commands
|
||||||
|
*url* URLs
|
||||||
|
*custom,{func}* custom completion, provided by {func}
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|E467| |E468| |:command-completion-custom| +
|
||||||
|
Custom completion
|
||||||
|
|
||||||
|
Custom completion can be provided by specifying the "custom,{func}" argument to
|
||||||
|
-complete. The {func} is called with one argument, the word being completed,
|
||||||
|
and should return an array [start, completions].
|
||||||
|
|
||||||
|
*start* is the index into the word being completed at which the returned values
|
||||||
|
should be applied and *completions* is a two dimensional array of the form:
|
||||||
|
\[[arg1, description1], [arg2, description2], ...]
|
||||||
|
|
||||||
|
// TODO: add examples
|
||||||
|
|
||||||
|E177| |E178| |:command-count| +
|
|E177| |E178| |:command-count| +
|
||||||
Count handling
|
Count handling
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user