mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 18:47:58 +01:00
delay user-command custom completer evaluation until call time
This commit is contained in:
@@ -757,14 +757,10 @@ function Commands() //{{{
|
|||||||
|
|
||||||
if (completeOpt)
|
if (completeOpt)
|
||||||
{
|
{
|
||||||
// TODO: Should we catch any eval error? It'll be reported anyway.
|
|
||||||
if (/^custom,/.test(completeOpt))
|
if (/^custom,/.test(completeOpt))
|
||||||
completeFunc = liberator.eval(completeOpt.substr(7));
|
completeFunc = completeOpt.substr(7);
|
||||||
else
|
else
|
||||||
completeFunc = completion[completeOptionMap[completeOpt]];
|
completeFunc = "completion." + completeOptionMap[completeOpt];
|
||||||
|
|
||||||
if (completeFunc == null)
|
|
||||||
return liberator.echoerr("No such completion function");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!commands.addUserCommand(
|
if (!commands.addUserCommand(
|
||||||
@@ -775,9 +771,20 @@ function Commands() //{{{
|
|||||||
argCount: nargsOpt,
|
argCount: nargsOpt,
|
||||||
bang: bangOpt,
|
bang: bangOpt,
|
||||||
count: countOpt,
|
count: countOpt,
|
||||||
// TODO: handle missing function
|
completer: function (context, args) {
|
||||||
//completer: completeFunc,
|
if (completeFunc)
|
||||||
completer: function (context, args) eval(completeFunc(context, args)),
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
liberator.eval(completeFunc).call(completion, context, args)
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
// FIXME: should be pushed to the MOW
|
||||||
|
liberator.echoerr("E117: Unknown function: " + completeFunc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
replacementText: args.literalArg
|
replacementText: args.literalArg
|
||||||
},
|
},
|
||||||
args.bang)
|
args.bang)
|
||||||
|
|||||||
@@ -323,9 +323,9 @@ Completion can be enabled by specifying one of the following arguments to the
|
|||||||
Custom completion
|
Custom completion
|
||||||
|
|
||||||
Custom completion can be provided by specifying the "custom,{func}" argument to
|
Custom completion can be provided by specifying the "custom,{func}" argument to
|
||||||
-complete. The {func} is called with to arguments, a completion context, and
|
-complete. The {func} is called with two arguments, a completion context, and
|
||||||
an an object describing the command's arguments. It should set the context's
|
an an object describing the command's arguments. It should set the context's
|
||||||
'completions' property, or return an object, with 'start' and 'items'
|
\'completions' property, or return an object, with \'start' and \'items'
|
||||||
properties, describing the completions and where the replacement is to start.
|
properties, describing the completions and where the replacement is to start.
|
||||||
|
|
||||||
*start* is the index into the word being completed at which the returned values
|
*start* is the index into the word being completed at which the returned values
|
||||||
|
|||||||
Reference in New Issue
Block a user