1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 11:48:00 +01:00

change :command to behave like Vim's and add :comclear and :delcommand

This commit is contained in:
Doug Kearns
2008-08-08 06:45:14 +00:00
parent 902d7c4030
commit 03d030db9e
3 changed files with 91 additions and 3 deletions

View File

@@ -646,7 +646,11 @@ liberator.Commands = function () //{{{
{
if (!liberator.commands.addUserCommand([cmd],
"User defined command",
function (args, special, count, modifiers) { eval(rep); },
function (args, special, count, modifiers)
{
var replaced = rep.replace("<args>", args).replace("<lt>", "<");
liberator.execute(replaced);
},
null, special))
{
liberator.echoerr("E174: Command already exists: add ! to replace it");
@@ -660,12 +664,14 @@ liberator.Commands = function () //{{{
var str = ":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "<br/>" +
"<table><tr align=\"left\" class=\"hl-Title\"><th>Name</th><th>Args</th><th>Definition</th></tr>";
for (var i = 0; i < cmdlist.length; i++)
str += "<tr><td>" + cmdlist[i].name + "</td><td>" + "*" + "</td><td>" + cmdlist[i].isUserCommand + "</td></tr>";
str += "<tr><td>" + cmdlist[i].name + "</td><td>" + "*" + "</td><td>" + "...definition not implemented yet" + "</td></tr>";
str += "</table>";
liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE);
}
else
{
liberator.echo("No user-defined commands found");
}
}
},
{
@@ -674,6 +680,41 @@ liberator.Commands = function () //{{{
[["-bar"], OPTION_NOARG]] */
});
commandManager.add(["comc[lear]"],
"Delete all user-defined commands",
function (args)
{
if (args)
{
liberator.echoerr("E488: Trailing characters");
return;
}
var commands = getUserCommands();
for (var i = 0; i < commands.length; i++)
removeUserCommand(commands[i].name);
});
// TODO: complete with user-defined commands
commandManager.add(["delc[ommand]"],
"Delete the specified user-defined command",
function (args)
{
if (!args)
{
liberator.echoerr("E471: Argument required");
return;
}
// TODO: add getUserCommand, removeUserCommands, or similar, and make them 'public'?
var commands = getUserCommands(args);
if (commands.length == 1 && args == commands[0].name)
removeUserCommand(commands[0].name);
else
liberator.echoerr("E184: No such user-defined command: " + args);
});
// TODO: remove preview window, or change it at least
// commandManager.add(["pc[lose]"],
// "Close preview window on bottom of screen",