diff --git a/chrome/content/vimperator/commands.js b/chrome/content/vimperator/commands.js index 5970e5df..8952ec3c 100644 --- a/chrome/content/vimperator/commands.js +++ b/chrome/content/vimperator/commands.js @@ -47,8 +47,8 @@ const COMPLETEFUNC = 5; */ var g_commands = [/*{{{*/ [ - ["addons"], - ["addons"], + ["addo[ns]"], + ["addo[ns]"], "Show available Browser Extensions and Themes", "You can add/remove/disable browser extensions from this dialog.
Be aware that not all Firefox extensions work, because Vimperator overrides some keybindings and changes Firefox's GUI.", //function() { }, @@ -56,7 +56,7 @@ var g_commands = [/*{{{*/ null ], [ - ["back", "ba"], + ["ba[ck]"], ["{count}ba[ck][!]"], "Go back in the browser history", "Count is supported, :3back goes back 3 pages in the browser history.
"+ @@ -65,7 +65,7 @@ var g_commands = [/*{{{*/ null ], [ - ["bdelete", "bd", "bwipeout", "bw", "bunload", "bun", "tabclose", "tabc"], + ["bd[elete]", "bw[ipeout]", "bun[load]", "tabc[lose]"], ["{count}bd[elete][!]"], "Delete current buffer (=tab)", "Count WILL be supported in future releases, then :2bd removes two tabs and the one the right is selected.
Do :bdelete! to select the tab to the left after removing the current tab.", @@ -81,8 +81,8 @@ var g_commands = [/*{{{*/ null ], [ - ["bmadd"], - ["bmadd [-tTk] [url]"], + ["bma[dd]"], + ["bma[dd] [-tTk] [url]"], "Add a bookmark", "If you don't add a custom title, either the title of the webpage or the URL will be taken as the title.
" + "Tags WILL be some mechanism to classify bookmarks. Assume, you tag a url with the tags \"linux\" and \"computer\" you'll be able to search for bookmarks containing these tags.
" + @@ -95,8 +95,8 @@ var g_commands = [/*{{{*/ null ], [ - ["bmdel"], - ["bmdel [-T] {url}"], + ["bmd[el]"], + ["bmd[el] [-T] {url}"], "Delete a bookmark", "Deletes all bookmarks which matches the url AND the specified tags. Use <Tab> key on a regular expression to complete the url which you want to delete.
" + "The following options WILL be interpretted in the future:
" + @@ -105,7 +105,7 @@ var g_commands = [/*{{{*/ function(filter) { return get_bookmark_completions(filter); } ], [ - ["bookmarks", "bm"], + ["bookm[arks]", "bm"], ["bm[!] [-T] {regexp}"], "Show bookmarks", "Open the preview window at the bottom of the screen for all bookmarks which match the regexp either in the title or URL.
" + @@ -116,7 +116,7 @@ var g_commands = [/*{{{*/ function(filter) { return get_bookmark_completions(filter); } ], [ - ["buffer", "b"], + ["b[uffer]"], ["b[uffer] {url|index}"], "Go to buffer from buffer list", "Argument can be either the buffer index or the full URL.", @@ -132,8 +132,8 @@ var g_commands = [/*{{{*/ null ], [ - ["downloads", "dl"], - ["downloads"], + ["downl[oads]", "dl"], + ["downl[oads]"], "Show progress of current downloads", "Open the original Firefox download dialog in a new tab.
"+ "Here, downloads can be paused, canceled and resumed.", @@ -141,7 +141,7 @@ var g_commands = [/*{{{*/ null ], [ - ["echo", "ec"], + ["ec[ho]"], ["ec[ho]"], "Display a string at the bottom of the window", "Echo all arguments of this command. Useful for showing informational messages.
Multiple lines WILL be seperated by \\n.", @@ -149,7 +149,7 @@ var g_commands = [/*{{{*/ null ], [ - ["echoerr", "echoe"], + ["echoe[rr]"], ["echoe[rr]"], "Display an error string at the bottom of the window", "Echo all arguments of this command highlighted in red. Useful for showing important messages.
Multiple lines WILL be seperated by \\n.", @@ -157,7 +157,7 @@ var g_commands = [/*{{{*/ null ], [ - ["execute", "exe"], + ["exe[cute]"], ["exe[cute] {expr1} [ ... ]"], "Execute the string that results from the evaluation of {expr1} as an Ex command.", ":execute "echo test" would show a message with the text "test".
", @@ -165,8 +165,8 @@ var g_commands = [/*{{{*/ null ], [ - ["forward", "fw"], - ["{count}forward[!]"], + ["fo[rward]", "fw"], + ["{count}fo[rward][!]"], "Go forward in the browser history", "Count is supported, :3forward goes forward 3 pages in the browser history.
"+ "The special version :forward! goes to the end of the browser history.", @@ -174,7 +174,7 @@ var g_commands = [/*{{{*/ null ], [ - ["hardcopy", "ha"], + ["ha[rdcopy]"], ["ha[rdcopy]"], "Print current document", "Open a GUI dialog where you can select the printer, number of copies, orientation, etc.", @@ -182,7 +182,7 @@ var g_commands = [/*{{{*/ null ], [ - ["help", "h"], + ["h[elp]"], ["h[elp] {subject}"], "Open the help window", "You can jump to the specified {subject} with :help {subject}.
"+ @@ -192,13 +192,13 @@ var g_commands = [/*{{{*/ "
  • :help 'complete' for settings (surrounded by ' and ')
  • "+ "
  • :help o for mappings (no pre- or postfix)
  • "+ ""+ - "You can however use partial stings in the tab completion, so :help he<Tab> will complete :help :help", + "You can however use partial stings in the tab completion, so :help he<Tab> will complete :help :help.", help, function(filter) { return get_help_completions(filter); } ], [ - ["history", "hs"], - ["history {filter}"], + ["hist[ory]", "hs"], + ["hist[ory] {filter}"], "Show recently visited URLs", "Open the preview window at the bottom of the screen for all history items which match the filter string either in the title or URL."+ "Close this window with :pclose or open entries with double click in the current tab or middle click in a new tab.", @@ -206,8 +206,8 @@ var g_commands = [/*{{{*/ function(filter) { return get_history_completions(filter); } ], [ - ["javascript", "js"], - ["javascript {cmd}", "javascript <<{endpattern}\\n{script}\\n{endpattern}"], // \\n is changed to
    in the help.js code + ["javas[cript]", "js"], + ["javas[cript] {cmd}", "javascript <<{endpattern}\\n{script}\\n{endpattern}"], // \\n is changed to
    in the help.js code "Run any javascript command through eval()", "Acts as a javascript interpreter by passing the argument to eval().
    " + ":javascript alert('Hello world') would show a dialog box with the text \"Hello world\".
    " + @@ -226,7 +226,7 @@ var g_commands = [/*{{{*/ null ], [ - ["mark", "ma"], + ["ma[rk]"], ["ma[rk] {arg}"], "Mark current location within the webpage", "Not implemented yet", @@ -242,8 +242,8 @@ var g_commands = [/*{{{*/ null ], [ - ["open", "op", "o", "edit", "e"], - ["open [url] [| url]"], + ["o[pen]", "e[dit]"], + ["o[pen] [url] [| url]"], "Open one ore more URLs in the current tab", "Multiple URLs can be separated with the | character.
    " + "Each |-separated token is analayzed and in this order:
    "+ @@ -281,7 +281,7 @@ var g_commands = [/*{{{*/ function(filter) { return get_url_completions(filter); } ], [ - ["pclose", "pc"], + ["pc[lose]"], ["pc[lose]"], "Close preview window on bottom of screen", null, @@ -289,8 +289,8 @@ var g_commands = [/*{{{*/ null ], [ - ["preferences", "prefs"], - ["preferences"], + ["pref[erences]", "prefs"], + ["pref[erences]"], "Show Browser Preferences", "You can change the browser preferences from this dialog.
    Be aware that not all Firefox preferences work, because Vimperator overrides some keybindings and changes Firefox's GUI.
    "+ "Works like :set!, but opens the dialog in a new window instead of a new tab. Use this, if you experience problems/crashes when using :set!", @@ -298,7 +298,7 @@ var g_commands = [/*{{{*/ null ], [ - ["quit", "q"], + ["q[uit]"], ["q[uit]"], "Quit current tab or quit Vimperator if this was the last tab", "When quitting Vimperator, the session is not stored.", @@ -306,7 +306,7 @@ var g_commands = [/*{{{*/ null ], [ - ["quitall", "quita", "qall", "qa"], + ["quita[ll]", "qa[ll]"], ["quita[ll]"], "Quit Vimperator", "Quit Vimperator, no matter how many tabs/windows are open. The session is not stored.", @@ -314,7 +314,7 @@ var g_commands = [/*{{{*/ null ], [ - ["reload", "re"], + ["re[load]"], ["re[load]"], "Reload current page", "Forces reloading of the current page, or of all open pages, if ! is given.", @@ -322,15 +322,15 @@ var g_commands = [/*{{{*/ null ], [ - ["restart"], - ["restart"], + ["res[tart]"], + ["res[tart]"], "Force the browser to restart", "Useful when installing extenstions.", restart, null ], [ - ["saveas", "sav"], + ["sav[eas]"], ["sav[eas]"], "Save current web page to disk", "Open the original Firefox \"Save page as...\" dialog in a new tab.
    " + @@ -339,7 +339,7 @@ var g_commands = [/*{{{*/ null ], [ - ["set", "se"], + ["se[t]"], ["se[t][!]", "se[t] {option}[?]", "se[t] {option}[+-]={value}"], "Set an option", "Permanently change an option. In contrast to Vim options are stored throughout sessions.
    "+ @@ -353,7 +353,7 @@ var g_commands = [/*{{{*/ function(filter) { return get_settings_completions(filter); } ], [ - ["source", "so"], + ["so[urce]"], ["so[urce][!] {file}"], "Read Ex commands from {file}", "The .vimperatorrc file in your home directory is always sourced at start up.
    "+ @@ -363,7 +363,7 @@ var g_commands = [/*{{{*/ function (filter) { return get_file_completions(filter); } ], [ - ["stop", "st"], + ["st[op]"], ["st[op]"], "Stop loading", "Stop loading current web page.", @@ -380,7 +380,7 @@ var g_commands = [/*{{{*/ null ], [ - ["tabnext", "tabn", "tn", "tnext"], + ["tabn[ext]", "tn[ext]"], ["tabn[ext]"], "Switch to the next tab", "Cycles to the first tab, when the last is selected.", @@ -388,7 +388,7 @@ var g_commands = [/*{{{*/ null ], [ - ["tabopen", "t", "to", "topen", "tabnew", "tabedit", "tabe"], + ["tabopen", "t[open]", "tabnew", "tabe[dit]"], ["tabopen [url] [| url]"], "Open one or more URLs in a new tab", "Like :open but open URLs in a new tab.
    "+ @@ -397,7 +397,7 @@ var g_commands = [/*{{{*/ function (filter) { return get_url_completions(filter); } ], [ - ["tabonly", "tabo"], + ["tabo[nly]"], ["tabo[nly]"], "Close all other tabs", null, @@ -405,7 +405,7 @@ var g_commands = [/*{{{*/ null ], [ - ["tabmove", "tabm"], + ["tabm[ove]"], ["tabm[ove] [N]"], "Move the current tab after tab N", "When N is 0 the current tab is made the first one. Without N the current tab is made the last one.", @@ -413,7 +413,7 @@ var g_commands = [/*{{{*/ null ], [ - ["tabprevious", "tabp", "tp", "tprev", "tprevious", "tabNext", "tabN", "tN", "tNext"], + ["tabp[revious]", "tp[revious]", "tabN[ext]", "tN[ext]"], ["tabp[revious]", "tabN[ext]"], "Switch to the previous tab", "Cycles to the last tab, when the first is selected.", @@ -421,7 +421,7 @@ var g_commands = [/*{{{*/ null ], [ - ["tabrewind", "tabr", "tabfir", "tabfirst"], + ["tabr[ewind]", "tabfir[st]"], ["tabr[ewind]", "tabfir[st]"], "Switch to the first tab", null, @@ -429,7 +429,7 @@ var g_commands = [/*{{{*/ null ], [ - ["tablast", "tabl"], + ["tabl[ast]"], ["tabl[ast]"], "Switch to the last tab", null, @@ -437,26 +437,26 @@ var g_commands = [/*{{{*/ null ], [ - ["undo", "u"], - ["{count}undo"], + ["u[ndo]"], + ["{count}u[ndo]"], "Undo closing of a tab", - "If a count is given, don't close the last but the n'th last tab", + "If a count is given, don't close the last but the n'th last tab.", function(args, special, count) { if(count < 1) count = 1; undoCloseTab(count-1); }, null ], [ - ["qmarkadd", "qmadd"], - ["qmarkadd {a-zA-Z0-9} [url]"], + ["qmarka[dd]", "qma[dd]"], + ["qmarka[dd] {a-zA-Z0-9} [url]"], "Mark a URL with a letter for quick access", - "Not implemented yet", + "Not implemented yet.", function(args) { set_url_mark("mark", "url"); }, // FIXME function(filter) { return [["a", ""], ["b", ""]]; } ], [ - ["qmarkdel", "qmdel"], - ["qmarkdel {a-zA-Z0-9}"], + ["qmarkd[el]", "qmd[el]"], + ["qmarkd[el] {a-zA-Z0-9}"], "Remove a marked URL" + - "Not implemented yet", + "Not implemented yet.", function(args) { set_url_mark("mark", "url"); }, // FIXME function(filter) { return [["a", ""], ["b", ""]]; } ], @@ -464,12 +464,12 @@ var g_commands = [/*{{{*/ ["qmarks", "qms"], ["qmarks"], "Shows marked URLs", - "Not implemented yet", + "Not implemented yet.", function(args) { show_url_marks(args); }, // FIXME null ], [ - ["version", "ve"], + ["ve[rsion]"], ["ve[rsion][!]"], "Show version information", "You can show the Firefox version page with :version!.", @@ -477,15 +477,15 @@ var g_commands = [/*{{{*/ null ], [ - ["winopen", "w", "wo", "wopen", "winedit", "wine"], - ["win[open] [url] [| url]"], + ["wino[pen]", "w[open]", "wine[dit]"], + ["wino[pen] [url] [| url]"], "Open an URL in a new window", - "Not implemented yet", + "Not implemented yet.", function () { vimperator.echo("winopen not yet implemented"); }, null ], [ - ["xall", "xa", "wqall", "wqa", "wq"], + ["xa[ll]", "wqa[ll]", "wq"], ["wqa[ll]", "xa[ll]"], "Save the session and quit", "Quit Vimperator, no matter how many tabs/windows are open. The session is stored.
    "+ @@ -494,7 +494,7 @@ var g_commands = [/*{{{*/ null ], [ - ["zoom", "zo"], + ["zo[om]"], ["zo[om] {value}"], "Set zoom value of the webpage", "{value} can be between 25 and 500%. If it is omitted, zoom is reset to 100%.", @@ -526,14 +526,14 @@ var g_mappings = [/*{{{*/ ["b"], ["b {number}"], "Open a prompt to switch buffers", - "Typing the corresponding number opens switches to this buffer", + "Typing the corresponding number opens switches to this buffer.", function (args) { vimperator.commandline.open(":", "buffer ", vimperator.modes.EX); } ], [ ["B"], ["B"], "Toggle buffer list", - "Toggles the display of the buffer list which shows all opened tabs,", + "Toggles the display of the buffer list which shows all opened tabs.", toggleBufferList ], [ @@ -599,7 +599,7 @@ var g_mappings = [/*{{{*/ ["o"], ["o"], "Open one or more URLs in the current tab", - "See :open for more details", + "See :open for more details.", function(count) { vimperator.commandline.open(":", "open ", vimperator.modes.EX); } ], [ @@ -613,7 +613,7 @@ var g_mappings = [/*{{{*/ ["p", ""], ["p", ""], "Open (put) an URL based on the current clipboard contents in the current buffer", - "You can also just select some non-URL text, and search for it with the default search engine or keyword (specified by the 'defsearch' setting) with p", + "You can also just select some non-URL text, and search for it with the default search engine or keyword (specified by the 'defsearch' setting) with p.", function(count) { openURLs(readFromClipboard()); } ], [ @@ -643,7 +643,7 @@ var g_mappings = [/*{{{*/ ["t"], "Open one or more URLs in a new tab", "Like o but open URLs in a new tab.
    "+ - "See :tabopen for more details", + "See :tabopen for more details.", function(count) { vimperator.commandline.open(":", "tabopen ", vimperator.modes.EX); } ], [ @@ -657,7 +657,7 @@ var g_mappings = [/*{{{*/ ["u"], ["{count}u"], "Undo closing of a tab", - "If a count is given, don't close the last but the n'th last tab", + "If a count is given, don't close the last but the n'th last tab.", function(count) { execute_command(count, 'undo', false, ''); } ], [ @@ -737,14 +737,14 @@ var g_mappings = [/*{{{*/ ["gg", ""], ["{count}gg", "{count}"], "Goto the top of the document", - "Count is supported, 35gg vertically goes to 35% of the document", + "Count is supported, 35gg vertically goes to 35% of the document.", function(count) { scrollBufferAbsolute(-1, count > 0 ? count : 0); } ], [ ["G", ""], ["{count}G", "{count}"], "Goto the end of the document", - "Count is supported, 35G vertically goes to 35% of the document", + "Count is supported, 35G vertically goes to 35% of the document.", function(count) { scrollBufferAbsolute(-1, count >= 0 ? count : 100); } ], [ @@ -783,7 +783,7 @@ var g_mappings = [/*{{{*/ ["", "", "", ""], [""], "Scroll up a full page of the current document", - "No count support for now,", + "No count support for now.", function(count) { goDoCommand('cmd_scrollPageUp'); } ], [ @@ -827,7 +827,7 @@ var g_mappings = [/*{{{*/ ["gu", ""], ["{count}gu", "{count}"], "Go to parent directory", - "Count is supported, 2gu on http://www.example.com/dir1/dir2/file.htm would open http://www.example.com/dir1/", + "Count is supported, 2gu on http://www.example.com/dir1/dir2/file.htm would open http://www.example.com/dir1/.", goUp ], [ @@ -1076,34 +1076,86 @@ var g_hint_mappings = [ /*{{{*/ ["", "", true, true] ]; /*}}}*/ +// FIXME (DJK) [Command Name Specs]: // {{{ +// remove this when commands are objects and all short/long names etc can be +// accessed with a property + +// convert command name abbreviation specs of the form +// 'shortname[optional-tail]' to short and long versions Eg. 'abc[def]' -> +// 'abc', 'abcdef' +function _command_parse_specs(specs) +{ + var short_names = []; + var long_names = []; + for (var i = 0; i < specs.length; i++) + { + var match; + if (match = specs[i].match(/(\w+)\[(\w+)\]/)) + { + short_names.push(match[1]); + long_names.push(match[1] + match[2]); + } + else + long_names.push(specs[i]); + } + return { long_names: long_names, short_names: short_names }; +} +// match a candidate name against a command name abbreviation spec - returning +// true if the candidate matches unambiguously +function _command_match_abbreviation(name, format) +{ + var minimum = format.indexOf('['); // minumum number of characters for a command name match + var fullname = format.replace(/\[(\w+)\]$/, '$1'); // full command name + if (fullname.indexOf(name) == 0 && name.length >= minimum) + return true; + else + return false; +} +// return the primary command name (the long name of the first spec listed) +function command_name(cmd) +{ + return command_long_names(cmd)[0]; +} +// return all command name aliases +function command_names(cmd) +{ + var names = _command_parse_specs(cmd[COMMANDS]); + return names.short_names.concat(names.long_names); +} +// return all short command name aliases +function command_short_names(cmd) +{ + return _command_parse_specs(cmd[COMMANDS]).short_names; +} +// return all long command name aliases +function command_long_names(cmd) +{ + return _command_parse_specs(cmd[COMMANDS]).long_names; +} +// return true if the candidate name matches one of the command's aliases +// (including all acceptable abbreviations) +function command_has_name(cmd, name) +{ + var specs = cmd[COMMANDS]; + for (var i = 0; i < specs.length; i++) + { + if (specs[i] == name) // literal command name + return cmd; + else if (specs[i].match(/^\w+\[\w+\]$/)) // abbreviation spec + if (_command_match_abbreviation(name, specs[i])) + return true; + } + return false; +} +// }}} + // returns null, if the cmd cannot be found in our g_commands array, or // otherwise a reference to our command function get_command(cmd) // {{{ { - var commands = []; - var added; - for (var i = 0; i < g_commands.length; i++, added = false) - { - for (var j = 0; j < g_commands[i][COMMANDS].length; j++) - { - if (g_commands[i][COMMANDS][j] == cmd) - { - return g_commands[i]; //exact command, returning it - } - if (g_commands[i][COMMANDS][j].indexOf(cmd) == 0) - { - if (!added) - { - commands.push(g_commands[i]); - added = true; - } - } - } - } - // return an unambigious command even if it was only given partly - if (commands.length == 1) - return commands[0]; - + for (var i = 0; i < g_commands.length; i++) + if (command_has_name(g_commands[i], cmd)) + return g_commands[i]; return null; } // }}} @@ -1117,7 +1169,7 @@ function execute_command(count, cmd, special, args, modifiers) // {{{ var command = get_command(cmd); if (command === null) { - echoerr("E492: Not an editor command: " + cmd); + vimperator.echoerr("E492: Not an editor command: " + cmd); vimperator.focusContent(); return; } diff --git a/chrome/content/vimperator/completion.js b/chrome/content/vimperator/completion.js index f99e4f50..d4aa1ef9 100644 --- a/chrome/content/vimperator/completion.js +++ b/chrome/content/vimperator/completion.js @@ -74,23 +74,24 @@ function build_longest_starting_substring(list, filter)/*{{{*/ //var filter_length = filter.length; for (var i = 0; i < list.length; i++) { - for (var j = 0; j < list[i][COMMANDS].length; j++) + var command_names = command_long_names(list[i]); + for (var j = 0; j < command_names.length; j++) { - if (list[i][0][j].indexOf(filter) != 0) + if (command_names[j].indexOf(filter) != 0) continue; if (g_substrings.length == 0) { - var length = list[i][COMMANDS][j].length; + var length = command_names[j].length; for (var k = filter.length; k <= length; k++) - g_substrings.push(list[i][COMMANDS][j].substring(0, k)); + g_substrings.push(command_names[j].substring(0, k)); } else { g_substrings = g_substrings.filter(function($_) { - return list[i][COMMANDS][j].indexOf($_) == 0; + return command_names[j].indexOf($_) == 0; }); } - filtered.push([list[i][COMMANDS][j], list[i][SHORTHELP]]); + filtered.push([command_names[j], list[i][SHORTHELP]]); break; } } @@ -285,7 +286,7 @@ function get_command_completions(filter)/*{{{*/ //g_completions = []; g_substrings = []; if (!filter) return g_commands.map(function($_) { - return [$_[COMMANDS][0], $_[SHORTHELP]]; + return [command_name($_), $_[SHORTHELP]]; }); return build_longest_starting_substring(g_commands, filter); }/*}}}*/ diff --git a/chrome/content/vimperator/help.js b/chrome/content/vimperator/help.js index ea979e9a..f585a4d7 100644 --- a/chrome/content/vimperator/help.js +++ b/chrome/content/vimperator/help.js @@ -91,11 +91,11 @@ function help(section, easter) else ret += "Sorry, no help available"; // the tags which are printed on the top right - //ret += '===================================='; ret += ''; - for (var j=0; j < commands[i][COMMANDS].length; j++) + var names = command_names(commands[i]); + for (var j=0; j < names.length; j++) { - var cmd_name = commands[i][COMMANDS][j]; + var cmd_name = names[j]; cmd_name = cmd_name.replace(//g, ">"); // cmd_name = cmd_name.replace(/"/g, """); diff --git a/chrome/content/vimperator/vimperator.js b/chrome/content/vimperator/vimperator.js index 710ecc40..9b34e3c7 100644 --- a/chrome/content/vimperator/vimperator.js +++ b/chrome/content/vimperator/vimperator.js @@ -1108,5 +1108,19 @@ function Tabs() { return getBrowser().tabContainer.childNodes.length; } + + this.get = function(filter) + { + var buffers = []; + var browsers = getBrowser().browsers; + for (var i in browsers) + { + var title = browsers[i].contentTitle || "(Untitled)"; + var uri = browsers[i].currentURI.spec; + var number = i + 1; + buffers.push([number, title, uri]); + } + return buffers; + } } // vim: set fdm=marker sw=4 ts=4 et: