1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 17:42:27 +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

6
NEWS
View File

@@ -1,6 +1,11 @@
<pre>
2008-06-xx:
* version 1.2
* IMPORTANT: changed :command to behave like Vim's version.
Eg. An alert command specified previously as
:command AlertMe alert(args)
should now be defined as
:command AlertMe :js alert(<args>)
* IMPORTANT: changed the default keybinding to temporarily disable all
Vimperator keybindings from <C-Q> to <C-Z>
* IMPORTANT: removed old :buffers! buffer window, as it was ugly and slightly broken
@@ -10,6 +15,7 @@
generous donation which made this behavior possible)
* IMPORTANT: ctrl-x/a never take possible negative URLs into account, it was just
too unpredictable
* add :comclear and :delcommand
* add a special version to :hardcopy to skip the Print dialog
* add :bl[ast], :bf[irst], :br[ewind] to go to first/last tab
* add :bn[ext], :bp[revious], :bN[ext] to switch to next/previous tab

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",

View File

@@ -200,9 +200,50 @@ ________________________________________________________________________________
section:User-defined{nbsp}commands[user-commands]
|:com| |:command|
||:com[mand]|| +
________________________________________________________________________________
List all user-defined commands.
________________________________________________________________________________
||:com[mand] {cmd}|| +
________________________________________________________________________________
List all user-defined commands that start with {cmd}.
________________________________________________________________________________
||:com[mand][!] [{attr}...] {cmd} {rep}|| +
________________________________________________________________________________
Lists and defines commands. To be written - but it works similar to Vim's :command
Define a new user command. The name of the command is {cmd} and its relacement
text is {rep}. The command's attributes are {attr}. If a command with this
name already exists an error is reported unless [!] is specified, in which case
the command is redefined. Unlike Vim, the command may start with a lowercase
letter.
The replacement text {rep} is scanned for escape sequences and these are
replaced with values from the user entered command line. The resulting string
is then executed as an Ex command.
The valid escape sequences are:
`------`------------------------------------------------------------------------
<args> The command arguments exactly as supplied
<lt> A literal '<' character to allow for a literal copy of one of the escape sequences. Eg. <lt>args> will expand to a literal <args>
--------------------------------------------------------------------------------
Note: {attr} not implemented yet.
________________________________________________________________________________
|:comc| |:comclear|
||:comc[lear]|| +
________________________________________________________________________________
Delete all user-defined commands.
________________________________________________________________________________
|:delc| |:delcommand|
||:delc[ommand] {cmd}|| +
________________________________________________________________________________
Delete the user-defined command {cmd}.
________________________________________________________________________________
// vim: set syntax=asciidoc: