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

new :command command, thanks dpb!

This commit is contained in:
Martin Stubenschrott
2008-01-05 12:05:01 +00:00
parent a8e0c3e290
commit d600bbabec
3 changed files with 75 additions and 10 deletions

View File

@@ -10,7 +10,7 @@ Inactive/former developers:
* Viktor Kojouharov (Виктор Кожухаров) * Viktor Kojouharov (Виктор Кожухаров)
Patches (in no special order): Patches (in no special order):
* Daniel Bainton (:viewsource) * Daniel Bainton (:viewsource, :command)
* Muthu Kannan (ctrl-v support) * Muthu Kannan (ctrl-v support)
* Lars Kindler (:buffer(s) functionality) * Lars Kindler (:buffer(s) functionality)
* Lee Hinman (:open ./.. support) * Lee Hinman (:open ./.. support)

1
NEWS
View File

@@ -9,6 +9,7 @@
removed the following hint options: 'hintchars' 'maxhints' removed the following hint options: 'hintchars' 'maxhints'
added the following hint options: 'hinttimeout' added the following hint options: 'hinttimeout'
* IMPORTANT: changed 'I' key to Ctrl-Q to also work in textboxes * IMPORTANT: changed 'I' key to Ctrl-Q to also work in textboxes
* new :command to add user defined commands
* new setCustomMode for plugin writers * new setCustomMode for plugin writers
* :au[tocmd] executes commands on events (only 'PageLoad' actually) on websites * :au[tocmd] executes commands on events (only 'PageLoad' actually) on websites
* @@ to repeat last macro * @@ to repeat last macro

View File

@@ -86,6 +86,7 @@ vimperator.Command = function (specs, action, extraInfo) //{{{
this.shortHelp = extraInfo.shortHelp || null; this.shortHelp = extraInfo.shortHelp || null;
this.completer = extraInfo.completer || null; this.completer = extraInfo.completer || null;
this.args = extraInfo.args || []; this.args = extraInfo.args || [];
this.isUserCommand = extraInfo.isUserCommand || false;
} }
}; };
@@ -443,6 +444,28 @@ vimperator.Commands = function () //{{{
throw StopIteration; throw StopIteration;
} }
function getUserCommands(name)
{
var matches = [];
for (var i = 0; i < exCommands.length; i++)
{
if (exCommands[i].isUserCommand)
{
if (name)
{
if (exCommands[i].name.match("^"+name))
matches.push(exCommands[i]);
}
else
{
matches.push(exCommands[i]);
}
}
}
return matches;
}
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
@@ -454,13 +477,28 @@ vimperator.Commands = function () //{{{
return commandsIterator(); return commandsIterator();
}, },
add: function (command) add: function (command, replace)
{ {
for (var i = 0; i < exCommands.length; i++)
{
if (exCommands[i].name == command.name)
{
if (!replace)
return false;
else
break;
}
}
// add an alias, so that commands can be accessed with
// vimperator.commands.zoom("130")
this[command.name] = function (args, special, count, modifiers) this[command.name] = function (args, special, count, modifiers)
{ {
command.execute(args, special, count, modifiers); command.execute(args, special, count, modifiers);
}; };
exCommands.push(command); exCommands.push(command);
return true;
}, },
get: function (name) get: function (name)
@@ -776,21 +814,47 @@ vimperator.Commands = function () //{{{
} }
)); ));
commandManager.add(new vimperator.Command(["com[mand]"], commandManager.add(new vimperator.Command(["com[mand]"],
function (args) function (args, special)
{ {
var res = parseArgs(args, this.args); if (args)
if (!res) {
return; var res = args.match(/^(\w+)(?:\s+(.+))?$/);
if (!res)
{
vimperator.echoerr("E182: Invalid command name");
return false;
}
var [cmd, rep] = [res[1], res[2]]
}
vimperator.echo(vimperator.util.colorize(res.args)); if (rep)
{
if (!vimperator.commands.add(new vimperator.Command([cmd], function (args, special, count, modifiers) { eval(rep) }, { isUserCommand: rep } ), special))
vimperator.echoerr("E174: Command already exists: add ! to replace it");
}
else
{
var cmdlist = getUserCommands(cmd);
if (cmdlist.length > 0)
{
var str = ":" + vimperator.util.escapeHTML(vimperator.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 += "</table>"
vimperator.commandline.echo(str, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE);
}
else
vimperator.echo("No user-defined commands found");
}
}, },
{ {
usage: ["com[mand][!] [{attr}...] {cmd} {rep}"], usage: ["com[mand][!] [{attr}...] {cmd} {rep}"],
shortHelp: "Temporarily used for testing args parser", shortHelp: "Lists and defines commands",
help: "", help: "To be written - but it works similar to vim's :command" /*,
args: [[["-nargs"], OPTION_STRING, function (arg) { return /^(0|1|\*|\?|\+)$/.test(arg); }], args: [[["-nargs"], OPTION_STRING, function (arg) { return /^(0|1|\*|\?|\+)$/.test(arg); }],
[["-bang"], OPTION_NOARG], [["-bang"], OPTION_NOARG],
[["-bar"], OPTION_NOARG]] [["-bar"], OPTION_NOARG]] */
} }
)); ));
commandManager.add(new vimperator.Command(["delm[arks]"], commandManager.add(new vimperator.Command(["delm[arks]"],