1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-22 06:47:58 +01:00

minor refactoring of :command action

This commit is contained in:
Doug Kearns
2008-12-19 23:50:12 +11:00
committed by Kris Maglione
parent d277dd5c1c
commit 39d6542e80

View File

@@ -759,19 +759,20 @@ function Commands() //{{{
{ {
if (/^custom,/.test(completeOpt)) if (/^custom,/.test(completeOpt))
{ {
completeOpt = completeOpt.substr(7);
completeFunc = function () completeFunc = function ()
{ {
try try
{ {
var completer = liberator.eval(completeOpt.substr(7)); var completer = liberator.eval(completeOpt);
if (!(completer instanceof Function)) if (!(completer instanceof Function))
throw new TypeError("User-defined custom completer '" + completeOpt.substr(7) + "' is not a function"); throw new TypeError("User-defined custom completer '" + completeOpt + "' is not a function");
} }
catch (e) catch (e)
{ {
// FIXME: should be pushed to the MOW // FIXME: should be pushed to the MOW
liberator.echoerr("E117: Unknown function: " + completeOpt.substr(7)); liberator.echoerr("E117: Unknown function: " + completeOpt);
liberator.log(e); liberator.log(e);
return undefined; return undefined;
} }
@@ -784,26 +785,23 @@ function Commands() //{{{
} }
} }
if (!commands.addUserCommand( let added = commands.addUserCommand([cmd],
[cmd], "User defined command",
"User defined command", userCommand,
userCommand, {
{ argCount: nargsOpt,
argCount: nargsOpt, bang: bangOpt,
bang: bangOpt, count: countOpt,
count: countOpt, completer: function (context, args)
completer: function (context, args) {
{ if (completeFunc)
if (completeFunc) return completeFunc(context, args)
return completeFunc(context, args) },
}, replacementText: args.literalArg
replacementText: args.literalArg }, args.bang);
},
args.bang) if (!added)
)
{
liberator.echoerr("E174: Command already exists: add ! to replace it"); liberator.echoerr("E174: Command already exists: add ! to replace it");
}
} }
else else
{ {