diff --git a/content/addressbook.js b/content/addressbook.js index 7ebd94fb..f275f362 100644 --- a/content/addressbook.js +++ b/content/addressbook.js @@ -137,7 +137,7 @@ function Addressbook() //{{{ commands.add(["contacts", "addr[essbook]"], "List or open multiple addresses", - function (args, special) { addressbook.list(args.string, special); }, + function (args) { addressbook.list(args.string, args.bang); }, { bang: true }); /////////////////////////////////////////////////////////////////////////////}}} diff --git a/content/bookmarks.js b/content/bookmarks.js index 8d993a51..4fbfcb4d 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -289,14 +289,14 @@ function Bookmarks() //{{{ commands.add(["bma[rk]"], "Add a bookmark", - function (args, special) + function (args) { var url = args.length == 0 ? buffer.URL : args[0]; var title = args["-title"] || (args.length == 0 ? buffer.title : null); var keyword = args["-keyword"] || null; var tags = args["-tags"] || []; - if (bookmarks.add(false, title, url, keyword, tags, special)) + if (bookmarks.add(false, title, url, keyword, tags, args.bang)) { let extra = (title == url) ? "" : " (" + title + ")"; liberator.echo("Added bookmark: " + url + extra, commandline.FORCE_SINGLELINE); @@ -314,9 +314,9 @@ function Bookmarks() //{{{ commands.add(["bmarks"], "List or open multiple bookmarks", - function (args, special) + function (args) { - bookmarks.list(args.join(" "), args["-tags"] || [], special); + bookmarks.list(args.join(" "), args["-tags"] || [], args.bang); }, { bang: true, @@ -616,11 +616,11 @@ function History() //{{{ commands.add(["ba[ck]"], "Go back in the browser history", - function (args, special, count) + function (args) { args = args.string; - if (special) + if (args.bang) { history.goToStart(); } @@ -641,7 +641,7 @@ function History() //{{{ } else { - history.stepTo(count > 0 ? -1 * count : -1); + history.stepTo(args.count > 0 ? -1 * args.count : -1); } } }, @@ -668,11 +668,11 @@ function History() //{{{ commands.add(["fo[rward]", "fw"], "Go forward in the browser history", - function (args, special, count) + function (args) { args = args.string; - if (special) + if (args.bang) { history.goToEnd(); } @@ -693,7 +693,7 @@ function History() //{{{ } else { - history.stepTo(count > 0 ? count : 1); + history.stepTo(args.count > 0 ? args.count : 1); } } }, @@ -720,7 +720,7 @@ function History() //{{{ commands.add(["hist[ory]", "hs"], "Show recently visited URLs", - function (args, special) { history.list(args.string, special); }, + function (args) { history.list(args.string, args.bang); }, { bang: true, // completer: function (filter) completion.history(filter) @@ -861,24 +861,22 @@ function QuickMarks() //{{{ commands.add(["delqm[arks]"], "Delete the specified QuickMarks", - function (args, special) + function (args) { - args = args.string; - // TODO: finish arg parsing - we really need a proper way to do this. :) - if (!special && !args) + if (!args.bang && !args.string) { liberator.echoerr("E471: Argument required"); return; } - if (special && args) + if (args.bang && args.string) { liberator.echoerr("E474: Invalid argument"); return; } - if (special) + if (args.bang) quickmarks.removeAll(); else quickmarks.remove(args); diff --git a/content/buffer.js b/content/buffer.js index ce9ed8f7..4956bcd9 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -468,14 +468,14 @@ function Buffer() //{{{ commands.add(["ha[rdcopy]"], "Print current document", - function (args, special) + function (args) { var aps = options.getPref("print.always_print_silent"); var spp = options.getPref("print.show_print_progress"); liberator.echo("Sending to printer..."); - options.setPref("print.always_print_silent", special); - options.setPref("print.show_print_progress", !special); + options.setPref("print.always_print_silent", args.bang); + options.setPref("print.show_print_progress", !args.bang); getBrowser().contentWindow.print(); @@ -519,7 +519,7 @@ function Buffer() //{{{ commands.add(["re[load]"], "Reload current page", - function (args, special) { tabs.reload(getBrowser().mCurrentTab, special); }, + function (args) { tabs.reload(getBrowser().mCurrentTab, args.bang); }, { bang: true, argCount: "0" @@ -528,7 +528,7 @@ function Buffer() //{{{ // TODO: we're prompted if download.useDownloadDir isn't set and no arg specified - intentional? commands.add(["sav[eas]", "w[rite]"], "Save current document to disk", - function (args, special) + function (args) { let doc = window.content.document; let chosenData = null; @@ -538,7 +538,7 @@ function Buffer() //{{{ { let file = io.getFile(filename); - if (file.exists() && !special) + if (file.exists() && !args.bang) { liberator.echoerr("E13: File exists (add ! to override)"); return; @@ -577,7 +577,7 @@ function Buffer() //{{{ commands.add(["vie[wsource]"], "View source code of current document", - function (args, special) { buffer.viewSource(args[0], special); }, + function (args) { buffer.viewSource(args[0], args.bang); }, { argCount: "?", bang: true, @@ -586,26 +586,24 @@ function Buffer() //{{{ commands.add(["zo[om]"], "Set zoom value of current web page", - function (args, special) + function (args) { - args = args.string; - let level; - if (!args) + if (!args.string) { level = 100; } - else if (/^\d+$/.test(args)) + else if (/^\d+$/.test(args.string)) { - level = parseInt(args, 10); + level = parseInt(args.string, 10); } - else if (/^[+-]\d+$/.test(args)) + else if (/^[+-]\d+$/.test(args.string)) { - if (special) - level = buffer.fullZoom + parseInt(args, 10); + if (args.bang) + level = buffer.fullZoom + parseInt(args.string, 10); else - level = buffer.textZoom + parseInt(args, 10); + level = buffer.textZoom + parseInt(args.string, 10); // relative args shouldn't take us out of range if (level < ZOOM_MIN) @@ -619,7 +617,7 @@ function Buffer() //{{{ return; } - if (special) + if (args.bang) buffer.fullZoom = level; else buffer.textZoom = level; @@ -1474,9 +1472,10 @@ function Marks() //{{{ commands.add(["delm[arks]"], "Delete the specified marks", - function (args, special) + function (args) { - args = args.string; + let special = args.bang; + let args = args.string; if (!special && !args) { diff --git a/content/commands.js b/content/commands.js index 8028db1a..4eee17a1 100644 --- a/content/commands.js +++ b/content/commands.js @@ -95,14 +95,24 @@ function Command(specs, description, action, extraInfo) //{{{ Command.prototype = { - execute: function (args, special, count, modifiers) + execute: function (args, bang, count, modifiers) { // XXX - special = !!special; + bang = !!bang; count = (count === undefined) ? -1 : count; modifiers = modifiers || {}; let self = this; + function exec(args) + { + // FIXME: Move to parseCommand? + args = self.parseArgs(args); + if (!args) + return; + args.count = count; + args.bang = bang; + self.action.call(self, args, bang, count, modifiers); + } if (this.hereDoc) { @@ -110,19 +120,12 @@ Command.prototype = { if (matches && matches[2]) { commandline.inputMultiline(new RegExp("^" + matches[2] + "$", "m"), - function (args) - { - args = self.parseArgs(matches[1] + "\n" + args); - if (args) - self.action.call(self, args, special, count, modifiers); - }); + function (args) { exec(matches[1] + "\n" + args) }); return; } } - args = this.parseArgs(args); - if (args) - this.action.call(this, args, special, count, modifiers); + exec(args); }, // return true if the candidate name matches one of the command's aliases @@ -745,12 +748,12 @@ function Commands() //{{{ ////////////////////// COMMANDS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - function userCommand(args, special, count, modifiers) + function userCommand(args, modifiers) { let tokens = { args: this.argCount && args.string, - bang: this.bang && special ? "!" : "", - count: this.count && count + bang: this.bang && args.bang ? "!" : "", + count: this.count && args.count }; liberator.execute(commands.replaceTokens(this.replacementText, tokens)); @@ -773,7 +776,7 @@ function Commands() //{{{ // specified - useful? commandManager.add(["com[mand]"], "List and define commands", - function (args, special) + function (args) { let cmd = args[0]; @@ -815,7 +818,7 @@ function Commands() //{{{ completer: completeFunc, replacementText: args.literalArg }, - special) + args.bang) ) { liberator.echoerr("E174: Command already exists: add ! to replace it"); diff --git a/content/completion.js b/content/completion.js index be7fbac1..82bea015 100644 --- a/content/completion.js +++ b/content/completion.js @@ -1181,7 +1181,7 @@ function Completion() //{{{ // if there is no space between the command name and the cursor // then get completions of the command name - let [count, cmd, special, args] = commands.parseCommand(context.filter); + let [count, cmd, bang, args] = commands.parseCommand(context.filter); let [, prefix, junk] = context.filter.match(/^(:*\d*)\w*(.?)/) || []; context.advance(prefix.length) if (!junk) @@ -1202,12 +1202,15 @@ function Completion() //{{{ args = command.parseArgs(cmdContext.filter, argContext); if (args) { + // FIXME: Move to parseCommand + args.count = count; + args.bang = bang; if (!args.completeOpt && command.completer) { cmdContext.advance(args.completeStart); cmdContext.quote = args.quote; cmdContext.filter = args.completeFilter; - compObject = command.completer.call(command, cmdContext, args, special, count); + compObject = command.completer.call(command, cmdContext, args); if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects compObject = { start: compObject[0], items: compObject[1] }; if (compObject != null) diff --git a/content/events.js b/content/events.js index 8186db93..6f20c60d 100644 --- a/content/events.js +++ b/content/events.js @@ -70,7 +70,7 @@ function AutoCommands() //{{{ commands.add(["au[tocmd]"], "Execute commands automatically on events", - function (args, special) + function (args) { let [event, regex, cmd] = args; let events = null; @@ -90,7 +90,7 @@ function AutoCommands() //{{{ if (cmd) // add new command, possibly removing all others with the same event/pattern { - if (special) + if (args.bang) autocommands.remove(event, regex); autocommands.add(events, regex, cmd); } @@ -98,7 +98,7 @@ function AutoCommands() //{{{ { if (event == "*") event = null; - if (special) + if (args.bang) { // TODO: "*" only appears to work in Vim when there is a {group} specified if (args[0] != "*" || regex) @@ -708,14 +708,12 @@ function Events() //{{{ commands.add(["delmac[ros]"], "Delete macros", - function (args, special) + function (args) { - args = args.string; + if (args.bang) + args.string = ".*"; // XXX - if (special) - args = ".*"; // XXX - - events.deleteMacros(args); + events.deleteMacros(args.string); }, { bang: true, diff --git a/content/io.js b/content/io.js index 22304c73..a166c178 100644 --- a/content/io.js +++ b/content/io.js @@ -241,13 +241,13 @@ function IO() //{{{ // "mkv[imperatorrc]" or "mkm[uttatorrc]" commands.add([EXTENSION_NAME.replace(/(.)(.*)/, "mk$1[$2rc]")], "Write current key mappings and changed options to the config file", - function (args, special) + function (args) { // TODO: "E172: Only one file name allowed" let filename = args[0] || "~/" + (WINDOWS ? "_" : ".") + EXTENSION_NAME + "rc"; let file = io.getFile(filename); - if (file.exists() && !special) + if (file.exists() && !args.bang) { liberator.echoerr("E189: \"" + filename + "\" exists (add ! to override)"); return; @@ -288,7 +288,7 @@ function IO() //{{{ commands.add(["runt[ime]"], "Source the specified file from each directory in 'runtimepath'", - function (args, special) { io.sourceFromRuntimePath(args, special); }, + function (args) { io.sourceFromRuntimePath(args, args.bang); }, { argCount: "+", bang: true @@ -308,10 +308,10 @@ function IO() //{{{ commands.add(["so[urce]"], "Read Ex commands from a file", - function (args, special) + function (args) { // FIXME: "E172: Only one file name allowed" - io.source(args[0], special); + io.source(args[0], args.bang); }, { argCount: "1", @@ -321,8 +321,9 @@ function IO() //{{{ commands.add(["!", "run"], "Run a command", - function (args, special) + function (args) { + let special = args.bang; args = args.string; // :!! needs to be treated specially as the command parser sets the diff --git a/content/liberator.js b/content/liberator.js index 6871b14d..9b15db4d 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -288,7 +288,7 @@ const liberator = (function () //{{{ commands.add(["exu[sage]"], "List all Ex commands with a short description", - function (args, special) { showHelpIndex("ex-cmd-index", commands, special); }, + function (args) { showHelpIndex("ex-cmd-index", commands, args.bang); }, { argCount: "0", bang: true @@ -296,9 +296,9 @@ const liberator = (function () //{{{ commands.add(["h[elp]"], "Display help", - function (args, special) + function (args) { - if (special) + if (args.bang) { liberator.echoerr("E478: Don't panic!"); return; @@ -314,9 +314,9 @@ const liberator = (function () //{{{ commands.add(["javas[cript]", "js"], "Run a JavaScript command through eval()", - function (args, special) + function (args) { - if (special) // open javascript console + if (args.bang) // open javascript console { liberator.open("chrome://global/content/console.xul", (options["newtab"] && options.get("newtab").has("all", "javascript")) @@ -347,7 +347,7 @@ const liberator = (function () //{{{ commands.add(["norm[al]"], "Execute Normal mode commands", - function (args, special) { events.feedkeys(args.string, special); }, + function (args) { events.feedkeys(args.string, args.bang); }, { argCount: "+", bang: true @@ -355,7 +355,7 @@ const liberator = (function () //{{{ commands.add(["optionu[sage]"], "List all options with a short description", - function (args, special) { showHelpIndex("option-index", options, special); }, + function (args) { showHelpIndex("option-index", options, args.bang); }, { argCount: "0", bang: true @@ -363,12 +363,12 @@ const liberator = (function () //{{{ commands.add(["q[uit]"], liberator.has("tabs") ? "Quit current tab" : "Quit application", - function (args, special) + function (args) { if (liberator.has("tabs")) tabs.remove(getBrowser().mCurrentTab, 1, false, 1); else - liberator.quit(false, special); + liberator.quit(false, args.bang); }, { argCount: "0", @@ -382,8 +382,10 @@ const liberator = (function () //{{{ commands.add(["time"], "Profile a piece of code or run a command multiple times", - function (args, special, count) + function (args) { + let count = args.count; + let special = args.bang; args = args.string; if (args[0] == ":") @@ -477,9 +479,9 @@ const liberator = (function () //{{{ commands.add(["ve[rsion]"], "Show version information", - function (args, special) + function (args) { - if (special) + if (args.bang) liberator.open("about:"); else liberator.echo(":" + util.escapeHTML(commandline.getCommand()) + "\n" + @@ -493,7 +495,7 @@ const liberator = (function () //{{{ commands.add(["viu[sage]"], "List all mappings with a short description", - function (args, special) { showHelpIndex("normal-index", mappings, special); }, + function (args) { showHelpIndex("normal-index", mappings, args.bang); }, { argCount: "0", bang: true diff --git a/content/mail.js b/content/mail.js index 7a71a6a4..34167960 100644 --- a/content/mail.js +++ b/content/mail.js @@ -662,8 +662,9 @@ function Mail() //{{{ commands.add(["go[to]"], "Select a folder", - function (args, special, count) + function (args) { + let count = args.count; args = args.string || "Inbox"; count = count > 0 ? (count - 1) : 0; @@ -732,7 +733,7 @@ function Mail() //{{{ commands.add(["get[messages]"], "Check for new messages", - function (args, special) mail.getNewMessages(!special), + function (args) mail.getNewMessages(!args.bang), { argCount: "0", bang: true, diff --git a/content/options.js b/content/options.js index 3f5302cb..d0953413 100644 --- a/content/options.js +++ b/content/options.js @@ -495,9 +495,9 @@ function Options() //{{{ commands.add(["pref[erences]", "prefs"], "Show " + config.hostApplication + " preferences", - function (args, special) + function (args) { - if (special) // open Firefox settings GUI dialog + if (args.bang) // open Firefox settings GUI dialog { liberator.open("about:config", (options["newtab"] && options.get("newtab").has("all", "prefs")) @@ -515,16 +515,16 @@ function Options() //{{{ commands.add(["setl[ocal]"], "Set local option", - function (args, special, count) + function (args) { - commands.get("set").execute(args.string, special, count, { scope: options.OPTION_SCOPE_LOCAL }); + commands.get("set").execute(args.string, args.bang, args.count, { scope: options.OPTION_SCOPE_LOCAL }); }, { bang: true, count: true, - completer: function (context, args, special, count) + completer: function (context, args) { - return commands.get("set").completer(context.filter, special, count, { scope: options.OPTION_SCOPE_LOCAL }); + return commands.get("set").completer(context.filter, args.bang, args.count, { scope: options.OPTION_SCOPE_LOCAL }); }, literal: true } @@ -532,16 +532,16 @@ function Options() //{{{ commands.add(["setg[lobal]"], "Set global option", - function (args, special, count) + function (args) { - commands.get("set").execute(args.string, special, count, { scope: options.OPTION_SCOPE_GLOBAL }); + commands.get("set").execute(args.string, args.bang, args.count, { scope: options.OPTION_SCOPE_GLOBAL }); }, { bang: true, count: true, - completer: function (context, args, special, count) + completer: function (context, args) { - return commands.get("set").completer(context.filter, special, count, { scope: options.OPTION_SCOPE_GLOBAL }); + return commands.get("set").completer(context.filter, args.bang, args.count, { scope: options.OPTION_SCOPE_GLOBAL }); }, literal: true } @@ -550,11 +550,11 @@ function Options() //{{{ // TODO: support setting multiple options at once commands.add(["se[t]"], "Set an option", - function (args, special, count, modifiers) + function (args, modifiers) { + let bang = args.bang; args = args.string; - - if (special) + if (bang) { var onlyNonDefault = false; if (!args) @@ -665,12 +665,12 @@ function Options() //{{{ }, { bang: true, - completer: function (context, args, special, count, modifiers) + completer: function (context, args) { let filter = context.filter; var optionCompletions = []; - if (special) // list completions for about:config entries + if (args.bang) // list completions for about:config entries { if (filter[filter.length - 1] == "=") { @@ -779,20 +779,20 @@ function Options() //{{{ commands.add(["unl[et]"], "Delete a variable", - function (args, special) + function (args) { //var names = args.split(/ /); //if (typeof names == "string") names = [names]; //var length = names.length; //for (let i = 0, name = names[i]; i < length; name = names[++i]) - for (let i = 0; i < args.length; i++) + for (let [,name] in Iterator(args)) { var name = args[i]; var reference = liberator.variableReference(name); if (!reference[0]) { - if (!special) + if (!args.bang) liberator.echoerr("E108: No such variable: " + name); return; } diff --git a/content/style.js b/content/style.js index 5c6c5bb1..65a87e30 100644 --- a/content/style.js +++ b/content/style.js @@ -399,7 +399,7 @@ liberator.registerObserver("load_commands", function () commands.add(["sty[le]"], "Add or list user styles", - function (args, special) + function (args) { let [filter, css] = args; let name = args["-name"]; @@ -426,7 +426,7 @@ liberator.registerObserver("load_commands", function () css = sheet.css.replace(/;?\s*$/, "; " + css); } } - let err = styles.addSheet(name, filter, css, false, special); + let err = styles.addSheet(name, filter, css, false, args.bang); if (err) liberator.echoerr(err); } @@ -434,7 +434,7 @@ liberator.registerObserver("load_commands", function () { argCount: 2, bang: true, - completer: function (context, args, bang) { + completer: function (context, args) { let compl = []; if (args.completeArg == 0) { @@ -483,7 +483,7 @@ liberator.registerObserver("load_commands", function () commands.add(["hi[ghlight]"], "Set the style of certain display elements", - function (args, special) + function (args) { let style = ; let [key, css] = args; - if (!css && !(key && special)) + if (!css && !(key && args.bang)) { let str = template.tabular(["Key", "Sample", "CSS"], ["padding: 0 1em 0 0; vertical-align: top", "text-align: center"], @@ -507,7 +507,7 @@ liberator.registerObserver("load_commands", function () commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); return; } - let error = highlight.set(key, css, special, "-append" in args); + let error = highlight.set(key, css, args.bang, "-append" in args); if (error) liberator.echoerr(error); }, diff --git a/content/tabs.js b/content/tabs.js index c77fce08..5f770f2a 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -310,8 +310,9 @@ function Tabs() //{{{ commands.add(["bd[elete]", "bw[ipeout]", "bun[load]", "tabc[lose]"], "Delete current buffer", - function (args, special, count) + function (args) { + let special = args.bang; args = args.string; if (args) @@ -381,8 +382,9 @@ function Tabs() //{{{ // TODO: "Zero count" if 0 specified as arg commands.add(["tabp[revious]", "tp[revious]", "tabN[ext]", "tN[ext]", "bp[revious]", "bN[ext]"], "Switch to the previous tab or go [count] tabs back", - function (args, special, count) + function (args) { + let count = args.count; args = args.string; // count is ignored if an arg is specified, as per Vim @@ -407,8 +409,9 @@ function Tabs() //{{{ // TODO: "Zero count" if 0 specified as arg commands.add(["tabn[ext]", "tn[ext]", "bn[ext]"], "Switch to the next or [count]th tab", - function (args, special, count) + function (args) { + let count = args.count; args = args.string; if (args || count > 0) @@ -455,8 +458,10 @@ function Tabs() //{{{ // TODO: "Zero count" if 0 specified as arg, multiple args and count ranges? commands.add(["b[uffer]"], "Switch to a buffer", - function (args, special, count) + function (args) { + let count = args.count; + let special = args.special; args = args.string; // if a numeric arg is specified any count is ignored; if a @@ -494,7 +499,7 @@ function Tabs() //{{{ commands.add(["quita[ll]", "qa[ll]"], "Quit " + config.name, - function (args, special) { liberator.quit(false, special); }, + function (args) { liberator.quit(false, args.bang); }, { argCount: "0", bang: true @@ -502,7 +507,7 @@ function Tabs() //{{{ commands.add(["reloada[ll]"], "Reload all tab pages", - function (args, special) { tabs.reloadAll(special); }, + function (args) { tabs.reloadAll(args.bang); }, { argCount: "0", bang: true @@ -511,8 +516,9 @@ function Tabs() //{{{ // TODO: add count support commands.add(["tabm[ove]"], "Move the current tab after tab N", - function (args, special) + function (args) { + let special = args.bang; args = args.string; // FIXME: tabmove! N should probably produce an error @@ -536,8 +542,9 @@ function Tabs() //{{{ commands.add(["tabopen", "t[open]", "tabnew", "tabe[dit]"], "Open one or more URLs in a new tab", - function (args, special) + function (args) { + let special = args.bang; args = args.string; var where = special ? liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB; @@ -562,18 +569,15 @@ function Tabs() //{{{ commands.add(["tabd[uplicate]"], "Duplicate current tab", - function (args, special, count) + function (args) { var tab = tabs.getTab(); - var activate = special ? true : false; + var activate = args.bang ? true : false; if (/\btabopen\b/.test(options["activate"])) activate = !activate; - if (count < 1) - count = 1; - - for (let i = 0; i < count; i++) + for (let i in range(0, Math.max(1, args.count))) tabs.cloneTab(tab, activate); }, { @@ -588,8 +592,9 @@ function Tabs() //{{{ // TODO: extract common functionality of "undoall" commands.add(["u[ndo]"], "Undo closing of a tab", - function (args, special, count) + function (args) { + let count = args.count; args = args.string; if (count < 1) diff --git a/content/vimperator.js b/content/vimperator.js index 59a5e465..8cf4aadd 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -275,15 +275,13 @@ const config = { //{{{ commands.add(["o[pen]", "e[dit]"], "Open one or more URLs in the current tab", - function (args, special) + function (args) { - args = args.string; - - if (args) + if (args.string) { - liberator.open(args); + liberator.open(args.string); } - else if (special) + else if (args.bang) BrowserReloadSkipCache(); else BrowserReload();