From aa3934cf2db65bdd401fd9082502f78d199e2d56 Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Fri, 29 Feb 2008 23:47:27 +0000 Subject: [PATCH] fixed system() and other io methods --- TODO | 5 ++-- content/buffer.js | 58 ++++++---------------------------------- content/commands.js | 1 - content/completion.js | 2 +- content/io.js | 48 +++++++++++++++++---------------- content/tabs.js | 53 ++++++++++++++++++++++++++++++++++-- content/ui.js | 6 +++++ content/vim.js | 2 +- locale/en-US/xhtml11.css | 3 +++ 9 files changed, 97 insertions(+), 81 deletions(-) diff --git a/TODO b/TODO index 0955bde0..5d90ebce 100644 --- a/TODO +++ b/TODO @@ -18,8 +18,6 @@ FEATURES: 8 add more autocommands (BrowserStart, TabClose, TabOpen, TabChanged, LocationChanged, any more?) 8 ;? should show more information 8 there should be a listbox/combobox mode -8 y and Y should be changed to: Y, yy and yl=yank location, ys=yank selection, - yd=yank domain name, yt=yank title, yw=yank current word, yf=yank filename, (other things to yank?) 8 all search commands should start searching from the top of the visible viewport 8 :bdelete full_url and :bdelete! filter should delete all tabs matching filter or full_url 7 adaptive learning for tab-completions @@ -44,6 +42,8 @@ FEATURES: 5 make a command to search within google search results (http://gadelkareem.com/2007/01/28/using-google-ajax-api-as-an-array/) maybe impossible, needs a per-site key from google +4 y and Y could maybe changed to, but probably not: Y, yy and yl=yank location, ys=yank selection, + yd=yank domain name, yt=yank title, yw=yank current word, yf=yank filename, (other things to yank?) 4 Add -nargs, -complete, etc. to :command 4 } { should jump to the next paragraph of the page (maybe impossible) 3 Splitting Windows with [:sp :vsp ctrl-w,s ctrl-w,v] and closing with [ctrl-w,q], moving with [ctrl-w,w or tab] @@ -53,5 +53,4 @@ FEATURES: RANDOM IDEAS: * numbered tabs * hide scrollbars: (window.content.document.body.style.overflow = "hidden" has problems with the mouse wheel) - diff --git a/content/buffer.js b/content/buffer.js index c15cdca0..b2e64768 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -150,16 +150,20 @@ vimperator.Buffer = function () //{{{ setter: function (value) { window.fullScreen = value; }, getter: function () { return window.fullScreen; } }); + vimperator.options.add(["nextpattern",], "Patterns to use when guessing the 'next' page in a document sequence", "stringlist", "\\bnext,^>$,^(>>|»)$,^(>|»),(>|»)$"); + vimperator.options.add(["previouspattern"], "Patterns to use when guessing the 'previous' page in a document sequence", "stringlist", "\\bprev|previous\\b,^<$,^(<<|«)$,^(<|«),(<|«)$"); + vimperator.options.add(["pageinfo", "pa"], "Desired info on :pa[geinfo]", "charlist", "gfm", { validator: function (value) { return !(/[^gfm]/.test(value) || value.length > 3 || value.length < 1); } }); + vimperator.options.add(["scroll", "scr"], "Number of lines to scroll with and commands", "number", 0, @@ -167,6 +171,7 @@ vimperator.Buffer = function () //{{{ validator: function (value) { return value >= 0; } } ); + vimperator.options.add(["showstatuslinks", "ssli"], "Show the destination of the link under the cursor in the status bar", "number", 1, @@ -185,6 +190,7 @@ vimperator.Buffer = function () //{{{ /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ + var modes = vimperator.config.browserModes || [vimperator.modes.NORMAL]; vimperator.mappings.add(modes, ["i", ""], @@ -337,10 +343,10 @@ vimperator.Buffer = function () //{{{ // yanking vimperator.mappings.add(modes, ["Y"], - "Copy selected text", + "Copy selected text or current word", function () { - var sel = window.content.document.getSelection(); + var sel = vimperator.buffer.getCurrentWord(); if (sel) vimperator.copyToClipboard(sel, true); else @@ -706,54 +712,6 @@ vimperator.Buffer = function () //{{{ return selection; }, - // TODO: move to tabs.js - list: function (fullmode) - { - if (fullmode) - { - // toggle the special buffer preview window - if (vimperator.bufferwindow.visible()) - { - vimperator.bufferwindow.hide(); - } - else - { - var items = vimperator.completion.buffer("")[1]; - vimperator.bufferwindow.show(items); - vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex); - } - } - else - { - // TODO: move this to vimperator.buffers.get() - var items = vimperator.completion.buffer("")[1]; - var number, indicator, title, url; - - var list = ":" + vimperator.util.escapeHTML(vimperator.commandline.getCommand()) + "
" + ""; - for (var i = 0; i < items.length; i++) - { - if (i == vimperator.tabs.index()) - indicator = " % "; - else if (i == vimperator.tabs.index(vimperator.tabs.alternate)) - indicator = " # "; - else - indicator = " "; - - [number, title] = items[i][0].split(/:\s+/, 2); - url = items[i][1]; - url = vimperator.util.escapeHTML(url); - title = vimperator.util.escapeHTML(title); - - list += ""; - } - list += "
" + number + "" + indicator + - "" + title + - "" + url + "
"; - - vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); - } - }, - scrollBottom: function () { scrollToPercentiles(-1, 100); diff --git a/content/commands.js b/content/commands.js index 56817b92..cd26b200 100644 --- a/content/commands.js +++ b/content/commands.js @@ -127,7 +127,6 @@ vimperator.Commands = function () //{{{ /////////////////////////////////////////////////////////////////////////////{{{ var exCommands = []; - var lastRunCommand = ""; // updated whenever the users runs a command with :! // in '-quoted strings, only ' and \ itself are escaped // in "-quoted strings, also ", \n and \t are translated diff --git a/content/completion.js b/content/completion.js index 27ea486b..5e74b524 100644 --- a/content/completion.js +++ b/content/completion.js @@ -134,7 +134,7 @@ vimperator.Completion = function () //{{{ substrings = []; var nodes = [ ["BrowserExit", "when firefox exits"], - ["BrowserRestart", "when firefox restarts"], + ["BrowserRestart", "when firefox restarts"], ["PageLoad", "when a page gets (re)loaded/opened"] ]; diff --git a/content/io.js b/content/io.js index 5e6b1f33..bdce12b1 100644 --- a/content/io.js +++ b/content/io.js @@ -39,6 +39,7 @@ vimperator.IO = function () //{{{ const WINDOWS = navigator.platform == "Win32"; var cwd = null, oldcwd = null; var extname = vimperator.config.name.toLowerCase(); // "vimperator" or "muttator" + var lastRunCommand = ""; // updated whenever the users runs a command with :! /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// COMMANDS //////////////////////////////////////////////// @@ -174,7 +175,7 @@ vimperator.IO = function () //{{{ ////////////////////// PUBLIC SECTION ////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ - return { + var ioManager = { MODE_RDONLY: 0x01, MODE_WRONLY: 0x02, @@ -240,7 +241,7 @@ vimperator.IO = function () //{{{ if (!dirs[i]) continue; - var fullname = this.expandPath(dirs[i]); + var fullname = ioManager.expandPath(dirs[i]); try { file.initWithPath(fullname); @@ -269,8 +270,8 @@ vimperator.IO = function () //{{{ } else { - newdir = this.expandPath(newdir); - var file = this.getFile(newdir); + newdir = ioManager.expandPath(newdir); + var file = ioManager.getFile(newdir); if (!file.exists() || !file.isDirectory()) { vimperator.echoerr("E344: Can't find directory \"" + newdir + "\" in path"); @@ -278,7 +279,7 @@ vimperator.IO = function () //{{{ } [cwd, oldcwd] = [newdir, cwd]; } - return this.getCurrentDirectory(); + return ioManager.getCurrentDirectory(); }, getSpecialDirectory: function (directory) @@ -290,15 +291,15 @@ vimperator.IO = function () //{{{ else pluginDir = "~/." + vimperator.config.name.toLowerCase() + "/" + directory; - pluginDir = this.getFile(this.expandPath(pluginDir)); + pluginDir = ioManager.getFile(ioManager.expandPath(pluginDir)); return pluginDir.exists() && pluginDir.isDirectory() ? pluginDir : null; }, getRCFile: function () { - var rcFile1 = this.getFile("~/." + vimperator.config.name.toLowerCase() + "rc"); - var rcFile2 = this.getFile("~/_" + vimperator.config.name.toLowerCase() + "rc"); + var rcFile1 = ioManager.getFile("~/." + vimperator.config.name.toLowerCase() + "rc"); + var rcFile2 = ioManager.getFile("~/_" + vimperator.config.name.toLowerCase() + "rc"); if (WINDOWS) [rcFile1, rcFile2] = [rcFile2, rcFile1] @@ -321,9 +322,9 @@ vimperator.IO = function () //{{{ createInstance(Components.interfaces.nsILocalFile); // convert relative to absolute pathname - path = this.expandPath(path); + path = ioManager.expandPath(path); if (!/^(file:|[a-zA-Z]:|\/)/.test(path)) // starts not with either /, C: or file: - path = this.getCurrentDirectory() + (WINDOWS ? "\\" : "/") + path; // TODO: for now homedir, later relative to current dir? + path = ioManager.getCurrentDirectory() + (WINDOWS ? "\\" : "/") + path; // TODO: for now homedir, later relative to current dir? else path = path.replace(/^file:(\/\/)?/, ""); @@ -359,7 +360,7 @@ vimperator.IO = function () //{{{ readDirectory: function (file) { if (typeof file == "string") - file = this.getFile(file); + file = ioManager.getFile(file); else if (!(file instanceof Components.interfaces.nsILocalFile)) throw Components.results.NS_ERROR_INVALID_ARG; // FIXME: does not work as expected, just shows undefined: undefined @@ -390,7 +391,7 @@ vimperator.IO = function () //{{{ var charset = "UTF-8"; if (typeof file == "string") - file = this.getFile(file); + file = ioManager.getFile(file); else if (!(file instanceof Components.interfaces.nsILocalFile)) throw Components.results.NS_ERROR_INVALID_ARG; // FIXME: does not work as expected, just shows undefined: undefined @@ -421,14 +422,14 @@ vimperator.IO = function () //{{{ var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports if (typeof file == "string") - file = this.getFile(file); + file = ioManager.getFile(file); else if (!(file instanceof Components.interfaces.nsILocalFile)) throw Components.results.NS_ERROR_INVALID_ARG; // FIXME: does not work as expected, just shows undefined: undefined if (mode == ">>") - mode = this.MODE_WRONLY | this.MODE_CREATE | this.MODE_APPEND; + mode = ioManager.MODE_WRONLY | ioManager.MODE_CREATE | ioManager.MODE_APPEND; else if (!mode || mode == ">") - mode = this.MODE_WRONLY | this.MODE_CREATE | this.MODE_TRUNCATE; + mode = ioManager.MODE_WRONLY | ioManager.MODE_CREATE | ioManager.MODE_TRUNCATE; if (!perms) perms = 0644; @@ -491,7 +492,7 @@ vimperator.IO = function () //{{{ // TODO: add shell/shellcmdflag options to replace "sh" and "-c" system: function (str, input) { - var fileout = this.createTempFile(); + var fileout = ioManager.createTempFile(); if (!fileout) return ""; @@ -503,18 +504,18 @@ vimperator.IO = function () //{{{ var filein = null; if (input) { - filein = this.createTempFile(); - this.writeFile(filein, input); + filein = ioManager.createTempFile(); + ioManager.writeFile(filein, input); command += " < \"" + filein.path.replace('"', '\\"') + "\""; } var res; if (WINDOWS) - res = this.run("cmd.exe", ["/C", command], true); + res = ioManager.run("cmd.exe", ["/C", command], true); else - res = this.run("sh", ["-c", command], true); + res = ioManager.run("sh", ["-c", command], true); - var output = this.readFile(fileout); + var output = ioManager.readFile(fileout); fileout.remove(false); if (filein) filein.remove(false); @@ -532,14 +533,14 @@ vimperator.IO = function () //{{{ { try { - var file = this.getFile(filename); + var file = ioManager.getFile(filename); if (!file.exists()) { if (!silent) vimperator.echoerr("E484: Can't open file " + filename); return false; } - var str = this.readFile(filename); + var str = ioManager.readFile(filename); // handle pure javascript files specially if (/\.js$/.test(filename)) @@ -602,6 +603,7 @@ vimperator.IO = function () //{{{ } } }; + return ioManager; //}}} }; //}}} diff --git a/content/tabs.js b/content/tabs.js index 992fd749..c77615c6 100644 --- a/content/tabs.js +++ b/content/tabs.js @@ -87,6 +87,7 @@ vimperator.Tabs = function () //{{{ return value.split(",").every(function (item) { return /^(homepage|quickmark|tabopen|paste|)$/.test(item); }); } }); + vimperator.options.add(["popups", "pps"], "Where to show requested popup windows", "number", 1, @@ -102,6 +103,7 @@ vimperator.Tabs = function () //{{{ }, validator: function (value) { return (value >= 0 && value <= 3); } }); + vimperator.options.add(["showtabline", "stal"], "Control when to show the tab bar of opened web pages", "number", 2, @@ -140,7 +142,7 @@ vimperator.Tabs = function () //{{{ vimperator.mappings.add([vimperator.modes.NORMAL], ["B"], "Show buffer list", - function () { vimperator.buffer.list(false); }); + function () { vimperator.tabs.list(false); }); vimperator.mappings.add([vimperator.modes.NORMAL], ["d"], "Delete current buffer", @@ -235,7 +237,7 @@ vimperator.Tabs = function () //{{{ return; } - vimperator.buffer.list(special); + vimperator.tabs.list(special); }); vimperator.commands.add(["quita[ll]", "qa[ll]"], @@ -456,6 +458,53 @@ vimperator.Tabs = function () //{{{ return getBrowser().mTabContainer.selectedItem; }, + list: function (fullmode) + { + if (fullmode) + { + // toggle the special buffer preview window + if (vimperator.bufferwindow.visible()) + { + vimperator.bufferwindow.hide(); + } + else + { + var items = vimperator.completion.buffer("")[1]; + vimperator.bufferwindow.show(items); + vimperator.bufferwindow.selectItem(getBrowser().mTabContainer.selectedIndex); + } + } + else + { + // TODO: move this to vimperator.buffers.get() + var items = vimperator.completion.buffer("")[1]; + var number, indicator, title, url; + + var list = ":" + (vimperator.util.escapeHTML(vimperator.commandline.getCommand()) || "buffers") + "
" + ""; + for (var i = 0; i < items.length; i++) + { + if (i == vimperator.tabs.index()) + indicator = " % "; + else if (i == vimperator.tabs.index(vimperator.tabs.alternate)) + indicator = " # "; + else + indicator = " "; + + [number, title] = items[i][0].split(/:\s+/, 2); + url = items[i][1]; + url = vimperator.util.escapeHTML(url); + title = vimperator.util.escapeHTML(title); + + list += ""; + } + list += "
" + number + "" + indicator + + "" + title + + "" + url + "
"; + + vimperator.commandline.echo(list, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); + } + }, + // wrap causes the movement to wrap around the start and end of the tab list // NOTE: position is a 0 based index move: function (tab, spec, wrap) diff --git a/content/ui.js b/content/ui.js index 6809449f..1b44a47d 100644 --- a/content/ui.js +++ b/content/ui.js @@ -275,18 +275,22 @@ vimperator.CommandLine = function () //{{{ vimperator.options.add(["history", "hi"], "Number of Ex commands and search patterns to store in the commandline history", "number", 500); + vimperator.options.add(["more"], "Pause the message list window when more than one screen of listings is displayed", "boolean", true); + vimperator.options.add(["complete", "cpt"], "Items which are completed at the :[tab]open prompt", "charlist", "sfbh", { validator: function (value) { return !/[^sfbh]/.test(value); } }); + vimperator.options.add(["showmode", "smd"], "Show the current mode in the command line", "boolean", true); + vimperator.options.add(["wildmode", "wim"], "Define how command line completion works", "stringlist", "list:full", @@ -296,6 +300,7 @@ vimperator.CommandLine = function () //{{{ return value.split(",").every(function (item) { return /^(full|longest|list|list:full|list:longest|)$/.test(item); }); } }); + vimperator.options.add(["wildoptions", "wop"], "Change how command line completion is done", "stringlist", "", @@ -306,6 +311,7 @@ vimperator.CommandLine = function () //{{{ /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ + var modes = [vimperator.modes.COMMAND_LINE]; vimperator.mappings.add(modes, diff --git a/content/vim.js b/content/vim.js index 579cf287..c89d947b 100644 --- a/content/vim.js +++ b/content/vim.js @@ -930,7 +930,7 @@ const vimperator = (function () //{{{ run: function () { - func.apply(window, args); + func(args); } }; } diff --git a/locale/en-US/xhtml11.css b/locale/en-US/xhtml11.css index 7a959da4..819f3c4e 100644 --- a/locale/en-US/xhtml11.css +++ b/locale/en-US/xhtml11.css @@ -1,3 +1,6 @@ +/* keep the mozdev header */ +@import url(http://www.mozdev.org/skin/color/mozdev2k.css); + /* CSS stylesheet for XHTML produced by DocBook XSL stylesheets. Tested with XSL stylesheets 1.61.2, 1.67.2