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

pass all command actions an args object - IMPORTANT: this will possibly break

your plugin, read the NEWS file
This commit is contained in:
Doug Kearns
2008-10-17 11:39:25 +00:00
parent dba3870773
commit bec8d33e59
15 changed files with 95 additions and 29 deletions

4
NEWS
View File

@@ -1,6 +1,10 @@
<pre> <pre>
2008-XX-XX: 2008-XX-XX:
* version 2.0 (probably) * version 2.0 (probably)
* IMPORTANT: command actions now take an args object, returned from
commands.parseArgs, as their first argument. This will break any commands
not using the args parser explicitly. The old string value is now
available via args.string.
* IMPORTANT: 'verbose' is now used for message levels. Logging is * IMPORTANT: 'verbose' is now used for message levels. Logging is
controlled by the extensions.liberator.loglevel preference. controlled by the extensions.liberator.loglevel preference.
* IMPORTANT: :viusage and :exusage now jump to the help index, use the * IMPORTANT: :viusage and :exusage now jump to the help index, use the

View File

@@ -137,7 +137,7 @@ function Addressbook() //{{{
commands.add(["contacts", "addr[essbook]"], commands.add(["contacts", "addr[essbook]"],
"List or open multiple addresses", "List or open multiple addresses",
function (args, special) { addressbook.list(args, special); }, function (args, special) { addressbook.list(args.string, special); },
{ bang: true }); { bang: true });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}

View File

@@ -299,7 +299,7 @@ function Bookmarks() //{{{
"Delete a bookmark", "Delete a bookmark",
function (args) function (args)
{ {
let url = args || buffer.URL; let url = args.string || buffer.URL;
let deletedCount = bookmarks.remove(url); let deletedCount = bookmarks.remove(url);
liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE); liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE);
@@ -610,6 +610,8 @@ function History() //{{{
"Go back in the browser history", "Go back in the browser history",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
if (special) if (special)
{ {
history.goToStart(); history.goToStart();
@@ -658,6 +660,8 @@ function History() //{{{
"Go forward in the browser history", "Go forward in the browser history",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
if (special) if (special)
{ {
history.goToEnd(); history.goToEnd();
@@ -704,7 +708,7 @@ function History() //{{{
commands.add(["hist[ory]", "hs"], commands.add(["hist[ory]", "hs"],
"Show recently visited URLs", "Show recently visited URLs",
function (args, special) { history.list(args, special); }, function (args, special) { history.list(args.string, special); },
{ {
bang: true, bang: true,
completer: function (filter) completion.history(filter) completer: function (filter) completion.history(filter)
@@ -876,6 +880,8 @@ function QuickMarks() //{{{
"Delete the specified QuickMarks", "Delete the specified QuickMarks",
function (args, special) function (args, special)
{ {
args = args.string;
// TODO: finish arg parsing - we really need a proper way to do this. :) // TODO: finish arg parsing - we really need a proper way to do this. :)
if (!special && !args) if (!special && !args)
{ {
@@ -914,6 +920,8 @@ function QuickMarks() //{{{
"Show all QuickMarks", "Show all QuickMarks",
function (args) function (args)
{ {
args = args.string;
// ignore invalid qmark characters unless there are no valid qmark chars // ignore invalid qmark characters unless there are no valid qmark chars
if (args && !/[a-zA-Z0-9]/.test(args)) if (args && !/[a-zA-Z0-9]/.test(args))
{ {

View File

@@ -770,6 +770,8 @@ function Buffer() //{{{
"Select the author style sheet to apply", "Select the author style sheet to apply",
function (args) function (args)
{ {
args = args.string;
var titles = buffer.alternateStyleSheets.map(function (stylesheet) stylesheet.title); var titles = buffer.alternateStyleSheets.map(function (stylesheet) stylesheet.title);
if (args && titles.indexOf(args) == -1) if (args && titles.indexOf(args) == -1)
@@ -797,6 +799,8 @@ function Buffer() //{{{
"Save current document to disk", "Save current document to disk",
function (args, special) function (args, special)
{ {
args = args.string;
let doc = window.content.document; let doc = window.content.document;
let file = io.getFile(args || ""); let file = io.getFile(args || "");
if (args && file.exists() && !special) if (args && file.exists() && !special)
@@ -930,6 +934,8 @@ function Buffer() //{{{
"Set zoom value of current web page", "Set zoom value of current web page",
function (args, special) function (args, special)
{ {
args = args.string;
var level; var level;
if (!args) if (!args)
@@ -1870,6 +1876,8 @@ function Marks() //{{{
"Delete the specified marks", "Delete the specified marks",
function (args, special) function (args, special)
{ {
args = args.string;
if (!special && !args) if (!special && !args)
{ {
liberator.echoerr("E471: Argument required"); liberator.echoerr("E471: Argument required");
@@ -1935,6 +1943,8 @@ function Marks() //{{{
"Show all location marks of current web page", "Show all location marks of current web page",
function (args) function (args)
{ {
args = args.string;
// ignore invalid mark characters unless there are no valid mark chars // ignore invalid mark characters unless there are no valid mark chars
if (args && !/[a-zA-Z]/.test(args)) if (args && !/[a-zA-Z]/.test(args))
{ {

View File

@@ -94,28 +94,32 @@ Command.prototype = {
special = !!special; special = !!special;
count = (count === undefined) ? -1 : count; count = (count === undefined) ? -1 : count;
modifiers = modifiers || {}; modifiers = modifiers || {};
let self = this; let self = this;
// whenever the user specifies special options or fixed number of arguments function parseArgs(args) commands.parseArgs(args, this.options, this.argCount, false, this.literal);
// we use our args parser instead of passing a string to the callback
if (this.options.length > 0 || this.argCount) if (this.hereDoc)
{
args = commands.parseArgs(args, this.options, this.argCount, false, this.literal);
if (args == null)
return false;
}
else if (this.hereDoc)
{ {
let matches = args.match(/(.*)<<\s*(\S+)$/); let matches = args.match(/(.*)<<\s*(\S+)$/);
if (matches && matches[2]) if (matches && matches[2])
{ {
commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"),
function (args) self.action.call(self, matches[1] + "\n" + args, special, count, modifiers)); function (args)
{
args = parseArgs.call(self, matches[1] + "\n" + args);
if (args)
self.action.call(self, args, special, count, modifiers);
});
return; return;
} }
} }
return this.action.call(this, args, special, count, modifiers); args = parseArgs.call(this, args);
if (args)
this.action.call(this, args, special, count, modifiers);
}, },
// return true if the candidate name matches one of the command's aliases // return true if the candidate name matches one of the command's aliases
@@ -464,7 +468,8 @@ function Commands() //{{{
args.literalArg = ""; args.literalArg = "";
var invalid = false; var invalid = false;
var onlyArgumentsRemaining = allowUnknownOptions || false; // after a -- has been found // FIXME: best way to specify these requirements?
var onlyArgumentsRemaining = allowUnknownOptions || options.length == 0 || false; // after a -- has been found
var arg = null; var arg = null;
var count = 0; // the length of the argument var count = 0; // the length of the argument
var i = 0; var i = 0;

View File

@@ -157,6 +157,8 @@ function Editor() //{{{
"Abbreviate a key sequence" + modeDescription, "Abbreviate a key sequence" + modeDescription,
function (args) function (args)
{ {
args = args.string;
if (!args) if (!args)
{ {
editor.listAbbreviations(mode, ""); editor.listAbbreviations(mode, "");
@@ -173,7 +175,7 @@ function Editor() //{{{
commands.add([ch ? ch + "una[bbrev]" : "una[bbreviate]"], commands.add([ch ? ch + "una[bbrev]" : "una[bbreviate]"],
"Remove an abbreviation" + modeDescription, "Remove an abbreviation" + modeDescription,
function (args) { editor.removeAbbreviation(mode, args); }); function (args) { editor.removeAbbreviation(mode, args.string); });
commands.add([ch + "abc[lear]"], commands.add([ch + "abc[lear]"],
"Remove all abbreviations" + modeDescription, "Remove all abbreviations" + modeDescription,

View File

@@ -122,7 +122,7 @@ function AutoCommands() //{{{
"Apply the autocommands matching the specified URL pattern to all buffers", "Apply the autocommands matching the specified URL pattern to all buffers",
function (args) function (args)
{ {
commands.get("doautocmd").action.call(this, args); commands.get("doautocmd").action.call(this, args.string);
}, },
{ {
argCount: "+", argCount: "+",
@@ -696,6 +696,8 @@ function Events() //{{{
"Delete macros", "Delete macros",
function (args, special) function (args, special)
{ {
args = args.string;
if (special) if (special)
args = ".*"; // XXX args = ".*"; // XXX
@@ -711,7 +713,7 @@ function Events() //{{{
function (args) function (args)
{ {
XML.prettyPrinting = false; XML.prettyPrinting = false;
var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args)); var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args.string));
liberator.echo(str, commandline.FORCE_MULTILINE); liberator.echo(str, commandline.FORCE_MULTILINE);
}, },
{ completer: function (filter) completion.macro(filter) }); { completer: function (filter) completion.macro(filter) });

View File

@@ -139,6 +139,8 @@ function IO() //{{{
"Change the current directory", "Change the current directory",
function (args) function (args)
{ {
args = args.string;
if (!args) if (!args)
{ {
args = "~"; args = "~";
@@ -216,6 +218,8 @@ function IO() //{{{
"Write current key mappings and changed options to the config file", "Write current key mappings and changed options to the config file",
function (args, special) function (args, special)
{ {
args = args.string;
// TODO: "E172: Only one file name allowed" // TODO: "E172: Only one file name allowed"
var filename; var filename;
if (args) if (args)
@@ -344,6 +348,8 @@ function IO() //{{{
"Read Ex commands from a file", "Read Ex commands from a file",
function (args, special) function (args, special)
{ {
args = args.string;
// FIXME: implement proper filename quoting - "E172: Only one file name allowed" // FIXME: implement proper filename quoting - "E172: Only one file name allowed"
if (!args) if (!args)
{ {
@@ -362,6 +368,8 @@ function IO() //{{{
"Run a command", "Run a command",
function (args, special) function (args, special)
{ {
args = args.string;
// :!! needs to be treated specially as the command parser sets the // :!! needs to be treated specially as the command parser sets the
// special flag but removes the ! from args // special flag but removes the ! from args
if (special) if (special)

View File

@@ -261,7 +261,7 @@ const liberator = (function () //{{{
{ {
try try
{ {
var cmd = liberator.eval(args); var cmd = liberator.eval(args.string);
liberator.execute(cmd); liberator.execute(cmd);
} }
catch (e) catch (e)
@@ -301,7 +301,7 @@ const liberator = (function () //{{{
return; return;
} }
liberator.help(args); liberator.help(args.string);
}, },
{ {
bang: true, bang: true,
@@ -322,7 +322,7 @@ const liberator = (function () //{{{
{ {
try try
{ {
liberator.eval(args); liberator.eval(args.string);
} }
catch (e) catch (e)
{ {
@@ -392,6 +392,7 @@ const liberator = (function () //{{{
function (args, special, count) function (args, special, count)
{ {
args = args.string; args = args.string;
let method = args[0] == ":" ? "execute" : "eval"; let method = args[0] == ":" ? "execute" : "eval";
try try

View File

@@ -720,12 +720,12 @@ function Mail() //{{{
commands.add(["copy[to]"], commands.add(["copy[to]"],
"Copy selected messages", "Copy selected messages",
function (args) { moveOrCopy(true, args); }, function (args) { moveOrCopy(true, args.string); },
{ completer: function (filter) getFolderCompletions(filter) }); { completer: function (filter) getFolderCompletions(filter) });
commands.add(["move[to]"], commands.add(["move[to]"],
"Move selected messages", "Move selected messages",
function (args) { moveOrCopy(false, args); }, function (args) { moveOrCopy(false, args.string); },
{ completer: function (filter) getFolderCompletions(filter) }); { completer: function (filter) getFolderCompletions(filter) });
commands.add(["empty[trash]"], commands.add(["empty[trash]"],

View File

@@ -234,6 +234,8 @@ function Mappings() //{{{
"Remove a mapping" + modeDescription, "Remove a mapping" + modeDescription,
function (args) function (args)
{ {
args = args.string;
if (!args) if (!args)
{ {
liberator.echoerr("E474: Invalid argument"); liberator.echoerr("E474: Invalid argument");

View File

@@ -279,6 +279,8 @@ function Options() //{{{
"Set or list a variable", "Set or list a variable",
function (args) function (args)
{ {
args = args.string;
if (!args) if (!args)
{ {
var str = var str =
@@ -387,7 +389,7 @@ function Options() //{{{
"Set local option", "Set local option",
function (args, special, count) function (args, special, count)
{ {
commands.get("set").execute(args, special, count, { scope: options.OPTION_SCOPE_LOCAL }); commands.get("set").execute(args.string, special, count, { scope: options.OPTION_SCOPE_LOCAL });
}, },
{ {
bang: true, bang: true,
@@ -403,7 +405,7 @@ function Options() //{{{
"Set global option", "Set global option",
function (args, special, count) function (args, special, count)
{ {
commands.get("set").execute(args, special, count, { scope: options.OPTION_SCOPE_GLOBAL }); commands.get("set").execute(args.string, special, count, { scope: options.OPTION_SCOPE_GLOBAL });
}, },
{ {
bang: true, bang: true,
@@ -474,6 +476,8 @@ function Options() //{{{
"Set an option", "Set an option",
function (args, special, count, modifiers) function (args, special, count, modifiers)
{ {
args = args.string;
if (special) if (special)
{ {
var onlyNonDefault = false; var onlyNonDefault = false;

View File

@@ -307,6 +307,8 @@ function Tabs() //{{{
"Delete current buffer", "Delete current buffer",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
if (args) if (args)
{ {
args = args.toLowerCase(); args = args.toLowerCase();
@@ -373,6 +375,8 @@ function Tabs() //{{{
"Switch to the previous tab or go [count] tabs back", "Switch to the previous tab or go [count] tabs back",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
// count is ignored if an arg is specified, as per Vim // count is ignored if an arg is specified, as per Vim
if (args) if (args)
{ {
@@ -397,6 +401,8 @@ function Tabs() //{{{
"Switch to the next or [count]th tab", "Switch to the next or [count]th tab",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
if (args || count > 0) if (args || count > 0)
{ {
var index; var index;
@@ -443,6 +449,8 @@ function Tabs() //{{{
"Switch to a buffer", "Switch to a buffer",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
// if a numeric arg is specified any count is ignored; if a // if a numeric arg is specified any count is ignored; if a
// count and non-numeric arg are both specified then E488 // count and non-numeric arg are both specified then E488
if (args && count > 0) if (args && count > 0)
@@ -493,6 +501,8 @@ function Tabs() //{{{
"Move the current tab after tab N", "Move the current tab after tab N",
function (args, special) function (args, special)
{ {
args = args.string;
// FIXME: tabmove! N should probably produce an error // FIXME: tabmove! N should probably produce an error
if (!/^([+-]?\d+|)$/.test(args)) if (!/^([+-]?\d+|)$/.test(args))
{ {
@@ -516,6 +526,8 @@ function Tabs() //{{{
"Open one or more URLs in a new tab", "Open one or more URLs in a new tab",
function (args, special) function (args, special)
{ {
args = args.string;
var where = special ? liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB; var where = special ? liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB;
if (/\btabopen\b/.test(options["activate"])) if (/\btabopen\b/.test(options["activate"]))
where = special ? liberator.NEW_BACKGROUND_TAB : liberator.NEW_TAB; where = special ? liberator.NEW_BACKGROUND_TAB : liberator.NEW_TAB;
@@ -565,6 +577,8 @@ function Tabs() //{{{
"Undo closing of a tab", "Undo closing of a tab",
function (args, special, count) function (args, special, count)
{ {
args = args.string;
if (count < 1) if (count < 1)
count = 1; count = 1;

View File

@@ -493,7 +493,7 @@ function CommandLine() //{{{
command.description, command.description,
function (args) function (args)
{ {
var str = echoArgumentToString(args, true); var str = echoArgumentToString(args.string, true);
if (str != null) if (str != null)
command.action(str); command.action(str);
}, },

View File

@@ -276,6 +276,8 @@ const config = { //{{{
"Open one or more URLs in the current tab", "Open one or more URLs in the current tab",
function (args, special) function (args, special)
{ {
args = args.string;
if (args) if (args)
{ {
liberator.open(args); liberator.open(args);
@@ -318,8 +320,10 @@ const config = { //{{{
"Open the sidebar window", "Open the sidebar window",
function (args) function (args)
{ {
args = args.string;
// do nothing if the requested sidebar is already open // do nothing if the requested sidebar is already open
if (document.getElementById("sidebar-title").value == args.string) if (document.getElementById("sidebar-title").value == args)
{ {
document.getElementById("sidebar-box").contentWindow.focus(); document.getElementById("sidebar-box").contentWindow.focus();
return; return;
@@ -328,13 +332,13 @@ const config = { //{{{
var menu = document.getElementById("viewSidebarMenu"); var menu = document.getElementById("viewSidebarMenu");
for (let i = 0; i < menu.childNodes.length; i++) for (let i = 0; i < menu.childNodes.length; i++)
{ {
if (menu.childNodes[i].label == args.string) if (menu.childNodes[i].label == args)
{ {
menu.childNodes[i].doCommand(); menu.childNodes[i].doCommand();
return; return;
} }
} }
liberator.echoerr("No sidebar " + args.string + " found"); liberator.echoerr("No sidebar " + args + " found");
}, },
{ {
argCount: "+", argCount: "+",
@@ -350,6 +354,8 @@ const config = { //{{{
"Open one or more URLs in a new window", "Open one or more URLs in a new window",
function (args) function (args)
{ {
args = args.string;
if (args) if (args)
liberator.open(args, liberator.NEW_WINDOW); liberator.open(args, liberator.NEW_WINDOW);
else else