diff --git a/common/content/commands.js b/common/content/commands.js index 0db3d315..af46822d 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -757,16 +757,14 @@ function Commands() //{{{ if (completeOpt) { - let func; - + // TODO: Should we catch any eval error? It'll be reported anyway. if (/^custom,/.test(completeOpt)) - func = completeOpt.replace("custom,", ""); - else - func = "completion." + completeOptionMap[completeOpt]; + completeFunc = liberator.eval(completeOpt.substr(7)); + else + completeFunc = completion[completeOptionMap[completeOpt]]; - //completeFunc = eval(func); - completeFunc = func; - liberator.log(func) + if (completeFunc == null) + return liberator.echoerr("No such completion function"); } if (!commands.addUserCommand( @@ -779,7 +777,7 @@ function Commands() //{{{ count: countOpt, // TODO: handle missing function //completer: completeFunc, - completer: function (context, args) eval(completeFunc + "(context, args)"), + completer: function (context, args) eval(completeFunc(context, args)), replacementText: args.literalArg }, args.bang) diff --git a/vimperator/locale/en-US/map.txt b/vimperator/locale/en-US/map.txt index ffc52cd1..30d04563 100644 --- a/vimperator/locale/en-US/map.txt +++ b/vimperator/locale/en-US/map.txt @@ -323,8 +323,10 @@ Completion can be enabled by specifying one of the following arguments to the 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]. +-complete. The {func} is called with to arguments, a completion context, and +an an object describing the command's arguments. It should set the context's +'completions' property, or return an object, with 'start' and 'items' +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 should be applied and *completions* is a two dimensional array of the form: