diff --git a/chrome.manifest b/chrome.manifest index fe31c25b..e26bd777 100644 --- a/chrome.manifest +++ b/chrome.manifest @@ -4,6 +4,7 @@ resource liberator modules/ locale liberator en-US locale/en-US/ skin liberator classic/1.0 skin/ override chrome://liberator/content/liberator.dtd chrome://liberator/content/vimperator.dtd +override chrome://liberator/content/config.js chrome://liberator/content/vimperator.js overlay chrome://browser/content/browser.xul chrome://liberator/content/liberator.xul overlay chrome://browser/content/browser.xul chrome://liberator/content/vimperator.xul diff --git a/content/addressbook.js b/content/addressbook.js index 56602e14..2cdc3b56 100644 --- a/content/addressbook.js +++ b/content/addressbook.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -with (liberator) liberator.Addressbook = function () //{{{ +function Addressbook() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -84,7 +84,7 @@ with (liberator) liberator.Addressbook = function () //{{{ } catch (e) { - beep(); + liberator.beep(); } if (!to) @@ -123,9 +123,9 @@ with (liberator) liberator.Addressbook = function () //{{{ displayName = generateDisplayName(firstName, lastName); if (addressbook.add(mailAddr, firstName, lastName, displayName)) - echo("Added address: " + displayName + " <" + mailAddr + ">", commandline.FORCE_SINGLELINE); + liberator.echo("Added address: " + displayName + " <" + mailAddr + ">", commandline.FORCE_SINGLELINE); else - echoerr("Exxx: Could not add bookmark `" + mailAddr + "'", commandline.FORCE_SINGLELINE); + liberator.echoerr("Exxx: Could not add bookmark `" + mailAddr + "'", commandline.FORCE_SINGLELINE); }, { @@ -189,7 +189,7 @@ with (liberator) liberator.Addressbook = function () //{{{ } if (addresses.length < 1) { - echoerr("E94: No matching contact for " + filter, commandline.FORCE_SINGLELINE); + liberator.echoerr("E94: No matching contact for " + filter, commandline.FORCE_SINGLELINE); return false; } @@ -201,7 +201,7 @@ with (liberator) liberator.Addressbook = function () //{{{ function (address) "\"" + address[0].replace(/"/g, "") + " <" + address[1] + ">\"" ).join(", "); - mail.composeNewMail(args); + liberator.mail.composeNewMail(args); } else { diff --git a/content/bookmarks.js b/content/bookmarks.js index cdf882c4..dea21581 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -27,7 +27,7 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // also includes methods for dealing with keywords and search engines -with (liberator) liberator.Bookmarks = function () //{{{ +function Bookmarks() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -43,10 +43,10 @@ with (liberator) liberator.Bookmarks = function () //{{{ const faviconService = Components.classes["@mozilla.org/browser/favicon-service;1"] .getService(Components.interfaces.nsIFaviconService); - const Bookmark = new util.Struct("url", "title", "icon", "keyword", "tags", "id"); - const Keyword = new util.Struct("keyword", "title", "icon", "url"); + const Bookmark = new Struct("url", "title", "icon", "keyword", "tags", "id"); + const Keyword = new Struct("keyword", "title", "icon", "url"); - const storage = liberator.storage; + const storage = modules.storage; function Cache(name, store, serial) { const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder]; @@ -100,7 +100,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ this.load = function load() { - // dump("cache.load()\n"); + // liberator.dump("cache.load()\n"); // update our bookmark cache bookmarks = []; this.__defineGetter__("bookmarks", function () bookmarks); @@ -141,7 +141,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ onItemMoved: function () {}, onItemAdded: function (itemId, folder, index) { - // dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n"); + // liberator.dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n"); if (bookmarksService.getItemType(itemId) == bookmarksService.TYPE_BOOKMARK) { if (rootFolders.indexOf(findRoot(itemId)) >= 0) @@ -153,7 +153,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ }, onItemRemoved: function (itemId, folder, index) { - // dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n"); + // liberator.dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n"); if (deleteBookmark(itemId)) storage.fireEvent(name, "remove", itemId); }, @@ -161,7 +161,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ { if (isAnnotation) return; - // dump("onItemChanged(" + itemId + ", " + property + ", " + value + ")\n"); + // liberator.dump("onItemChanged(" + itemId + ", " + property + ", " + value + ")\n"); var bookmark = bookmarks.filter(function (item) item.id == itemId)[0]; if (bookmark) { @@ -192,11 +192,11 @@ with (liberator) liberator.Bookmarks = function () //{{{ var cache = storage.newObject("bookmark-cache", Cache, false); storage.addObserver("bookmark-cache", bookmarkObserver); - registerObserver("shutdown", function () { + liberator.registerObserver("shutdown", function () { storage.removeObserver("bookmark-cache", bookmarkObserver) }); - registerObserver("enter", function () { + liberator.registerObserver("enter", function () { if (options["preload"]) cache.bookmarks; // Forces a load, if not already loaded. }); @@ -270,10 +270,10 @@ with (liberator) liberator.Bookmarks = function () //{{{ var extra = ""; if (title != url) extra = " (" + title + ")"; - echo("Added bookmark: " + url + extra, commandline.FORCE_SINGLELINE); + liberator.echo("Added bookmark: " + url + extra, commandline.FORCE_SINGLELINE); } else - echoerr("Exxx: Could not add bookmark `" + title + "'", commandline.FORCE_SINGLELINE); + liberator.echoerr("Exxx: Could not add bookmark `" + title + "'", commandline.FORCE_SINGLELINE); }, { argCount: "?", @@ -302,7 +302,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ let url = args || buffer.URL; let deletedCount = bookmarks.remove(url); - echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE); + liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE); }, { completer: function (filter) completion.bookmark(filter) }); @@ -356,7 +356,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ } catch (e) { - log(e, 0); + liberator.log(e, 0); return false; } @@ -415,7 +415,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ } catch (e) { - log(e, 0); + liberator.log(e, 0); return i; } @@ -497,26 +497,26 @@ with (liberator) liberator.Bookmarks = function () //{{{ if (items.length == 0) { if (filter.length > 0 && tags.length > 0) - echoerr("E283: No bookmarks matching tags: \"" + tags + "\" and string: \"" + filter + "\""); + liberator.echoerr("E283: No bookmarks matching tags: \"" + tags + "\" and string: \"" + filter + "\""); else if (filter.length > 0) - echoerr("E283: No bookmarks matching string: \"" + filter + "\""); + liberator.echoerr("E283: No bookmarks matching string: \"" + filter + "\""); else if (tags.length > 0) - echoerr("E283: No bookmarks matching tags: \"" + tags + "\""); + liberator.echoerr("E283: No bookmarks matching tags: \"" + tags + "\""); else - echoerr("No bookmarks set"); + liberator.echoerr("No bookmarks set"); return; } if (openItems) - return open([i.url for each (i in items)], NEW_TAB); + return liberator.open([i.url for each (i in items)], liberator.NEW_TAB); let list = template.bookmarks("title", ( { url: item.url, title: item.title, - extra: [['keyword', item.keyword, "hl-Keyword"], - ['tags', item.tags.join(','), "hl-Tag"] + extra: [['keyword', item.keyword, "hl-Keyword"], + ['tags', item.tags.join(', '), "hl-Tag"] ].filter(function (i) i[1]) } for each (item in items))); commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); @@ -525,7 +525,7 @@ with (liberator) liberator.Bookmarks = function () //{{{ //}}} }; //}}} -with (liberator) liberator.History = function () //{{{ +function History() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -542,12 +542,12 @@ with (liberator) liberator.History = function () //{{{ return faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec; } - var history; + var placesHistory; var cachedHistory = []; // add pages here after loading the initial Places history function load() { - history = []; + placesHistory = []; // no query parameters will get all history // XXX default sorting is... ? @@ -562,16 +562,16 @@ with (liberator) liberator.History = function () //{{{ for (let i = 0; i < rootNode.childCount; i++) { var node = rootNode.getChild(i); - // dump("History child " + node.itemId + ": " + node.title + " - " + node.type); + // liberator.dump("History child " + node.itemId + ": " + node.title + " - " + node.type); if (node.type == node.RESULT_TYPE_URI) // just make sure it's a bookmark - history.push([node.uri, node.title || "[No title]", getIcon(node.uri)]); + placesHistory.push([node.uri, node.title || "[No title]", getIcon(node.uri)]); } // close a container after using it! rootNode.containerOpen = false; } - registerObserver("enter", function () { + liberator.registerObserver("enter", function () { if (options["preload"]) load(); }); @@ -584,22 +584,22 @@ with (liberator) liberator.History = function () //{{{ mappings.add(myModes, [""], "Go to an older position in the jump list", - function (count) { liberator.history.stepTo(-(count > 1 ? count : 1)); }, + function (count) { history.stepTo(-(count > 1 ? count : 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, [""], "Go to a newer position in the jump list", - function (count) { liberator.history.stepTo(count > 1 ? count : 1); }, + function (count) { history.stepTo(count > 1 ? count : 1); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["H", "", ""], "Go back in the browser history", - function (count) { liberator.history.stepTo(-(count > 1 ? count : 1)); }, + function (count) { history.stepTo(-(count > 1 ? count : 1)); }, { flags: Mappings.flags.COUNT }); mappings.add(myModes, ["L", "", ""], "Go forward in the browser history", - function (count) { liberator.history.stepTo(count > 1 ? count : 1); }, + function (count) { history.stepTo(count > 1 ? count : 1); }, { flags: Mappings.flags.COUNT }); /////////////////////////////////////////////////////////////////////////////}}} @@ -627,11 +627,11 @@ with (liberator) liberator.History = function () //{{{ return; } } - echoerr("Exxx: URL not found in history"); + liberator.echoerr("Exxx: URL not found in history"); } else { - liberator.history.stepTo(count > 0 ? -1 * count : -1); + history.stepTo(count > 0 ? -1 * count : -1); } } }, @@ -675,11 +675,11 @@ with (liberator) liberator.History = function () //{{{ return; } } - echoerr("Exxx: URL not found in history"); + liberator.echoerr("Exxx: URL not found in history"); } else { - liberator.history.stepTo(count > 0 ? count : 1); + history.stepTo(count > 0 ? count : 1); } } }, @@ -718,12 +718,12 @@ with (liberator) liberator.History = function () //{{{ get: function (filter) { - if (!history) + if (!placesHistory) load(); if (!filter) - return cachedHistory.concat(history); - return completion.cached("history", filter, function () cachedHistory.concat(history), + return cachedHistory.concat(placesHistory); + return completion.cached("history", filter, function () cachedHistory.concat(placesHistory), "filterURLArray"); }, @@ -731,20 +731,20 @@ with (liberator) liberator.History = function () //{{{ // so just update our cached history here add: function (url, title) { - if (!history) + if (!placesHistory) load(); let filter = function (h) h[0] != url; // don't let cachedHistory grow too large if (cachedHistory.length > 1000) { - history = cachedHistory.concat(history); + placesHistory = cachedHistory.concat(placesHistory); cachedHistory = []; } else cachedHistory = cachedHistory.filter(filter); - if (history.some(function (h) h[0] == url)) - history = history.filter(filter); + if (placesHistory.some(function (h) h[0] == url)) + placesHistory = placesHistory.filter(filter); cachedHistory.unshift([url, title || "[No title]", getIcon(url)]); return true; @@ -762,7 +762,7 @@ with (liberator) liberator.History = function () //{{{ } else { - beep(); + liberator.beep(); } }, @@ -772,7 +772,7 @@ with (liberator) liberator.History = function () //{{{ if (index == 0) { - beep(); + liberator.beep(); return; } @@ -786,7 +786,7 @@ with (liberator) liberator.History = function () //{{{ if (index == max) { - beep(); + liberator.beep(); return; } @@ -800,16 +800,16 @@ with (liberator) liberator.History = function () //{{{ if (items.length == 0) { if (filter.length > 0) - echoerr("E283: No history matching \"" + filter + "\""); + liberator.echoerr("E283: No history matching \"" + filter + "\""); else - echoerr("No history set"); + liberator.echoerr("No history set"); return; } if (openItems) { - return open([i[0] for each (i in items)], NEW_TAB); + return liberator.open([i[0] for each (i in items)], liberator.NEW_TAB); } else { @@ -825,7 +825,7 @@ with (liberator) liberator.History = function () //{{{ //}}} }; //}}} -with (liberator) liberator.QuickMarks = function () //{{{ +function QuickMarks() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -841,7 +841,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ mappings.add(myModes, ["go"], "Jump to a QuickMark", - function (arg) { quickmarks.jumpTo(arg, CURRENT_TAB); }, + function (arg) { quickmarks.jumpTo(arg, liberator.CURRENT_TAB); }, { flags: Mappings.flags.ARGUMENT }); mappings.add(myModes, @@ -850,7 +850,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ { quickmarks.jumpTo(arg, /\bquickmark\b/.test(options["activate"]) ? - NEW_TAB : NEW_BACKGROUND_TAB); + liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB); }, { flags: Mappings.flags.ARGUMENT }); @@ -860,7 +860,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ { if (/[^a-zA-Z0-9]/.test(arg)) { - beep(); + liberator.beep(); return; } @@ -879,13 +879,13 @@ with (liberator) liberator.QuickMarks = function () //{{{ // TODO: finish arg parsing - we really need a proper way to do this. :) if (!special && !args) { - echoerr("E471: Argument required"); + liberator.echoerr("E471: Argument required"); return; } if (special && args) { - echoerr("E474: Invalid argument"); + liberator.echoerr("E474: Invalid argument"); return; } @@ -902,7 +902,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ { var matches = args.string.match(/^([a-zA-Z0-9])(?:\s+(.+))?$/); if (!matches) - echoerr("E488: Trailing characters"); + liberator.echoerr("E488: Trailing characters"); else if (!matches[2]) quickmarks.add(matches[1], buffer.URL); else @@ -917,7 +917,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ // ignore invalid qmark characters unless there are no valid qmark chars if (args && !/[a-zA-Z0-9]/.test(args)) { - echoerr("E283: No QuickMarks matching \"" + args + "\""); + liberator.echoerr("E283: No QuickMarks matching \"" + args + "\""); return; } @@ -957,9 +957,9 @@ with (liberator) liberator.QuickMarks = function () //{{{ var url = qmarks.get(qmark); if (url) - open(url, where); + liberator.open(url, where); else - echoerr("E20: QuickMark not set"); + liberator.echoerr("E20: QuickMark not set"); }, list: function (filter) @@ -974,7 +974,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ if (marks.length == 0) { - echoerr("No QuickMarks set"); + liberator.echoerr("No QuickMarks set"); return; } @@ -983,7 +983,7 @@ with (liberator) liberator.QuickMarks = function () //{{{ marks = marks.filter(function (qmark) filter.indexOf(qmark) >= 0); if (marks.length == 0) { - echoerr("E283: No QuickMarks matching \"" + filter + "\""); + liberator.echoerr("E283: No QuickMarks matching \"" + filter + "\""); return; } } diff --git a/content/buffer.js b/content/buffer.js index 128bca86..1216218a 100644 --- a/content/buffer.js +++ b/content/buffer.js @@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL. Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); -with (liberator) liberator.Buffer = function () //{{{ +function Buffer() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -49,8 +49,8 @@ with (liberator) liberator.Buffer = function () //{{{ var zoomLevels = [ 1, 10, 25, 50, 75, 90, 100, 120, 150, 200, 300, 500, 1000, 2000 ]; - const util = liberator.util; - const arrayIter = liberator.util.arrayIter; + const util = modules.util; + const arrayIter = util.arrayIter; function Styles(name, store, serial) { @@ -59,7 +59,7 @@ with (liberator) liberator.Buffer = function () //{{{ * with this window. */ const sleep = liberator.sleep; - const storage = liberator.storage; + const storage = modules.storage; const consoleService = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); const ios = Components.classes["@mozilla.org/network/io-service;1"] @@ -69,7 +69,7 @@ with (liberator) liberator.Buffer = function () //{{{ const XHTML = "http://www.w3.org/1999/xhtml"; const namespace = "@namespace html url(" + XHTML + ");\n" + "@namespace xul url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);\n"; - const Sheet = new util.Struct("name", "sites", "css", "ref"); + const Sheet = new Struct("name", "sites", "css", "ref"); let cssUri = function (css) "data:text/css," + encodeURI(css); @@ -284,7 +284,7 @@ with (liberator) liberator.Buffer = function () //{{{ { if (value < 1 || value > 2000) { - echoerr("Zoom value out of range (1-2000%)"); + liberator.echoerr("Zoom value out of range (1-2000%)"); return; } @@ -293,7 +293,7 @@ with (liberator) liberator.Buffer = function () //{{{ else getBrowser().markupDocumentViewer.textZoom = value / 100.0; - echo((fullZoom ? "Full zoom: " : "Text zoom: ") + value + "%"); + liberator.echo((fullZoom ? "Full zoom: " : "Text zoom: ") + value + "%"); // TODO: shouldn't this just recalculate hint coords, rather than // unsuccessfully attempt to reshow hints? i.e. isn't it just relying @@ -334,7 +334,7 @@ with (liberator) liberator.Buffer = function () //{{{ } if (index < 0 || index >= zoomLevels.length) { - beep(); + liberator.beep(); return; } setZoom(zoomLevels[index], fullZoom); @@ -344,7 +344,7 @@ with (liberator) liberator.Buffer = function () //{{{ { // NOTE: it's possible to have scrollY > scrollMaxY - FF bug? if (direction > 0 && win.scrollY >= win.scrollMaxY || direction < 0 && win.scrollY == 0) - beep(); + liberator.beep(); } function findScrollableWindow() @@ -537,7 +537,7 @@ with (liberator) liberator.Buffer = function () //{{{ if (count > 0 && count <= 100) buffer.scrollToPercentile(count); else - beep(); + liberator.beep(); }, { flags: Mappings.flags.COUNT }); @@ -625,7 +625,7 @@ with (liberator) liberator.Buffer = function () //{{{ } else { - beep(); + liberator.beep(); } } }, @@ -635,22 +635,22 @@ with (liberator) liberator.Buffer = function () //{{{ "Open (put) a URL based on the current clipboard contents in a new buffer", function () { - open(util.readFromClipboard(), + liberator.open(util.readFromClipboard(), /\bpaste\b/.test(options["activate"]) ? - NEW_BACKGROUND_TAB : NEW_TAB); + liberator.NEW_BACKGROUND_TAB : liberator.NEW_TAB); }); mappings.add(myModes, ["p", ""], "Open (put) a URL based on the current clipboard contents in the current buffer", - function () { open(util.readFromClipboard()); }); + function () { liberator.open(util.readFromClipboard()); }); mappings.add(myModes, ["P"], "Open (put) a URL based on the current clipboard contents in a new buffer", function () { - open(util.readFromClipboard(), + liberator.open(util.readFromClipboard(), /\bpaste\b/.test(options["activate"]) ? - NEW_TAB : NEW_BACKGROUND_TAB); + liberator.NEW_TAB : liberator.NEW_BACKGROUND_TAB); }); // reloading @@ -671,7 +671,7 @@ with (liberator) liberator.Buffer = function () //{{{ if (sel) util.copyToClipboard(sel, true); else - beep(); + liberator.beep(); }); // zooming @@ -746,7 +746,7 @@ with (liberator) liberator.Buffer = function () //{{{ var aps = options.getPref("print.always_print_silent"); var spp = options.getPref("print.show_print_progress"); - echo("Sending to printer..."); + liberator.echo("Sending to printer..."); options.setPref("print.always_print_silent", special); options.setPref("print.show_print_progress", !special); @@ -754,7 +754,7 @@ with (liberator) liberator.Buffer = function () //{{{ options.setPref("print.always_print_silent", aps); options.setPref("print.show_print_progress", spp); - echo("Print job sent."); + liberator.echo("Print job sent."); }, { argCount: "0", @@ -774,7 +774,7 @@ with (liberator) liberator.Buffer = function () //{{{ if (args && titles.indexOf(args) == -1) { - echoerr("E475: Invalid argument: " + args); + liberator.echoerr("E475: Invalid argument: " + args); return; } @@ -800,7 +800,7 @@ with (liberator) liberator.Buffer = function () //{{{ let doc = window.content.document; let file = io.getFile(args || ""); if (args && file.exists() && !special) - return echoerr("E13: File exists (add ! to override)"); + return liberator.echoerr("E13: File exists (add ! to override)"); options.setPref("browser.download.lastDir", io.getCurrentDirectory()); try @@ -850,7 +850,7 @@ with (liberator) liberator.Buffer = function () //{{{ { let err = styles.addSheet(name, filter, css, false, special); if (err) - echoerr(err); + liberator.echoerr(err); } }, { @@ -955,7 +955,7 @@ with (liberator) liberator.Buffer = function () //{{{ } else { - echoerr("E488: Trailing characters"); + liberator.echoerr("E488: Trailing characters"); return; } @@ -1039,7 +1039,7 @@ with (liberator) liberator.Buffer = function () //{{{ nFeed++; var type = feedTypes[feed.type] || feedTypes["application/rss+xml"]; if (verbose) - yield [feed.title, template.highlightURL(feed.href, true) +  ({type})]; + yield [feed.title, template.highlightURL(feed.href, true) + \u00a0({type})]; } } } @@ -1207,7 +1207,7 @@ with (liberator) liberator.Buffer = function () //{{{ class = highlightClasses.filter(function (i) i == class || i[0] == class)[0]; if (!class) { - echoerr("Unknown highlight keyword"); + liberator.echoerr("Unknown highlight keyword"); return; } if (!(class instanceof Array)) @@ -1228,7 +1228,7 @@ with (liberator) liberator.Buffer = function () //{{{ let error = styles.addSheet("hl-" + key, scope, css, true, force); if (error) - echoerr(error); + liberator.echoerr(error); else highlight.set(key, style); }, @@ -1347,7 +1347,7 @@ with (liberator) liberator.Buffer = function () //{{{ revString = "next"; break; default: - echoerr("Bad document relationship: " + relationship); + liberator.echoerr("Bad document relationship: " + relationship); } relText = new RegExp(relationship, "i"); @@ -1358,7 +1358,7 @@ with (liberator) liberator.Buffer = function () //{{{ { if (relText.test(elems[i].rel) || revText.test(elems[i].rev)) { - open(elems[i].href); + liberator.open(elems[i].href); return true; } } @@ -1369,7 +1369,7 @@ with (liberator) liberator.Buffer = function () //{{{ { if (relText.test(elems[i].rel) || revText.test(elems[i].rev)) { - buffer.followLink(elems[i], CURRENT_TAB); + buffer.followLink(elems[i], liberator.CURRENT_TAB); return true; } } @@ -1381,7 +1381,7 @@ with (liberator) liberator.Buffer = function () //{{{ { if (patternText.test(elems[i].textContent)) { - buffer.followLink(elems[i], CURRENT_TAB); + buffer.followLink(elems[i], liberator.CURRENT_TAB); return true; } else @@ -1392,7 +1392,7 @@ with (liberator) liberator.Buffer = function () //{{{ { if (patternText.test(children[j].alt)) { - buffer.followLink(elems[i], CURRENT_TAB); + buffer.followLink(elems[i], liberator.CURRENT_TAB); return true; } } @@ -1423,7 +1423,7 @@ with (liberator) liberator.Buffer = function () //{{{ } if (!retVal) - beep(); + liberator.beep(); }, // artificially "clicks" a link in order to open it @@ -1450,18 +1450,18 @@ with (liberator) liberator.Buffer = function () //{{{ var ctrlKey = false, shiftKey = false; switch (where) { - case NEW_TAB: - case NEW_BACKGROUND_TAB: + case liberator.NEW_TAB: + case liberator.NEW_BACKGROUND_TAB: ctrlKey = true; - shiftKey = (where == NEW_BACKGROUND_TAB); + shiftKey = (where == liberator.NEW_BACKGROUND_TAB); break; - case NEW_WINDOW: + case liberator.NEW_WINDOW: shiftKey = true; break; - case CURRENT_TAB: + case liberator.CURRENT_TAB: break; default: - log("Invalid where argument for followLink()", 0); + liberator.log("Invalid where argument for followLink()", 0); } elem.focus(); @@ -1490,7 +1490,7 @@ with (liberator) liberator.Buffer = function () //{{{ } catch (e) { - echoerr(e); + liberator.echoerr(e); } }, @@ -1505,7 +1505,7 @@ with (liberator) liberator.Buffer = function () //{{{ const COL_WIDTH = 20; if (cols > 0 && win.scrollX >= win.scrollMaxX || cols < 0 && win.scrollX == 0) - beep(); + liberator.beep(); win.scrollBy(COL_WIDTH * cols, 0); }, @@ -1604,7 +1604,7 @@ with (liberator) liberator.Buffer = function () //{{{ if (next > frames.length - 1) { if (current == frames.length - 1) - beep(); // still allow the frame indicator to be activated + liberator.beep(); // still allow the frame indicator to be activated next = frames.length - 1; } @@ -1619,7 +1619,7 @@ with (liberator) liberator.Buffer = function () //{{{ if (next < 0) { if (current == 0) - beep(); // still allow the frame indicator to be activated + liberator.beep(); // still allow the frame indicator to be activated next = 0; } @@ -1643,7 +1643,7 @@ with (liberator) liberator.Buffer = function () //{{{ // TODO: print more useful information, just like the DOM inspector showElementInfo: function (elem) { - echo(<>Element:
+ util.objectToString(elem), commandline.FORCE_MULTILINE); + liberator.echo(<>Element:
+ util.objectToString(elem), commandline.FORCE_MULTILINE); }, showPageInfo: function (verbose) @@ -1663,7 +1663,7 @@ with (liberator) liberator.Buffer = function () //{{{ info += ", bookmarked"; var pageInfoText = <>"{file}" [{info}] {title}; - echo(pageInfoText, commandline.FORCE_SINGLELINE); + liberator.echo(pageInfoText, commandline.FORCE_SINGLELINE); return; } @@ -1674,7 +1674,7 @@ with (liberator) liberator.Buffer = function () //{{{ if (opt) return template.table(opt[1], opt[0](true)); },
); - echo(list, commandline.FORCE_MULTILINE); + liberator.echo(list, commandline.FORCE_MULTILINE); }, viewSelectionSource: function () @@ -1710,17 +1710,17 @@ with (liberator) liberator.Buffer = function () //{{{ var args = commands.parseArgs(editor, [], "*", true).arguments; if (args.length < 1) { - echoerr("No editor specified"); + liberator.echoerr("No editor specified"); return; } var prog = args.shift(); args.push(url); - callFunctionInThread(null, io.run, [prog, args, true]); + liberator.callFunctionInThread(null, io.run, [prog, args, true]); } else { - open("view-source:" + url); + liberator.open("view-source:" + url); } }, @@ -1737,7 +1737,7 @@ with (liberator) liberator.Buffer = function () //{{{ //}}} }; //}}} -with (liberator) liberator.Marks = function () //{{{ +function Marks() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -1785,7 +1785,7 @@ with (liberator) liberator.Marks = function () //{{{ { if (localmark[i].location == win.location.href) { - log("Deleting local mark: " + markToString(mark, localmark[i]), 5); + liberator.log("Deleting local mark: " + markToString(mark, localmark[i]), 5); localmark.splice(i, 1); if (localmark.length == 0) localMarks.remove(mark); @@ -1800,7 +1800,7 @@ with (liberator) liberator.Marks = function () //{{{ var urlmark = urlMarks.get(mark); if (urlmark) { - log("Deleting URL mark: " + markToString(mark, urlmark), 5); + liberator.log("Deleting URL mark: " + markToString(mark, urlmark), 5); urlMarks.remove(mark); } } @@ -1849,7 +1849,7 @@ with (liberator) liberator.Marks = function () //{{{ { if (/[^a-zA-Z]/.test(arg)) { - beep(); + liberator.beep(); return; } @@ -1872,12 +1872,12 @@ with (liberator) liberator.Marks = function () //{{{ { if (!special && !args) { - echoerr("E471: Argument required"); + liberator.echoerr("E471: Argument required"); return; } if (special && args) { - echoerr("E474: Invalid argument"); + liberator.echoerr("E474: Invalid argument"); return; } var matches; @@ -1886,7 +1886,7 @@ with (liberator) liberator.Marks = function () //{{{ // NOTE: this currently differs from Vim's behavior which // deletes any valid marks in the arg list, up to the first // invalid arg, as well as giving the error message. - echoerr("E475: Invalid argument: " + matches[0]); + liberator.echoerr("E475: Invalid argument: " + matches[0]); return; } // check for illegal ranges - only allow a-z A-Z 0-9 @@ -1901,7 +1901,7 @@ with (liberator) liberator.Marks = function () //{{{ /[0-9]/.test(start) != /[0-9]/.test(end) || start > end) { - echoerr("E475: Invalid argument: " + args.match(matches[i] + ".*")[0]); + liberator.echoerr("E475: Invalid argument: " + args.match(matches[i] + ".*")[0]); return; } } @@ -1918,12 +1918,12 @@ with (liberator) liberator.Marks = function () //{{{ var mark = args.arguments[0]; if (mark.length > 1) { - echoerr("E488: Trailing characters"); + liberator.echoerr("E488: Trailing characters"); return; } if (!/[a-zA-Z]/.test(mark)) { - echoerr("E191: Argument must be a letter or forward/backward quote"); + liberator.echoerr("E191: Argument must be a letter or forward/backward quote"); return; } @@ -1938,7 +1938,7 @@ with (liberator) liberator.Marks = function () //{{{ // ignore invalid mark characters unless there are no valid mark chars if (args && !/[a-zA-Z]/.test(args)) { - echoerr("E283: No marks matching \"" + args + "\""); + liberator.echoerr("E283: No marks matching \"" + args + "\""); return; } @@ -1959,7 +1959,7 @@ with (liberator) liberator.Marks = function () //{{{ if (win.document.body.localName.toLowerCase() == "frameset") { - echoerr("Marks support for frameset pages not implemented yet"); + liberator.echoerr("Marks support for frameset pages not implemented yet"); return; } @@ -1970,7 +1970,7 @@ with (liberator) liberator.Marks = function () //{{{ if (isURLMark(mark)) { urlMarks.set(mark, { location: win.location.href, position: position, tab: tabs.getTab() }); - log("Adding URL mark: " + markToString(mark, urlMarks.get(mark)), 5); + liberator.log("Adding URL mark: " + markToString(mark, urlMarks.get(mark)), 5); } else if (isLocalMark(mark)) { @@ -1980,7 +1980,7 @@ with (liberator) liberator.Marks = function () //{{{ localMarks.set(mark, []); let vals = { location: win.location.href, position: position }; localMarks.get(mark).push(vals); - log("Adding local mark: " + markToString(mark, vals), 5); + liberator.log("Adding local mark: " + markToString(mark, vals), 5); } }, @@ -2022,7 +2022,7 @@ with (liberator) liberator.Marks = function () //{{{ pendingJumps.push(slice); // NOTE: this obviously won't work on generated pages using // non-unique URLs :( - open(slice.location, NEW_TAB); + liberator.open(slice.location, liberator.NEW_TAB); return; } var index = tabs.index(slice.tab); @@ -2036,7 +2036,7 @@ with (liberator) liberator.Marks = function () //{{{ win.location.href = slice.location; return; } - log("Jumping to URL mark: " + markToString(mark, slice), 5); + liberator.log("Jumping to URL mark: " + markToString(mark, slice), 5); win.scrollTo(slice.position.x * win.scrollMaxX, slice.position.y * win.scrollMaxY); ok = true; } @@ -2051,7 +2051,7 @@ with (liberator) liberator.Marks = function () //{{{ { if (win.location.href == slice[i].location) { - log("Jumping to local mark: " + markToString(mark, slice[i]), 5); + liberator.log("Jumping to local mark: " + markToString(mark, slice[i]), 5); win.scrollTo(slice[i].position.x * win.scrollMaxX, slice[i].position.y * win.scrollMaxY); ok = true; } @@ -2059,7 +2059,7 @@ with (liberator) liberator.Marks = function () //{{{ } if (!ok) - echoerr("E20: Mark not set"); // FIXME: move up? + liberator.echoerr("E20: Mark not set"); // FIXME: move up? }, list: function (filter) @@ -2068,7 +2068,7 @@ with (liberator) liberator.Marks = function () //{{{ if (marks.length == 0) { - echoerr("No marks set"); + liberator.echoerr("No marks set"); return; } @@ -2077,7 +2077,7 @@ with (liberator) liberator.Marks = function () //{{{ marks = marks.filter(function (mark) filter.indexOf(mark[0]) >= 0); if (marks.length == 0) { - echoerr("E283: No marks matching \"" + filter + "\""); + liberator.echoerr("E283: No marks matching \"" + filter + "\""); return; } } diff --git a/content/commands.js b/content/commands.js index 9ec7e333..018c994a 100644 --- a/content/commands.js +++ b/content/commands.js @@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL. // Do NOT create instances of this class yourself, use the helper method // commands.add() instead -with (liberator) liberator.Command = function (specs, description, action, extraInfo) //{{{ +function Command(specs, description, action, extraInfo) //{{{ { if (!specs || !action) return null; @@ -86,7 +86,7 @@ with (liberator) liberator.Command = function (specs, description, action, extra this.replacementText = extraInfo.replacementText || null; }; -with (liberator) liberator.Command.prototype = { +Command.prototype = { execute: function (args, special, count, modifiers) { @@ -151,7 +151,7 @@ with (liberator) liberator.Command.prototype = { }; //}}} -with (liberator) liberator.Commands = function () //{{{ +function Commands() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -195,7 +195,7 @@ with (liberator) liberator.Commands = function () //{{{ return NaN; } - const ArgType = new util.Struct("description", "parse"); + const ArgType = new Struct("description", "parse"); const argTypes = [ null, ["no arg", function (arg) !arg], @@ -246,7 +246,7 @@ with (liberator) liberator.Commands = function () //{{{ if (exCommands[i].name == command.name) { // never replace for now - log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); + liberator.log("Warning: :" + names[0] + " already exists, NOT replacing existing command.", 1); return false; } } @@ -479,7 +479,7 @@ with (liberator) liberator.Commands = function () //{{{ } var sub = str.substr(i); - //dump(i + ": " + sub + " - " + onlyArgumentsRemaining + "\n"); + //liberator.dump(i + ": " + sub + " - " + onlyArgumentsRemaining + "\n"); if ((!onlyArgumentsRemaining) && /^--(\s|$)/.test(sub)) { onlyArgumentsRemaining = true; @@ -536,7 +536,7 @@ with (liberator) liberator.Commands = function () //{{{ { if (!complete) { - echoerr("Invalid argument for option " + optname); + liberator.echoerr("Invalid argument for option " + optname); return null; } let compl = opt[3] || []; @@ -554,7 +554,7 @@ with (liberator) liberator.Commands = function () //{{{ arg = type.parse(arg); if (arg == null || arg == NaN) { - echoerr("Invalid argument for " + type.description + "option: " + optname); + liberator.echoerr("Invalid argument for " + type.description + "option: " + optname); return null; } } @@ -564,7 +564,7 @@ with (liberator) liberator.Commands = function () //{{{ { if (opt[2].call(this, arg) == false) { - echoerr("Invalid argument for option: " + optname); + liberator.echoerr("Invalid argument for option: " + optname); return null; } } @@ -589,12 +589,12 @@ with (liberator) liberator.Commands = function () //{{{ var [count, arg] = getNextArg(sub); if (count == -1) { - echoerr("Error parsing arguments: " + arg); + liberator.echoerr("Error parsing arguments: " + arg); return null; } else if (!onlyArgumentsRemaining && /^-/.test(arg)) { - echoerr("Invalid option: " + arg); + liberator.echoerr("Invalid option: " + arg); return null; } @@ -610,13 +610,13 @@ with (liberator) liberator.Commands = function () //{{{ // check for correct number of arguments if (args.arguments.length == 0 && (argCount == "1" || argCount == "+")) { - echoerr("E471: Argument required"); + liberator.echoerr("E471: Argument required"); return null; } else if (args.arguments.length == 1 && (argCount == "0") || args.arguments.length > 1 && (argCount == "0" || argCount == "1" || argCount == "?")) { - echoerr("E488: Trailing characters"); + liberator.echoerr("E488: Trailing characters"); return null; } @@ -705,7 +705,7 @@ with (liberator) liberator.Commands = function () //{{{ count: this.count && count }; - execute(commands.replaceTokens(this.replacementText, tokens)); + liberator.execute(commands.replaceTokens(this.replacementText, tokens)); } // TODO: Vim allows commands to be defined without {rep} if there are {attr}s @@ -717,7 +717,7 @@ with (liberator) liberator.Commands = function () //{{{ let cmd = args.arguments[0]; if (cmd != null && /\W/.test(cmd)) { - echoerr("E182: Invalid command name"); + liberator.echoerr("E182: Invalid command name"); return; } @@ -740,7 +740,7 @@ with (liberator) liberator.Commands = function () //{{{ special) ) { - echoerr("E174: Command already exists: add ! to replace it"); + liberator.echoerr("E174: Command already exists: add ! to replace it"); } } else @@ -765,7 +765,7 @@ with (liberator) liberator.Commands = function () //{{{ } else { - echo("No user-defined commands found"); + liberator.echo("No user-defined commands found"); } } }, @@ -805,7 +805,7 @@ with (liberator) liberator.Commands = function () //{{{ } } - echoerr("E184: No such user-defined command: " + name); + liberator.echoerr("E184: No such user-defined command: " + name); }, { argCount: "1", diff --git a/content/completion.js b/content/completion.js index 5d5bb55b..b676701e 100644 --- a/content/completion.js +++ b/content/completion.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -with (liberator) liberator.Completion = function () //{{{ +function Completion() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -190,8 +190,8 @@ with (liberator) liberator.Completion = function () //{{{ { try { - // dump("eval(" + util.escapeString(arg) + ")\n"); - return eval(arg); + // liberator.dump("eval(" + util.escapeString(arg) + ")\n"); + return liberator.eval(arg); } catch (e) { @@ -339,7 +339,7 @@ with (liberator) liberator.Completion = function () //{{{ } catch (e) { - dump(util.escapeString(string) + ": " + e + "\n" + e.stack); + liberator.dump(util.escapeString(string) + ": " + e + "\n" + e.stack); lastIdx = 0; return [0, []]; } @@ -871,7 +871,7 @@ with (liberator) liberator.Completion = function () //{{{ return [dir.length, this.cached("file-" + dir, compl, generate, "filter", [true])]; else return [0, this.cached("file", filter, generate, "filter", [true])]; - }catch(e){dump(e)} + }catch(e){liberator.dump(e)} }, help: function help(filter) @@ -889,7 +889,7 @@ with (liberator) liberator.Completion = function () //{{{ } catch (e) { - log("Error opening chrome://liberator/locale/" + files[i], 1); + liberator.log("Error opening chrome://liberator/locale/" + files[i], 1); continue; } var doc = xmlhttp.responseXML; @@ -913,7 +913,7 @@ with (liberator) liberator.Completion = function () //{{{ } catch (e) { - dump(e); + liberator.dump(e); return [0, []]; } }, @@ -932,14 +932,14 @@ with (liberator) liberator.Completion = function () //{{{ let engines = this.filter(keywords.concat(bookmarks.getSearchEngines()), filter, false, true); let generate = function () { - let history = liberator.history.get(); + let hist = history.get(); let searches = []; for (let [, k] in Iterator(keywords)) { if (k[0].toLowerCase() != keyword.toLowerCase() || k[3].indexOf("%s") == -1) continue; let [begin, end] = k[3].split("%s"); - for (let [, h] in Iterator(history)) + for (let [, h] in Iterator(hist)) { if (h[0].indexOf(begin) == 0 && (!end.length || h[0].substr(-end.length) == end)) { diff --git a/content/editor.js b/content/editor.js index 6cee45fd..b29a11d9 100644 --- a/content/editor.js +++ b/content/editor.js @@ -29,7 +29,7 @@ the terms of any one of the MPL, the GPL or the LGPL. // command names taken from: // http://developer.mozilla.org/en/docs/Editor_Embedding_Guide -with (liberator) liberator.Editor = function () //{{{ +function Editor() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -229,7 +229,7 @@ with (liberator) liberator.Editor = function () //{{{ mappings.add(myModes, ["", "", "", "", ""], "Ignore certain " + config.hostApplication + " key bindings", - function () { /*beep();*/ }); + function () { /*liberator.beep();*/ }); mappings.add(myModes, [""], "Delete previous word", @@ -285,7 +285,7 @@ with (liberator) liberator.Editor = function () //{{{ // FIXME: does not work correctly mappings.add([modes.INSERT], [""], "Edit text field in vi mode", - function () { liberator.mode = liberator.modes.TEXTAREA; }); + function () { liberator.mode = modes.TEXTAREA; }); mappings.add([modes.INSERT], ["", ""], "Expand insert mode abbreviation", @@ -306,7 +306,7 @@ with (liberator) liberator.Editor = function () //{{{ function (count) { editor.executeCommand("cmd_undo", count); - liberator.mode = liberator.modes.TEXTAREA; + liberator.mode = modes.TEXTAREA; }, { flags: Mappings.flags.COUNT }); @@ -315,7 +315,7 @@ with (liberator) liberator.Editor = function () //{{{ function (count) { editor.executeCommand("cmd_redo", count); - liberator.mode = liberator.modes.TEXTAREA; + liberator.mode = modes.TEXTAREA; }, { flags: Mappings.flags.COUNT }); @@ -355,7 +355,7 @@ with (liberator) liberator.Editor = function () //{{{ // visual mode mappings.add([modes.CARET, modes.TEXTAREA, modes.VISUAL], ["v"], "Start visual mode", - function (count) { modes.set(modes.VISUAL, mode); }); + function (count) { modes.set(modes.VISUAL, liberator.mode); }); mappings.add([modes.TEXTAREA], ["V"], "Start visual line mode", @@ -376,7 +376,7 @@ with (liberator) liberator.Editor = function () //{{{ modes.set(modes.INSERT, modes.TEXTAREA); } else - beep(); + liberator.beep(); }); mappings.add([modes.VISUAL], @@ -389,7 +389,7 @@ with (liberator) liberator.Editor = function () //{{{ modes.set(modes.TEXTAREA); } else - beep(); + liberator.beep(); }); mappings.add([modes.VISUAL], @@ -407,7 +407,7 @@ with (liberator) liberator.Editor = function () //{{{ if (sel) util.copyToClipboard(sel, true); else - beep(); + liberator.beep(); } }); @@ -420,10 +420,10 @@ with (liberator) liberator.Editor = function () //{{{ if (!count) count = 1; while (count--) editor.executeCommand("cmd_paste"); - liberator.mode = liberator.modes.TEXTAREA; + liberator.mode = modes.TEXTAREA; } else - beep(); + liberator.beep(); }); // finding characters @@ -433,7 +433,7 @@ with (liberator) liberator.Editor = function () //{{{ { var pos = editor.findCharForward(arg, count); if (pos >= 0) - editor.moveToPosition(pos, true, mode == modes.VISUAL); + editor.moveToPosition(pos, true, liberator.mode == modes.VISUAL); }, { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); @@ -443,7 +443,7 @@ with (liberator) liberator.Editor = function () //{{{ { var pos = editor.findCharBackward(arg, count); if (pos >= 0) - editor.moveToPosition(pos, false, mode == modes.VISUAL); + editor.moveToPosition(pos, false, liberator.mode == modes.VISUAL); }, { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); @@ -453,7 +453,7 @@ with (liberator) liberator.Editor = function () //{{{ { var pos = editor.findCharForward(arg, count); if (pos >= 0) - editor.moveToPosition(pos - 1, true, mode == modes.VISUAL); + editor.moveToPosition(pos - 1, true, liberator.mode == modes.VISUAL); }, { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); @@ -463,7 +463,7 @@ with (liberator) liberator.Editor = function () //{{{ { var pos = editor.findCharBackward(arg, count); if (pos >= 0) - editor.moveToPosition(pos + 1, false, mode == modes.VISUAL); + editor.moveToPosition(pos + 1, false, liberator.mode == modes.VISUAL); }, { flags: Mappings.flags.ARGUMENT | Mappings.flags.COUNT }); @@ -487,7 +487,7 @@ with (liberator) liberator.Editor = function () //{{{ var pos = getEditor().selectionStart; if (pos >= text.length) { - beep(); + liberator.beep(); return; } var chr = text[pos]; @@ -575,7 +575,7 @@ with (liberator) liberator.Editor = function () //{{{ var controller = getController(); if (!controller || !controller.supportsCommand(cmd) || !controller.isCommandEnabled(cmd)) { - beep(); + liberator.beep(); return false; } @@ -596,7 +596,7 @@ with (liberator) liberator.Editor = function () //{{{ catch (e) { if (!didCommand) - beep(); + liberator.beep(); return false; } } @@ -662,7 +662,7 @@ with (liberator) liberator.Editor = function () //{{{ break; default: - beep(); + liberator.beep(); return false; } @@ -683,7 +683,7 @@ with (liberator) liberator.Editor = function () //{{{ break; default: - beep(); + liberator.beep(); return false; } return true; @@ -748,7 +748,7 @@ with (liberator) liberator.Editor = function () //{{{ return i + 1; // always position the cursor after the char } - beep(); + liberator.beep(); return -1; }, @@ -775,7 +775,7 @@ with (liberator) liberator.Editor = function () //{{{ return i; } - beep(); + liberator.beep(); return -1; }, @@ -798,7 +798,7 @@ with (liberator) liberator.Editor = function () //{{{ var args = commands.parseArgs(editor, [], "*", true).arguments; if (args.length < 1) { - echoerr("No editor specified"); + liberator.echoerr("No editor specified"); return false; } @@ -808,7 +808,7 @@ with (liberator) liberator.Editor = function () //{{{ } catch (e) { - echoerr("Could not create temporary file: " + e.message); + liberator.echoerr("Could not create temporary file: " + e.message); return false; } try @@ -817,7 +817,7 @@ with (liberator) liberator.Editor = function () //{{{ } catch (e) { - echoerr("Could not write to temporary file " + tmpfile.path + ": " + e.message); + liberator.echoerr("Could not write to temporary file " + tmpfile.path + ": " + e.message); return false; } @@ -833,7 +833,7 @@ with (liberator) liberator.Editor = function () //{{{ } // TODO: save return value in v:shell_error - callFunctionInThread(null, io.run, [prog, args, true]); + liberator.callFunctionInThread(null, io.run, [prog, args, true]); if (textBox) textBox.removeAttribute("readonly"); @@ -841,7 +841,7 @@ with (liberator) liberator.Editor = function () //{{{ // if (v:shell_error != 0) // { // tmpBg = "red"; - // echoerr("External editor returned with exit code " + retcode); + // liberator.echoerr("External editor returned with exit code " + retcode); // } // else // { @@ -868,7 +868,7 @@ with (liberator) liberator.Editor = function () //{{{ catch (e) { tmpBg = "red"; - echoerr("Could not read from temporary file " + tmpfile.path + ": " + e.message); + liberator.echoerr("Could not read from temporary file " + tmpfile.path + ": " + e.message); } // } @@ -915,11 +915,11 @@ with (liberator) liberator.Editor = function () //{{{ for (let i = 0; i < abbrev[lhs].length; i++) { if (abbrev[lhs][i][0] == filter) - echo(abbrev[lhs][i][0] + " " + lhs + " " + abbrev[lhs][i][1]); + liberator.echo(abbrev[lhs][i][0] + " " + lhs + " " + abbrev[lhs][i][1]); return true; } } - echoerr("No abbreviations found"); + liberator.echoerr("No abbreviations found"); return false; } else // list all (for that filter {i,c,!}) @@ -943,7 +943,7 @@ with (liberator) liberator.Editor = function () //{{{ if (list.*.length()) commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); else - echoerr("No abbreviations found"); + liberator.echoerr("No abbreviations found"); } }, @@ -1033,7 +1033,7 @@ with (liberator) liberator.Editor = function () //{{{ { if (!lhs) { - echoerr("E474: Invalid argument"); + liberator.echoerr("E474: Invalid argument"); return false; } @@ -1071,7 +1071,7 @@ with (liberator) liberator.Editor = function () //{{{ } } - echoerr("E24: No such abbreviation"); + liberator.echoerr("E24: No such abbreviation"); return false; }, diff --git a/content/events.js b/content/events.js index 78927e07..da8faec4 100644 --- a/content/events.js +++ b/content/events.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -with (liberator) liberator.AutoCommands = function () //{{{ +function AutoCommands() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -83,7 +83,7 @@ with (liberator) liberator.AutoCommands = function () //{{{ events = event.split(","); if (!events.every(function (event) validEvents.indexOf(event) >= 0)) { - echoerr("E216: No such group or event: " + event); + liberator.echoerr("E216: No such group or event: " + event); return; } } @@ -144,18 +144,18 @@ with (liberator) liberator.AutoCommands = function () //{{{ if (event == "*") { - echoerr("E217: Can't execute autocommands for ALL events"); + liberator.echoerr("E217: Can't execute autocommands for ALL events"); } else if (validEvents.indexOf(event) == -1) { - echoerr("E216: No such group or event: " + args); + liberator.echoerr("E216: No such group or event: " + args); } else { // TODO: perhaps trigger could return the number of autocmds triggered // TODO: Perhaps this should take -args to pass to the command? if (!autocommands.get(event).some(function (c) c.pattern.test(url))) - echo("No matching autocommands"); + liberator.echo("No matching autocommands"); else autocommands.trigger(event, {url: url}); } @@ -184,7 +184,7 @@ with (liberator) liberator.AutoCommands = function () //{{{ if (typeof events == "string") { events = events.split(","); - log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names"); + liberator.log("DEPRECATED: the events list arg to autocommands.add() should be an array of event names"); } events.forEach(function (event) store.push({event: event, pattern: RegExp(regex), command: cmd})); @@ -242,7 +242,7 @@ with (liberator) liberator.AutoCommands = function () //{{{ let autoCmds = store.filter(function (autoCmd) autoCmd.event == event); - echomsg("Executing " + event + " Auto commands for \"*\"", 8); + liberator.echomsg("Executing " + event + " Auto commands for \"*\"", 8); let lastPattern = null; @@ -252,12 +252,12 @@ with (liberator) liberator.AutoCommands = function () //{{{ if (autoCmd.pattern.test(url)) { if (!lastPattern || lastPattern.source != autoCmd.pattern.source) - echomsg("Executing " + event + " Auto commands for \"" + autoCmd.pattern.source + "\"", 8); + liberator.echomsg("Executing " + event + " Auto commands for \"" + autoCmd.pattern.source + "\"", 8); lastPattern = autoCmd.pattern; - echomsg("autocommand " + autoCmd.command, 9); - execute(commands.replaceTokens(autoCmd.command, args)); + liberator.echomsg("autocommand " + autoCmd.command, 9); + liberator.execute(commands.replaceTokens(autoCmd.command, args)); } } } @@ -265,12 +265,14 @@ with (liberator) liberator.AutoCommands = function () //{{{ //}}} }; //}}} -with (liberator) liberator.Events = function () //{{{ +function Events() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ + const input = liberator.input; + var inputBufferLength = 0; // count the number of keys in v.input.buffer (can be different from v.input.buffer.length) var skipMap = false; // while feeding the keys (stored in v.input.buffer | no map found) - ignore mappings @@ -306,7 +308,7 @@ with (liberator) liberator.Events = function () //{{{ tabs.updateSelectionHistory(); if (options["focuscontent"]) - setTimeout(function () { focusContent(true); }, 10); // just make sure, that no widget has focus + setTimeout(function () { liberator.focusContent(true); }, 10); // just make sure, that no widget has focus }, false); } @@ -365,7 +367,7 @@ with (liberator) liberator.Events = function () //{{{ // window.document.addEventListener("DOMTitleChanged", function (event) // { - // log("titlechanged"); + // liberator.log("titlechanged"); // }, null); // NOTE: the order of ["Esc", "Escape"] or ["Escape", "Esc"] @@ -523,7 +525,7 @@ with (liberator) liberator.Events = function () //{{{ } else // background tab { - echomsg("Background tab loaded: " + title || url, 1); + liberator.echomsg("Background tab loaded: " + title || url, 1); } triggerLoadAutocmd("PageLoad", doc); @@ -541,12 +543,12 @@ with (liberator) liberator.Events = function () //{{{ catch (e) { if (e.message == "Interrupted") - echoerr("Interrupted"); + liberator.echoerr("Interrupted"); else - echoerr("Processing " + event.type + " event: " + (e.echoerr || e)); + liberator.echoerr("Processing " + event.type + " event: " + (e.echoerr || e)); + liberator.dump(e); if (Components.utils.reportError) Components.utils.reportError(e); - liberator.dump(e); } } } @@ -554,8 +556,8 @@ with (liberator) liberator.Events = function () //{{{ // return true when load successful, or false otherwise function waitForPageLoaded() { - dump("start waiting in loaded state: " + buffer.loaded); - threadYield(true); // clear queue + liberator.dump("start waiting in loaded state: " + buffer.loaded); + liberator.threadYield(true); // clear queue if (buffer.loaded == 1) return true; @@ -564,32 +566,32 @@ with (liberator) liberator.Events = function () //{{{ var then = new Date().getTime(); for (let now = then; now - then < ms; now = new Date().getTime()) { - threadYield(); + liberator.threadYield(); if ((now - then) % 1000 < 10) - dump("waited: " + (now - then) + " ms"); + liberator.dump("waited: " + (now - then) + " ms"); if (!events.feedingKeys) return false; if (buffer.loaded > 0) { - sleep(250); + liberator.sleep(250); break; } else - echo("Waiting for page to load..."); + liberator.echo("Waiting for page to load..."); } modes.show(); // TODO: allow macros to be continued when page does not fully load with an option var ret = (buffer.loaded == 1); if (!ret) - echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped."); - dump("done waiting: " + ret); + liberator.echoerr("Page did not load completely in " + ms + " milliseconds. Macro stopped."); + liberator.dump("done waiting: " + ret); // sometimes the input widget had focus when replaying a macro // maybe this call should be moved somewhere else? - // focusContent(true); + // liberator.focusContent(true); return ret; } @@ -606,9 +608,9 @@ with (liberator) liberator.Events = function () //{{{ { for (let [,dir] in Iterator(dirs)) { - echomsg("Searching for \"macros/*\" in \"" + dir.path + "\"", 2); + liberator.echomsg("Searching for \"macros/*\" in \"" + dir.path + "\"", 2); - log("Sourcing macros directory: " + dir.path + "...", 3); + liberator.log("Sourcing macros directory: " + dir.path + "...", 3); let files = io.readDirectory(dir.path); @@ -620,19 +622,19 @@ with (liberator) liberator.Events = function () //{{{ let name = file.leafName.replace(/\.vimp$/i, ""); macros.set(name, io.readFile(file).split("\n")[0]); - log("Macro " + name + " added: " + macros.get(name), 5); + liberator.log("Macro " + name + " added: " + macros.get(name), 5); }); } } else { - log("No user macros directory found", 3); + liberator.log("No user macros directory found", 3); } } catch (e) { // thrown if directory does not exist - log("Error sourcing macros directory: " + e, 9); + liberator.log("Error sourcing macros directory: " + e, 9); } }, 100); @@ -710,7 +712,7 @@ with (liberator) liberator.Events = function () //{{{ { XML.prettyPrinting = false; var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args)); - echo(str, commandline.FORCE_MULTILINE); + liberator.echo(str, commandline.FORCE_MULTILINE); }, { completer: function (filter) completion.macro(filter) }); @@ -735,7 +737,7 @@ with (liberator) liberator.Events = function () //{{{ destroy: function () { // removeEventListeners() to avoid mem leaks - dump("TODO: remove all eventlisteners"); + liberator.dump("TODO: remove all eventlisteners"); if (typeof getBrowser != "undefined") getBrowser().removeProgressListener(this.progressListener); @@ -754,7 +756,7 @@ with (liberator) liberator.Events = function () //{{{ if (!/[a-zA-Z0-9]/.test(macro)) { // TODO: ignore this like Vim? - echoerr("E354: Invalid register name: '" + macro + "'"); + liberator.echoerr("E354: Invalid register name: '" + macro + "'"); return; } @@ -778,7 +780,7 @@ with (liberator) liberator.Events = function () //{{{ var res = false; if (!/[a-zA-Z0-9@]/.test(macro) && macro.length == 1) { - echoerr("E354: Invalid register name: '" + macro + "'"); + liberator.echoerr("E354: Invalid register name: '" + macro + "'"); return false; } @@ -786,7 +788,7 @@ with (liberator) liberator.Events = function () //{{{ { if (!lastMacro) { - echoerr("E748: No previously used register"); + liberator.echoerr("E748: No previously used register"); return false; } } @@ -816,9 +818,9 @@ with (liberator) liberator.Events = function () //{{{ { if (lastMacro.length == 1) // TODO: ignore this like Vim? - echoerr("Exxx: Register " + lastMacro + " not set"); + liberator.echoerr("Exxx: Register " + lastMacro + " not set"); else - echoerr("Exxx: Named macro '" + lastMacro + "' not set"); + liberator.echoerr("Exxx: Named macro '" + lastMacro + "' not set"); } return res; }, @@ -922,7 +924,7 @@ with (liberator) liberator.Events = function () //{{{ if (modes.isReplaying && !waitForPageLoaded()) break; // else // a short break between keys often helps - // sleep(50); + // liberator.sleep(50); } this.feedingKeys = wasFeeding; return i == keys.length; @@ -1025,7 +1027,7 @@ with (liberator) liberator.Events = function () //{{{ onFocusChange: function (event) { // command line has it's own focus change handler - if (mode == modes.COMMAND_LINE) + if (liberator.mode == modes.COMMAND_LINE) return; var win = window.document.commandDispatcher.focusedWindow; @@ -1033,9 +1035,9 @@ with (liberator) liberator.Events = function () //{{{ if (elem && elem.readOnly) return; - //log("onFocusChange: " + elem); - //dump("=+++++++++=\n" + util.objectToString(event.target) + "\n") - //dump (elem + ": " + win + "\n");//" - target: " + event.target + " - origtarget: " + event.originalTarget + " - expltarget: " + event.explicitOriginalTarget + "\n"); + //liberator.log("onFocusChange: " + elem); + //liberator.dump("=+++++++++=\n" + util.objectToString(event.target) + "\n") + //liberator.dump (elem + ": " + win + "\n");//" - target: " + event.target + " - origtarget: " + event.originalTarget + " - expltarget: " + event.explicitOriginalTarget + "\n"); if (elem && ( (elem instanceof HTMLInputElement && (elem.type.toLowerCase() == "text" || elem.type.toLowerCase() == "password")) || @@ -1043,7 +1045,7 @@ with (liberator) liberator.Events = function () //{{{ )) { this.wantsModeReset = false; - liberator.mode = liberator.modes.INSERT; + liberator.mode = modes.INSERT; buffer.lastInputField = elem; return; } @@ -1069,24 +1071,24 @@ with (liberator) liberator.Events = function () //{{{ { if (config.isComposeWindow) { - dump("Compose editor got focus"); + liberator.dump("Compose editor got focus"); modes.set(modes.INSERT, modes.TEXTAREA); } - else if (mode != modes.MESSAGE) - liberator.mode = liberator.modes.MESSAGE; + else if (liberator.mode != modes.MESSAGE) + liberator.mode = modes.MESSAGE; return; } } - if (mode == modes.INSERT || - mode == modes.TEXTAREA || - mode == modes.MESSAGE || - mode == modes.VISUAL) + if (liberator.mode == modes.INSERT || + liberator.mode == modes.TEXTAREA || + liberator.mode == modes.MESSAGE || + liberator.mode == modes.VISUAL) { // FIXME: currently this hack is disabled to make macros work // this.wantsModeReset = true; // setTimeout(function () { - // dump("cur: " + mode + "\n"); + // liberator.dump("cur: " + liberator.mode + "\n"); // if (events.wantsModeReset) // { // events.wantsModeReset = false; @@ -1103,15 +1105,15 @@ with (liberator) liberator.Events = function () //{{{ if (controller && controller.isCommandEnabled("cmd_copy")) couldCopy = true; - if (mode != modes.VISUAL) + if (liberator.mode != modes.VISUAL) { if (couldCopy) { - if ((mode == modes.TEXTAREA || + if ((liberator.mode == modes.TEXTAREA || (modes.extended & modes.TEXTAREA)) && !options["insertmode"]) modes.set(modes.VISUAL, modes.TEXTAREA); - else if (mode == modes.CARET) + else if (liberator.mode == modes.CARET) modes.set(modes.VISUAL, modes.CARET); } } @@ -1119,7 +1121,7 @@ with (liberator) liberator.Events = function () //{{{ // else // { // if (!couldCopy && modes.extended & modes.CARET) - // liberator.mode = liberator.modes.CARET; + // liberator.mode = modes.CARET; // } }, @@ -1134,7 +1136,7 @@ with (liberator) liberator.Events = function () //{{{ return; } - switch (mode) + switch (liberator.mode) { case modes.NORMAL: // clear any selection made @@ -1147,14 +1149,14 @@ with (liberator) liberator.Events = function () //{{{ commandline.clear(); modes.reset(); - focusContent(true); + liberator.focusContent(true); break; case modes.VISUAL: if (modes.extended & modes.TEXTAREA) - liberator.mode = liberator.modes.TEXTAREA; + liberator.mode = modes.TEXTAREA; else if (modes.extended & modes.CARET) - liberator.mode = liberator.modes.CARET; + liberator.mode = modes.CARET; break; case modes.CARET: @@ -1166,12 +1168,12 @@ with (liberator) liberator.Events = function () //{{{ case modes.INSERT: if ((modes.extended & modes.TEXTAREA) && !options["insertmode"]) { - liberator.mode = liberator.modes.TEXTAREA; + liberator.mode = modes.TEXTAREA; } else { modes.reset(); - focusContent(true); + liberator.focusContent(true); } break; @@ -1190,22 +1192,22 @@ with (liberator) liberator.Events = function () //{{{ if (!key) return true; - //log(key + " in mode: " + mode); - //dump(key + " in mode: " + mode + "\n"); + //liberator.log(key + " in mode: " + liberator.mode); + //liberator.dump(key + " in mode: " + liberator.mode + "\n"); if (modes.isRecording) { if (key == "q") // TODO: should not be hardcoded { modes.isRecording = false; - log("Recorded " + currentMacro + ": " + macros.get(currentMacro), 9); - echo("Recorded macro '" + currentMacro + "'"); + liberator.log("Recorded " + currentMacro + ": " + macros.get(currentMacro), 9); + liberator.echo("Recorded macro '" + currentMacro + "'"); event.preventDefault(); event.stopPropagation(); return true; } else if (!(modes.extended & modes.INACTIVE_HINT) && - !mappings.hasMap(mode, input.buffer + key)) + !mappings.hasMap(liberator.mode, input.buffer + key)) { macros.set(currentMacro, macros.get(currentMacro) + key); } @@ -1223,7 +1225,7 @@ with (liberator) liberator.Events = function () //{{{ if (key == "" && !event.isMacro) { events.feedingKeys = false; - setTimeout(function () { echo("Canceled playback of macro '" + lastMacro + "'") }, 100); + setTimeout(function () { liberator.echo("Canceled playback of macro '" + lastMacro + "'") }, 100); event.preventDefault(); event.stopPropagation(); return true; @@ -1258,7 +1260,7 @@ with (liberator) liberator.Events = function () //{{{ } // just forward event without checking any mappings when the MOW is open - if (mode == modes.COMMAND_LINE && + if (liberator.mode == modes.COMMAND_LINE && (modes.extended & modes.OUTPUT_MULTILINE)) { commandline.onMultilineOutputEvent(event); @@ -1270,8 +1272,8 @@ with (liberator) liberator.Events = function () //{{{ // XXX: ugly hack for now pass certain keys to firefox as they are without beeping // also fixes key navigation in combo boxes, submitting forms, etc. // FIXME: breaks iabbr for now --mst - if ((config.name == "Vimperator" && mode == modes.NORMAL) - || mode == modes.INSERT) + if ((config.name == "Vimperator" && liberator.mode == modes.NORMAL) + || liberator.mode == modes.INSERT) { if (key == "") return false; @@ -1302,7 +1304,7 @@ with (liberator) liberator.Events = function () //{{{ if (key != "" && key != "") { // custom mode... - if (mode == modes.CUSTOM) + if (liberator.mode == modes.CUSTOM) { plugins.onEvent(event); event.preventDefault(); @@ -1310,7 +1312,7 @@ with (liberator) liberator.Events = function () //{{{ return false; } // if Hint mode is on, special handling of keys is required - if (mode == modes.HINTS) + if (liberator.mode == modes.HINTS) { hints.onEvent(event); event.preventDefault(); @@ -1326,22 +1328,22 @@ with (liberator) liberator.Events = function () //{{{ // whatever reason). if that happens to be correct, well.. // XXX: why not just do that as well for HINTS mode actually? - if (mode == modes.CUSTOM) + if (liberator.mode == modes.CUSTOM) return true; var countStr = input.buffer.match(/^[0-9]*/)[0]; var candidateCommand = (input.buffer + key).replace(countStr, ""); var map; if (event.noremap) - map = mappings.getDefault(mode, candidateCommand); + map = mappings.getDefault(liberator.mode, candidateCommand); else - map = mappings.get(mode, candidateCommand); + map = mappings.get(liberator.mode, candidateCommand); // counts must be at the start of a complete mapping (10j -> go 10 lines down) if (/^[1-9][0-9]*$/.test(input.buffer + key)) { // no count for insert mode mappings - if (mode == modes.INSERT || mode == modes.COMMAND_LINE) + if (liberator.mode == modes.INSERT || liberator.mode == modes.COMMAND_LINE) stop = false; else { @@ -1367,7 +1369,7 @@ with (liberator) liberator.Events = function () //{{{ // (allows you to do :map z yy, when zz is a longer mapping than z) // TODO: map.rhs is only defined for user defined commands, should add a "isDefault" property else if (map && !skipMap && (map.rhs || - mappings.getCandidates(mode, candidateCommand).length == 0)) + mappings.getCandidates(liberator.mode, candidateCommand).length == 0)) { input.count = parseInt(countStr, 10); if (isNaN(input.count)) @@ -1408,7 +1410,7 @@ with (liberator) liberator.Events = function () //{{{ stop = false; } } - else if (mappings.getCandidates(mode, candidateCommand).length > 0 && !skipMap) + else if (mappings.getCandidates(liberator.mode, candidateCommand).length > 0 && !skipMap) { input.buffer += key; inputBufferLength++; @@ -1416,8 +1418,8 @@ with (liberator) liberator.Events = function () //{{{ else // if the key is neither a mapping nor the start of one { // the mode checking is necessary so that things like g do not beep - if (input.buffer != "" && !skipMap && (mode == modes.INSERT || - mode == modes.COMMAND_LINE || mode == modes.TEXTAREA)) + if (input.buffer != "" && !skipMap && (liberator.mode == modes.INSERT || + liberator.mode == modes.COMMAND_LINE || liberator.mode == modes.TEXTAREA)) { // no map found -> refeed stuff in v.input.buffer (only while in INSERT, CO... modes) skipMap = true; // ignore maps while doing so @@ -1438,14 +1440,14 @@ with (liberator) liberator.Events = function () //{{{ // allow key to be passed to firefox if we can't handle it stop = false; - if (mode == modes.COMMAND_LINE) + if (liberator.mode == modes.COMMAND_LINE) { if (!(modes.extended & modes.INPUT_MULTILINE)) commandline.onEvent(event); // reroute event in command line mode } - else if (mode != modes.INSERT && mode != modes.TEXTAREA) + else if (liberator.mode != modes.INSERT && liberator.mode != modes.TEXTAREA) { - beep(); + liberator.beep(); } } } @@ -1505,7 +1507,7 @@ with (liberator) liberator.Events = function () //{{{ if (document.commandDispatcher.focusedWindow == webProgress.DOMWindow) { setTimeout(function () { modes.reset(false); }, - mode == modes.HINTS ? 500 : 0); + liberator.mode == modes.HINTS ? 500 : 0); } } else if (flags & Components.interfaces.nsIWebProgressListener.STATE_STOP) @@ -1558,7 +1560,7 @@ with (liberator) liberator.Events = function () //{{{ if (ssli == 1) statusline.updateUrl("Link: " + link); else if (ssli == 2) - echo("Link: " + link, commandline.DISALLOW_MULTILINE); + liberator.echo("Link: " + link, commandline.DISALLOW_MULTILINE); } if (link == "") @@ -1605,7 +1607,7 @@ with (liberator) liberator.Events = function () //{{{ { case "accessibility.browsewithcaret": var value = options.getPref("accessibility.browsewithcaret", false); - liberator.mode = value ? liberator.modes.CARET : liberator.modes.NORMAL; + liberator.mode = value ? modes.CARET : modes.NORMAL; break; } } @@ -1626,7 +1628,7 @@ with (liberator) liberator.Events = function () //{{{ catch (e) {} eventManager.prefObserver.register(); - registerObserver("shutdown", function () { + liberator.registerObserver("shutdown", function () { eventManager.destroy(); eventManager.prefObserver.unregister(); }); diff --git a/content/find.js b/content/find.js index 9bb6a751..7461f298 100644 --- a/content/find.js +++ b/content/find.js @@ -37,7 +37,7 @@ the terms of any one of the MPL, the GPL or the LGPL. // : incremental searches shouldn't permanently update search modifiers // make sure you only create this object when the "liberator" object is ready -with (liberator) liberator.Search = function () //{{{ +function Search() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -56,13 +56,13 @@ with (liberator) liberator.Search = function () //{{{ var linksOnly = false; // search is limited to link text only // Event handlers for search - closure is needed - registerCallback("change", modes.SEARCH_FORWARD, function (command) { search.searchKeyPressed(command); }); - registerCallback("submit", modes.SEARCH_FORWARD, function (command) { search.searchSubmitted(command); }); - registerCallback("cancel", modes.SEARCH_FORWARD, function () { search.searchCanceled(); }); + liberator.registerCallback("change", modes.SEARCH_FORWARD, function (command) { search.searchKeyPressed(command); }); + liberator.registerCallback("submit", modes.SEARCH_FORWARD, function (command) { search.searchSubmitted(command); }); + liberator.registerCallback("cancel", modes.SEARCH_FORWARD, function () { search.searchCanceled(); }); // TODO: allow advanced myModes in register/triggerCallback - registerCallback("change", modes.SEARCH_BACKWARD, function (command) { search.searchKeyPressed(command); }); - registerCallback("submit", modes.SEARCH_BACKWARD, function (command) { search.searchSubmitted(command); }); - registerCallback("cancel", modes.SEARCH_BACKWARD, function () { search.searchCanceled(); }); + liberator.registerCallback("change", modes.SEARCH_BACKWARD, function (command) { search.searchKeyPressed(command); }); + liberator.registerCallback("submit", modes.SEARCH_BACKWARD, function (command) { search.searchSubmitted(command); }); + liberator.registerCallback("cancel", modes.SEARCH_BACKWARD, function () { search.searchCanceled(); }); // set searchString, searchPattern, caseSensitive, linksOnly function processUserPattern(pattern) @@ -204,8 +204,8 @@ with (liberator) liberator.Search = function () //{{{ this.startPt.setStart(node, node.childNodes.length); this.startPt.setEnd(node, node.childNodes.length); if (n++ % 20 == 0) - threadYield(); - if (interrupted) + liberator.threadYield(); + if (liberator.interrupted) break; } }, @@ -343,7 +343,7 @@ with (liberator) liberator.Search = function () //{{{ found = fastFind.find(searchString, linksOnly) != Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND; if (!found) - setTimeout(function () { echoerr("E486: Pattern not found: " + searchPattern); }, 0); + setTimeout(function () { liberator.echoerr("E486: Pattern not found: " + searchPattern); }, 0); return found; }, @@ -362,7 +362,7 @@ with (liberator) liberator.Search = function () //{{{ if (result == Components.interfaces.nsITypeAheadFind.FIND_NOTFOUND) { - echoerr("E486: Pattern not found: " + lastSearchPattern); + liberator.echoerr("E486: Pattern not found: " + lastSearchPattern); } else if (result == Components.interfaces.nsITypeAheadFind.FIND_WRAPPED) { @@ -379,7 +379,7 @@ with (liberator) liberator.Search = function () //{{{ } else { - echo((up ? "?" : "/") + lastSearchPattern, null, commandline.FORCE_SINGLELINE); + liberator.echo((up ? "?" : "/") + lastSearchPattern, null, commandline.FORCE_SINGLELINE); if (options["hlsearch"]) this.highlight(lastSearchString); diff --git a/content/hints.js b/content/hints.js index de64a4de..5dc03317 100644 --- a/content/hints.js +++ b/content/hints.js @@ -26,7 +26,7 @@ the provisions above, a recipient may use your version of this file under the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ -with (liberator) liberator.Hints = function () //{{{ +function Hints() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -303,7 +303,7 @@ with (liberator) liberator.Hints = function () //{{{ { if (validHints.length == 0) { - beep(); + liberator.beep(); return false; } @@ -329,19 +329,19 @@ with (liberator) liberator.Hints = function () //{{{ case "?": buffer.showElementInfo(elem); break; case "a": buffer.saveLink(elem, false); break; case "s": buffer.saveLink(elem, true); break; - case "o": buffer.followLink(elem, CURRENT_TAB); break; + case "o": buffer.followLink(elem, liberator.CURRENT_TAB); break; case "O": commandline.open(":", "open " + loc, modes.EX); break; - case "t": buffer.followLink(elem, NEW_TAB); break; - case "b": buffer.followLink(elem, NEW_BACKGROUND_TAB); break; + case "t": buffer.followLink(elem, liberator.NEW_TAB); break; + case "b": buffer.followLink(elem, liberator.NEW_BACKGROUND_TAB); break; case "T": commandline.open(":", "tabopen " + loc, modes.EX); break; case "v": buffer.viewSource(loc, false); break; case "V": buffer.viewSource(loc, true); break; - case "w": buffer.followLink(elem, NEW_WINDOW); break; + case "w": buffer.followLink(elem, liberator.NEW_WINDOW); break; case "W": commandline.open(":", "winopen " + loc, modes.EX); break; case "y": setTimeout(function () { util.copyToClipboard(loc, true); }, timeout + 50); break; case "Y": setTimeout(function () { util.copyToClipboard(elem.textContent || "", true); }, timeout + 50); break; default: - echoerr("INTERNAL ERROR: unknown submode: " + submode); + liberator.echoerr("INTERNAL ERROR: unknown submode: " + submode); } removeHints(timeout); @@ -360,14 +360,14 @@ with (liberator) liberator.Hints = function () //{{{ { // force a possible mode change, based on wheter an input field has focus events.onFocusChange(); - if (mode == modes.HINTS) + if (liberator.mode == modes.HINTS) modes.reset(false); } else { modes.add(modes.INACTIVE_HINT); setTimeout(function () { - if (mode == modes.HINTS) + if (liberator.mode == modes.HINTS) modes.pop(); }, timeout); } @@ -536,7 +536,7 @@ with (liberator) liberator.Hints = function () //{{{ case "wordstartswith": return wordStartsWithMatcher(hintString, /*allowWordOverleaping=*/ true); case "firstletters" : return wordStartsWithMatcher(hintString, /*allowWordOverleaping=*/ false); case "custom" : return plugins.customHintMatcher(hintString); - default : echoerr("Invalid hintmatching type: " + hintMatching); + default : liberator.echoerr("Invalid hintmatching type: " + hintMatching); } return null; } //}}} @@ -629,7 +629,7 @@ with (liberator) liberator.Hints = function () //{{{ { if (mode == modes.EXTENDED_HINT && !/^[;?asoOtbTvVwWyY]$/.test(minor)) { - beep(); + liberator.beep(); return; } @@ -642,14 +642,14 @@ with (liberator) liberator.Hints = function () //{{{ generate(win); // get all keys from the input queue - threadYield(true); + liberator.threadYield(true); canUpdate = true; showHints(); if (validHints.length == 0) { - beep(); + liberator.beep(); modes.reset(); return false; } @@ -725,7 +725,7 @@ with (liberator) liberator.Hints = function () //{{{ { usedTabKey = false; hintNumber = 0; - beep(); + liberator.beep(); return; } break; @@ -756,7 +756,7 @@ with (liberator) liberator.Hints = function () //{{{ return; } - beep(); + liberator.beep(); return; } @@ -785,7 +785,7 @@ with (liberator) liberator.Hints = function () //{{{ if (hintNumber == 0 || hintNumber > validHints.length) { - beep(); + liberator.beep(); return; } diff --git a/content/io.js b/content/io.js index 9554d4f9..cff079e0 100644 --- a/content/io.js +++ b/content/io.js @@ -28,7 +28,7 @@ the terms of any one of the MPL, the GPL or the LGPL. }}} ***** END LICENSE BLOCK *****/ // TODO: why are we passing around strings rather than file objects? -with (liberator) liberator.IO = function () //{{{ +function IO() //{{{ { //////////////////////////////////////////////////////////////////////////////// ////////////////////// PRIVATE SECTION ///////////////////////////////////////// @@ -128,7 +128,7 @@ with (liberator) liberator.IO = function () //{{{ } else { - echoerr("E186: No previous directory"); + liberator.echoerr("E186: No previous directory"); return; } } @@ -141,7 +141,7 @@ with (liberator) liberator.IO = function () //{{{ { // TODO: apparently we don't handle ../ or ./ paths yet if (io.setCurrentDirectory(args)) - echo(io.getCurrentDirectory()); + liberator.echo(io.getCurrentDirectory()); } else { @@ -161,7 +161,7 @@ with (liberator) liberator.IO = function () //{{{ { // FIXME: we're just overwriting the error message from // setCurrentDirectory here - echo(io.getCurrentDirectory()); + liberator.echo(io.getCurrentDirectory()); directoryFound = true; break; } @@ -169,7 +169,7 @@ with (liberator) liberator.IO = function () //{{{ if (!directoryFound) { - echoerr("E344: Can't find directory \"" + args + "\" in cdpath" + liberator.echoerr("E344: Can't find directory \"" + args + "\" in cdpath" + "\n" + "E472: Command failed"); } @@ -180,12 +180,12 @@ with (liberator) liberator.IO = function () //{{{ // NOTE: this command is only used in :source commands.add(["fini[sh]"], "Stop sourcing a script file", - function () { echoerr("E168: :finish used outside of a sourced file"); }, + function () { liberator.echoerr("E168: :finish used outside of a sourced file"); }, { argCount: "0" }); commands.add(["pw[d]"], "Print the current directory name", - function () { echo(io.getCurrentDirectory()); }, + function () { liberator.echo(io.getCurrentDirectory()); }, { argCount: "0" }); // "mkv[imperatorrc]" or "mkm[uttatorrc]" @@ -203,11 +203,11 @@ with (liberator) liberator.IO = function () //{{{ var file = io.getFile(filename); if (file.exists() && !special) { - echoerr("E189: \"" + filename + "\" exists (add ! to override)"); + liberator.echoerr("E189: \"" + filename + "\" exists (add ! to override)"); return; } - var line = "\" " + version + "\n"; + var line = "\" " + liberator.version + "\n"; line += "\" Mappings\n"; [[[modes.NORMAL], ""], @@ -254,8 +254,8 @@ with (liberator) liberator.IO = function () //{{{ } catch (e) { - echoerr("E190: Cannot open \"" + filename + "\" for writing"); - log("Could not write to " + file.path + ": " + e.message); // XXX + liberator.echoerr("E190: Cannot open \"" + filename + "\" for writing"); + liberator.log("Could not write to " + file.path + ": " + e.message); // XXX } }, { @@ -275,7 +275,7 @@ with (liberator) liberator.IO = function () //{{{ let found = false; // FIXME: should use original arg string - echomsg("Searching for \"" + paths.join(" ") + "\" in \"" + options["runtimepath"] + "\"", 2); + liberator.echomsg("Searching for \"" + paths.join(" ") + "\" in \"" + options["runtimepath"] + "\"", 2); outer: for (let [,runtimeDir] in Iterator(runtimeDirs)) @@ -284,7 +284,7 @@ with (liberator) liberator.IO = function () //{{{ { let file = io.getFile(joinPaths(runtimeDir, path)); - echomsg("Searching for \"" + file.path + "\" in \"", 3); + liberator.echomsg("Searching for \"" + file.path + "\" in \"", 3); if (file.exists() && file.isReadable() && !file.isDirectory()) // XXX { @@ -298,7 +298,7 @@ with (liberator) liberator.IO = function () //{{{ } if (!found) - echomsg("not found in 'runtimepath': \"" + paths.join(" ") + "\"", 1); // FIXME: should use original arg string + liberator.echomsg("not found in 'runtimepath': \"" + paths.join(" ") + "\"", 1); // FIXME: should use original arg string }, { argCount: "+", @@ -324,7 +324,7 @@ with (liberator) liberator.IO = function () //{{{ // FIXME: implement proper filename quoting - "E172: Only one file name allowed" if (!args) { - echoerr("E471: Argument required"); + liberator.echoerr("E471: Argument required"); return; } @@ -351,7 +351,7 @@ with (liberator) liberator.IO = function () //{{{ var output = io.system(args); var command = ":" + util.escapeHTML(commandline.getCommand()) + "
"; - echo(command + util.escapeHTML(output)); + liberator.echo(command + util.escapeHTML(output)); autocommands.trigger("ShellCmdPost", {}); }, @@ -372,6 +372,8 @@ with (liberator) liberator.IO = function () //{{{ MODE_SYNC: 0x40, MODE_EXCL: 0x80, + sourcing: null, + expandPath: function (path) { // TODO: proper pathname separator translation like Vim - this should be done elsewhere @@ -439,7 +441,7 @@ with (liberator) liberator.IO = function () //{{{ if (!dir.exists() || !dir.isDirectory()) { - echoerr("E344: Can't find directory \"" + dir.path + "\" in path"); + liberator.echoerr("E344: Can't find directory \"" + dir.path + "\" in path"); return null; } @@ -670,7 +672,7 @@ lookup: if (!file.exists()) { - echoerr("Command not found: " + program); + liberator.echoerr("Command not found: " + program); return -1; } @@ -687,7 +689,7 @@ lookup: // is fixed, should use that instead of a tmpfile system: function (command, input) { - echomsg("Calling shell to execute: " + command, 4); + liberator.echomsg("Calling shell to execute: " + command, 4); var stdoutFile = ioManager.createTempFile(); var stderrFile = ioManager.createTempFile(); @@ -740,23 +742,27 @@ lookup: try { var file = ioManager.getFile(filename); + this.sourcing = { + file: file.path, + line: 0 + }; if (!file.exists() || !file.isReadable() || file.isDirectory()) { if (!silent) { if (file.exists() && file.isDirectory()) - echomsg("Cannot source a directory: \"" + filename + "\"", 0); + liberator.echomsg("Cannot source a directory: \"" + filename + "\"", 0); else - echomsg("could not source: \"" + filename + "\"", 1); + liberator.echomsg("could not source: \"" + filename + "\"", 1); - echoerr("E484: Can't open file " + filename); + liberator.echoerr("E484: Can't open file " + filename); } return; } - echomsg("sourcing \"" + filename + "\"", 2); + liberator.echomsg("sourcing \"" + filename + "\"", 2); let str = ioManager.readFile(file); let uri = util.createURI(file.path); @@ -803,6 +809,7 @@ lookup: } else { + this.sourcing.line = i + 1; // skip line comments and blank lines if (/^\s*(".*)?$/.test(line)) continue; @@ -817,11 +824,11 @@ lookup: // FIXME: messages need to be able to specify // whether they can be cleared/overwritten or // should be appended to and the MOW opened - echoerr("Error detected while processing " + file.path, + liberator.echoerr("Error detected while processing " + file.path, commandline.FORCE_MULTILINE); commandline.echo("line " + lineNumber + ":", commandline.HL_LINENR, commandline.APPEND_TO_MESSAGES); - echoerr("E492: Not an editor command: " + line); + liberator.echoerr("E492: Not an editor command: " + line); } else { @@ -849,7 +856,7 @@ lookup: else { // execute a normal liberator command - execute(line); + liberator.execute(line); } } } @@ -857,15 +864,16 @@ lookup: // if no heredoc-end delimiter is found before EOF then // process the heredoc anyway - Vim compatible ;-) - eval(heredoc); + if (heredocEnd) + command.execute(heredoc, special, count); } if (scriptNames.indexOf(file.path) == -1) scriptNames.push(file.path); - echomsg("finished sourcing \"" + filename + "\"", 2); + liberator.echomsg("finished sourcing \"" + filename + "\"", 2); - log("Sourced: " + file.path, 3); + liberator.log("Sourced: " + file.path, 3); } catch (e) { @@ -873,7 +881,11 @@ lookup: if (Components.utils.reportError) Components.utils.reportError(e); if (!silent) - echoerr(message); + liberator.echoerr(message); + } + finally + { + this.sourcing = null; } } }; //}}} diff --git a/content/liberator-overlay.js b/content/liberator-overlay.js new file mode 100644 index 00000000..bf98b1eb --- /dev/null +++ b/content/liberator-overlay.js @@ -0,0 +1,45 @@ + +(function () { + const modules = {}; + const BASE = "chrome://liberator/content/"; + + modules.modules = modules; + + var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Components.interfaces.mozIJSSubScriptLoader); + function load(script) { + try + { + dump("liberator: Loading script: " + script + "\n"); + loader.loadSubScript(BASE + script, modules) + } + catch (e) + { + if (Components.utils.reportError) + Components.utils.reportError(e); + dump("liberator: Loading script " + script + ": " + e + "\n"); + } + } + + Components.utils.import("resource://liberator/storage.jsm", modules); + + ["liberator.js", + "config.js", + "buffer.js", + "commands.js", + "completion.js", + "editor.js", + "events.js", + "find.js", + "hints.js", + "io.js", + "mappings.js", + "modes.js", + "options.js", + "template.js", + "ui.js", + "util.js"].forEach(load); + modules.config.scripts.forEach(load); + +})() + diff --git a/content/liberator.js b/content/liberator.js index 7e3c594d..1b02145b 100644 --- a/content/liberator.js +++ b/content/liberator.js @@ -45,7 +45,7 @@ const liberator = (function () //{{{ { liberator.log(message, 0); liberator.dump(message); - liberator[name] = func(); + modules[name] = func(); } catch (e) { @@ -59,17 +59,17 @@ const liberator = (function () //{{{ // Only general options are added here, which are valid for all vimperator like extensions function addOptions() { - const tabopts = [ - ["n", "Tab number", null, ".hl-TabNumber"], - ["N", "Tab number over icon", null, ".hl-TabIconNumber"], - ]; - liberator.options.add(["guioptions", "go"], + const tabopts = [ + ["n", "Tab number", null, ".hl-TabNumber"], + ["N", "Tab number over icon", null, ".hl-TabIconNumber"], + ]; + options.add(["guioptions", "go"], "Show or hide certain GUI elements like the menu or toolbar", - "charlist", liberator.config.defaults.guioptions || "", + "charlist", config.defaults.guioptions || "", { setter: function (value) { - var guioptions = liberator.config.guioptions || {}; + var guioptions = config.guioptions || {}; for (let option in guioptions) { @@ -87,9 +87,9 @@ const liberator = (function () //{{{ let classes = tabopts.filter(function (o) value.indexOf(o[0]) == -1) .map(function (a) a[3]) if (!classes.length) - liberator.storage.styles.removeSheet("taboptions", null, null, null, true); + storage.styles.removeSheet("taboptions", null, null, null, true); else - liberator.storage.styles.addSheet("taboptions", "chrome://*", classes.join(",") + "{ display: none; }", true, true); + storage.styles.addSheet("taboptions", "chrome://*", classes.join(",") + "{ display: none; }", true, true); return value; }, @@ -101,29 +101,29 @@ const liberator = (function () //{{{ ["b", "Bookmark bar"] ].concat(!liberator.has("tabs") ? [] : tabopts); }, - validator: function (value) Array.every(value, function (c) c in liberator.config.guioptions || tabopts.some(function (a) a[0] == c)), + validator: function (value) Array.every(value, function (c) c in config.guioptions || tabopts.some(function (a) a[0] == c)), }); - liberator.options.add(["helpfile", "hf"], + options.add(["helpfile", "hf"], "Name of the main help file", "string", "intro.html"); - liberator.options.add(["loadplugins", "lpl"], + options.add(["loadplugins", "lpl"], "Load plugin scripts when starting up", "boolean", true); - liberator.options.add(["verbose", "vbs"], + options.add(["verbose", "vbs"], "Define which info messages are displayed", "number", 0, { validator: function (value) value >= 0 && value <= 15 }); - liberator.options.add(["visualbell", "vb"], + options.add(["visualbell", "vb"], "Use visual bell instead of beeping on errors", "boolean", false, { setter: function (value) { - liberator.options.setPref("accessibility.typeaheadfind.enablesound", !value); + options.setPref("accessibility.typeaheadfind.enablesound", !value); return value; } }); @@ -131,48 +131,48 @@ const liberator = (function () //{{{ function addMappings() { - liberator.mappings.add(liberator.modes.all, [""], + mappings.add(modes.all, [""], "Open help window", function () { liberator.help(); }); if (liberator.has("session")) { - liberator.mappings.add([liberator.modes.NORMAL], ["ZQ"], + mappings.add([modes.NORMAL], ["ZQ"], "Quit and don't save the session", function () { liberator.quit(false); }); } - liberator.mappings.add([liberator.modes.NORMAL], ["ZZ"], + mappings.add([modes.NORMAL], ["ZZ"], "Quit and save the session", function () { liberator.quit(true); }); } function addCommands() { - liberator.commands.add(["addo[ns]"], + commands.add(["addo[ns]"], "Manage available Extensions and Themes", function () { liberator.open("chrome://mozapps/content/extensions/extensions.xul", - (liberator.options["newtab"] && liberator.options.get("newtab").has("all", "addons")) + (options["newtab"] && options.get("newtab").has("all", "addons")) ? liberator.NEW_TAB: liberator.CURRENT_TAB); }, { argCount: "0" }); - liberator.commands.add(["beep"], + commands.add(["beep"], "Play a system beep", function () { liberator.beep(); }, { argCount: "0" }); - liberator.commands.add(["dia[log]"], - "Open a " + liberator.config.name + " dialog", + commands.add(["dia[log]"], + "Open a " + config.name + " dialog", function (args) { args = args.arguments[0]; try { - var dialogs = liberator.config.dialogs || []; + var dialogs = config.dialogs || []; for (let i = 0; i < dialogs.length; i++) { if (dialogs[i][0] == args) @@ -188,13 +188,13 @@ const liberator = (function () //{{{ { argCount: "1", bang: true, - completer: function (filter) liberator.completion.dialog(filter) + completer: function (filter) completion.dialog(filter) }); // TODO: move this function getMenuItems() { - var menubar = document.getElementById(liberator.config.guioptions["m"]); + var menubar = document.getElementById(config.guioptions["m"]); var items = []; for (let i = 0; i < menubar.childNodes.length; i++) @@ -221,7 +221,7 @@ const liberator = (function () //{{{ return items; } - liberator.commands.add(["em[enu]"], + commands.add(["em[enu]"], "Execute the specified menu item from the command line", function (args) { @@ -246,11 +246,11 @@ const liberator = (function () //{{{ completer: function (filter) { let completions = getMenuItems().map(function (item) [item.fullMenuPath, item.label]); - return [0, liberator.completion.filter(completions, filter)]; + return [0, completion.filter(completions, filter)]; } }); - liberator.commands.add(["exe[cute]"], + commands.add(["exe[cute]"], "Execute the argument as an Ex command", // FIXME: this should evaluate each arg separately then join // with " " before executing. @@ -271,7 +271,7 @@ const liberator = (function () //{{{ } }); - liberator.commands.add(["exu[sage]"], + commands.add(["exu[sage]"], "List all Ex commands with a short description", function (args, special) { @@ -282,8 +282,8 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = liberator.template.usage(liberator.commands); - liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); + var usage = template.usage(commands); + liberator.echo(usage, commandline.FORCE_MULTILINE); } }, { @@ -291,7 +291,7 @@ const liberator = (function () //{{{ bang: true }); - liberator.commands.add(["h[elp]"], + commands.add(["h[elp]"], "Display help", function (args, special) { @@ -305,17 +305,17 @@ const liberator = (function () //{{{ }, { bang: true, - completer: function (filter) liberator.completion.help(filter) + completer: function (filter) completion.help(filter) }); - liberator.commands.add(["javas[cript]", "js"], + commands.add(["javas[cript]", "js"], "Run a JavaScript command through eval()", function (args, special) { if (special) // open javascript console { liberator.open("chrome://global/content/console.xul", - (liberator.options["newtab"] && liberator.options.get("newtab").has("all", "javascript")) + (options["newtab"] && options.get("newtab").has("all", "javascript")) ? liberator.NEW_TAB : liberator.CURRENT_TAB); } else @@ -332,23 +332,23 @@ const liberator = (function () //{{{ }, { bang: true, - completer: function (filter) liberator.completion.javascript(filter), + completer: function (filter) completion.javascript(filter), hereDoc: true, }); - liberator.commands.add(["loadplugins", "lpl"], + commands.add(["loadplugins", "lpl"], "Load all plugins immediately", function () { liberator.loadPlugins(); }); - liberator.commands.add(["norm[al]"], + commands.add(["norm[al]"], "Execute Normal mode commands", - function (args, special) { liberator.events.feedkeys(args.string, special); }, + function (args, special) { events.feedkeys(args.string, special); }, { argCount: "+", bang: true }); - liberator.commands.add(["optionu[sage]"], + commands.add(["optionu[sage]"], "List all options with a short description", function (args, special) { @@ -359,8 +359,8 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = liberator.template.usage(liberator.options); - liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); + var usage = template.usage(options); + liberator.echo(usage, commandline.FORCE_MULTILINE); } }, { @@ -368,12 +368,12 @@ const liberator = (function () //{{{ bang: true }); - liberator.commands.add(["q[uit]"], + commands.add(["q[uit]"], liberator.has("tabs") ? "Quit current tab" : "Quit application", function (args, special) { if (liberator.has("tabs")) - liberator.tabs.remove(getBrowser().mCurrentTab, 1, false, 1); + tabs.remove(getBrowser().mCurrentTab, 1, false, 1); else liberator.quit(false, special); }, @@ -382,12 +382,12 @@ const liberator = (function () //{{{ bang: true }); - liberator.commands.add(["res[tart]"], - "Force " + liberator.config.name + " to restart", + commands.add(["res[tart]"], + "Force " + config.name + " to restart", function () { liberator.restart(); }, { argCount: "0" }); - liberator.commands.add(["time"], + commands.add(["time"], "Profile a piece of code or run a command multiple times", function (args, special, count) { @@ -401,7 +401,7 @@ const liberator = (function () //{{{ let each, eachUnits, totalUnits; let total = 0; - for (let i in liberator.util.rangeInterruptable(0, count, 500)) + for (let i in util.rangeInterruptable(0, count, 500)) { let now = Date.now(); liberator[method](args); @@ -432,16 +432,16 @@ const liberator = (function () //{{{ totalUnits = "msec"; } - var str = liberator.template.generic( + var str = template.generic( - - - + + +
Code execution summary
  Executed:{count}times
  Average time:{each.toFixed(2)}{eachUnits}
  Total time:{total.toFixed(2)}{totalUnits}
\u00a0\u00a0Executed:{count}times
\u00a0\u00a0Average time:{each.toFixed(2)}{eachUnits}
\u00a0\u00a0Total time:{total.toFixed(2)}{totalUnits}
); - liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, liberator.commandline.FORCE_MULTILINE); + commandline.echo(str, commandline.HL_NORMAL, commandline.FORCE_MULTILINE); } else { @@ -473,22 +473,22 @@ const liberator = (function () //{{{ completer: function (filter) { if (/^:/.test(filter)) - return liberator.completion.ex(filter); + return completion.ex(filter); else - return liberator.completion.javascript(filter); + return completion.javascript(filter); }, count: true }); - liberator.commands.add(["ve[rsion]"], + commands.add(["ve[rsion]"], "Show version information", function (args, special) { if (special) liberator.open("about:"); else - liberator.echo(":" + liberator.util.escapeHTML(liberator.commandline.getCommand()) + "\n" + - liberator.config.name + " " + liberator.version + + liberator.echo(":" + util.escapeHTML(commandline.getCommand()) + "\n" + + config.name + " " + liberator.version + " running on:\n" + navigator.userAgent); }, { @@ -496,7 +496,7 @@ const liberator = (function () //{{{ bang: true }); - liberator.commands.add(["viu[sage]"], + commands.add(["viu[sage]"], "List all mappings with a short description", function (args, special) { @@ -507,8 +507,8 @@ const liberator = (function () //{{{ else { // TODO: clicking on these should open the help - var usage = liberator.template.usage(liberator.mappings); - liberator.echo(usage, liberator.commandline.FORCE_MULTILINE); + var usage = template.usage(mappings); + liberator.echo(usage, commandline.FORCE_MULTILINE); } }, { @@ -521,7 +521,7 @@ const liberator = (function () //{{{ // similar in his config function hideGUI() { - var guioptions = liberator.config.guioptions || {}; + var guioptions = config.guioptions || {}; for (let option in guioptions) { guioptions[option].forEach(function (elem) { @@ -540,8 +540,10 @@ const liberator = (function () //{{{ return { - get mode() liberator.modes.main, - set mode(value) liberator.modes.main = value, + modules: modules, + + get mode() modes.main, + set mode(value) modes.main = value, // Global constants CURRENT_TAB: 1, @@ -603,11 +605,11 @@ const liberator = (function () //{{{ beep: function () { - if (liberator.options["visualbell"]) + if (options["visualbell"]) { // flash the visual bell let popup = document.getElementById("liberator-visualbell"); - let win = liberator.config.visualbellWindow; + let win = config.visualbellWindow; let box = document.getBoxObjectFor(win); popup.openPopup(win, "overlap", 0, 0, false, false); @@ -627,10 +629,10 @@ const liberator = (function () //{{{ dump: function (message) { if (typeof message == "object") - message = liberator.util.objectToString(message); + message = util.objectToString(message); else message += "\n"; - dump(liberator.config.name.toLowerCase() + ": " + message); + dump(config.name.toLowerCase() + ": " + message); }, dumpStack: function (msg) @@ -654,6 +656,12 @@ const liberator = (function () //{{{ e.source = str; e.fileName = ""; e.lineNumber -= line; + if (modules.io && io.sourcing) + { + liberator.dump(io.sourcing); + e.fileName = io.sourcing.file; + e.lineNumber += io.sourcing.line; + } } throw e; } @@ -669,12 +677,12 @@ const liberator = (function () //{{{ modifiers = modifiers || {}; let err = null; - let [count, cmd, special, args] = liberator.commands.parseCommand(str.replace(/^'(.*)'$/, "$1")); - let command = liberator.commands.get(cmd); + let [count, cmd, special, args] = commands.parseCommand(str.replace(/^'(.*)'$/, "$1")); + let command = commands.get(cmd); if (command === null) { - err = "E492: Not a " + liberator.config.name.toLowerCase() + " command: " + str; + err = "E492: Not a " + config.name.toLowerCase() + " command: " + str; liberator.focusContent(); } else if (command.action === null) @@ -696,7 +704,7 @@ const liberator = (function () //{{{ liberator.echoerr(err); }, - // TODO: move to liberator.buffer.focus()? + // TODO: move to buffer.focus()? // after pressing Escape, put focus on a non-input field of the browser document // if clearFocusedElement, also blur a focused link focusContent: function (clearFocusedElement) @@ -709,7 +717,7 @@ const liberator = (function () //{{{ // TODO: make more generic try { - if (liberator.has("mail") && clearFocusedElement && !liberator.config.isComposeWindow) + if (liberator.has("mail") && clearFocusedElement && !config.isComposeWindow) { var i = gDBView.selection.currentIndex; if (i == -1 && gDBView.rowCount >= 0) @@ -720,7 +728,7 @@ const liberator = (function () //{{{ } catch (e) {} - var elem = liberator.config.mainWidget || window.content; + var elem = config.mainWidget || window.content; if (elem && (elem != document.commandDispatcher.focusedElement)) elem.focus(); }, @@ -803,51 +811,51 @@ const liberator = (function () //{{{ echo: function (str, flags) { - liberator.commandline.echo(str, liberator.commandline.HL_NORMAL, flags); + commandline.echo(str, commandline.HL_NORMAL, flags); }, // TODO: Vim replaces unprintable characters in echoerr/echomsg echoerr: function (str, flags) { - flags |= liberator.commandline.APPEND_TO_MESSAGES; + flags |= commandline.APPEND_TO_MESSAGES; if (typeof str == "object" && "echoerr" in str) str = str.echoerr; else if (str instanceof Error) str = str.fileName + ":" + str.lineNumber + ": " + str; - liberator.commandline.echo(str, liberator.commandline.HL_ERRORMSG, flags); + commandline.echo(str, commandline.HL_ERRORMSG, flags); }, // TODO: add proper level constants echomsg: function (str, verbosity, flags) { - flags |= liberator.commandline.APPEND_TO_MESSAGES; + flags |= commandline.APPEND_TO_MESSAGES; if (verbosity == null) verbosity = 0; // verbosity level is exclusionary - if (liberator.options["verbose"] >= verbosity) - liberator.commandline.echo(str, liberator.commandline.HL_INFOMSG, flags); + if (options["verbose"] >= verbosity) + commandline.echo(str, commandline.HL_INFOMSG, flags); }, // return true, if this VIM-like extension has a certain feature has: function (feature) { - var features = liberator.config.features || []; + var features = config.features || []; return features.some(function (feat) feat == feature); }, help: function (topic) { - var where = (liberator.options["newtab"] && liberator.options.get("newtab").has("all", "help")) + var where = (options["newtab"] && options.get("newtab").has("all", "help")) ? liberator.NEW_TAB : liberator.CURRENT_TAB; if (!topic) { - var helpFile = liberator.options["helpfile"]; + var helpFile = options["helpfile"]; - if (liberator.config.helpFiles.indexOf(helpFile) != -1) + if (config.helpFiles.indexOf(helpFile) != -1) liberator.open("chrome://liberator/locale/" + helpFile, where); else liberator.echo("Sorry, help file \"" + helpFile + "\" not found"); @@ -860,7 +868,7 @@ const liberator = (function () //{{{ liberator.open("chrome://liberator/locale/" + file, where); // TODO: it would be better wo wait for pageLoad setTimeout(function () { - var elem = liberator.buffer.getElement('@class="tag" and text()="' + tag + '"'); + var elem = buffer.getElement('@class="tag" and text()="' + tag + '"'); if (elem) window.content.scrollTo(0, elem.getBoundingClientRect().top - 10); // 10px context else @@ -868,7 +876,7 @@ const liberator = (function () //{{{ }, 500); } - var [, items] = liberator.completion.help(topic); + var [, items] = completion.help(topic); var partialMatch = -1; for (let i = 0; i < items.length; i++) @@ -899,7 +907,7 @@ const liberator = (function () //{{{ // FIXME: largely duplicated for loading macros try { - let dirs = liberator.io.getRuntimeDirectories("plugin"); + let dirs = io.getRuntimeDirectories("plugin"); if (dirs.length > 0) { @@ -910,15 +918,15 @@ const liberator = (function () //{{{ liberator.log("Sourcing plugin directory: " + dir.path + "...", 3); - let files = liberator.io.readDirectory(dir.path, true); + let files = io.readDirectory(dir.path, true); files.forEach(function (file) { - if (!file.isDirectory() && /\.(js|vimp)$/i.test(file.path) && !(file.path in liberator.pluginFiles)) + if (!file.isDirectory() && /\.(js|vimp)$/i.test(file.path) && !(file.path in pluginFiles)) { try { - liberator.io.source(file.path, false); - liberator.pluginFiles[file.path] = true; + io.source(file.path, false); + pluginFiles[file.path] = true; } catch (e) {}; } @@ -946,19 +954,19 @@ const liberator = (function () //{{{ if (typeof level != "number") // XXX level = 1; - // liberator.options does not exist at the very beginning - if (liberator.options) - verbose = liberator.options.getPref("extensions.liberator.loglevel", 0); + // options does not exist at the very beginning + if (modules.options) + verbose = options.getPref("extensions.liberator.loglevel", 0); if (level > verbose) return; if (typeof msg == "object") - msg = liberator.util.objectToString(msg, false); + msg = util.objectToString(msg, false); var consoleService = Components.classes["@mozilla.org/consoleservice;1"] .getService(Components.interfaces.nsIConsoleService); - consoleService.logStringMessage(liberator.config.name.toLowerCase() + ": " + msg); + consoleService.logStringMessage(config.name.toLowerCase() + ": " + msg); }, // open one or more URLs @@ -974,13 +982,13 @@ const liberator = (function () //{{{ open: function (urls, where, force) { // convert the string to an array of converted URLs - // -> see liberator.util.stringToURLArray for more details + // -> see util.stringToURLArray for more details if (typeof urls == "string") - urls = liberator.util.stringToURLArray(urls); + urls = util.stringToURLArray(urls); if (urls.length > 20 && !force) { - liberator.commandline.input("This will open " + urls.length + " new tabs. Would you like to continue? (yes/[no])", + commandline.input("This will open " + urls.length + " new tabs. Would you like to continue? (yes/[no])", function (resp) { if (resp && resp.match(/^y(es)?$/i)) liberator.open(urls, where, true); }); return true; } @@ -1053,9 +1061,9 @@ const liberator = (function () //{{{ quit: function (saveSession, force) { if (saveSession) - liberator.options.setPref("browser.startup.page", 3); // start with saved session + options.setPref("browser.startup.page", 3); // start with saved session else - liberator.options.setPref("browser.startup.page", 1); // start with default homepage session + options.setPref("browser.startup.page", 1); // start with default homepage session const nsIAppStartup = Components.interfaces.nsIAppStartup; if (force) @@ -1105,43 +1113,40 @@ const liberator = (function () //{{{ { liberator.log("Initializing liberator object...", 0); - // components which should be shared across all windows - Components.utils.import("resource://liberator/storage.jsm", liberator); - // commands must always be the first module to be initialized - loadModule("commands", liberator.Commands); addCommands(); - loadModule("options", liberator.Options); addOptions(); - loadModule("mappings", liberator.Mappings); addMappings(); - loadModule("buffer", liberator.Buffer); - loadModule("events", liberator.Events); - loadModule("commandline", liberator.CommandLine); - loadModule("statusline", liberator.StatusLine); - loadModule("editor", liberator.Editor); - loadModule("autocommands", liberator.AutoCommands); - loadModule("io", liberator.IO); - loadModule("completion", liberator.Completion); + loadModule("commands", Commands); addCommands(); + loadModule("options", Options); addOptions(); + loadModule("mappings", Mappings); addMappings(); + loadModule("buffer", Buffer); + loadModule("events", Events); + loadModule("commandline", CommandLine); + loadModule("statusline", StatusLine); + loadModule("editor", Editor); + loadModule("autocommands", AutoCommands); + loadModule("io", IO); + loadModule("completion", Completion); // This adds options/mappings/commands which are only valid in this particular extension - if (liberator.config.init) - liberator.config.init(); + if (config.init) + config.init(); liberator.log("All modules loaded", 3); // TODO: move elsewhere - liberator.registerCallback("submit", liberator.modes.EX, function (command) { liberator.execute(command); }); - liberator.registerCallback("complete", liberator.modes.EX, function (str) { return liberator.completion.ex(str); }); + liberator.registerCallback("submit", modes.EX, function (command) { liberator.execute(command); }); + liberator.registerCallback("complete", modes.EX, function (str) { return completion.ex(str); }); // first time intro message - if (liberator.options.getPref("extensions." + liberator.config.name.toLowerCase() + ".firsttime", true)) + if (options.getPref("extensions." + config.name.toLowerCase() + ".firsttime", true)) { setTimeout(function () { liberator.help(); - liberator.options.setPref("extensions." + liberator.config.name.toLowerCase() + ".firsttime", false); + options.setPref("extensions." + config.name.toLowerCase() + ".firsttime", false); }, 1000); } // always start in normal mode - liberator.modes.reset(); + modes.reset(); // TODO: we should have some class where all this guioptions stuff fits well hideGUI(); @@ -1150,45 +1155,45 @@ const liberator = (function () //{{{ // make sourcing asynchronous, otherwise commands that open new tabs won't work setTimeout(function () { - var rcFile = liberator.io.getRCFile(); + var rcFile = io.getRCFile(); if (rcFile) - liberator.io.source(rcFile.path, true); + io.source(rcFile.path, true); else liberator.log("No user RC file found", 3); - if (liberator.options["loadplugins"]) + if (options["loadplugins"]) liberator.loadPlugins; // after sourcing the initialization files, this function will set // all gui options to their default values, if they have not been // set before by any rc file - for (let option in liberator.options) + for (let option in options) { if (option.setter) option.value = option.value; } liberator.triggerObserver("enter", null); - liberator.autocommands.trigger(liberator.config.name + "Enter", {}); + autocommands.trigger(config.name + "Enter", {}); }, 0); - liberator.statusline.update(); + statusline.update(); - liberator.log(liberator.config.name + " fully initialized", 0); + liberator.log(config.name + " fully initialized", 0); }, shutdown: function () { - liberator.autocommands.trigger(liberator.config.name + "LeavePre", {}); + autocommands.trigger(config.name + "LeavePre", {}); - liberator.storage.saveAll(); + storage.saveAll(); liberator.triggerObserver("shutdown", null); liberator.dump("All liberator modules destroyed\n"); - liberator.autocommands.trigger(liberator.config.name + "Leave", {}); + autocommands.trigger(config.name + "Leave", {}); }, sleep: function (ms) @@ -1255,6 +1260,8 @@ const liberator = (function () //{{{ //}}} })(); //}}} +window.liberator = liberator; + // called when the chrome is fully loaded and before the main window is shown window.addEventListener("load", liberator.startup, false); window.addEventListener("unload", liberator.shutdown, false); diff --git a/content/liberator.xul b/content/liberator.xul index 981c5b0b..8a671d50 100644 --- a/content/liberator.xul +++ b/content/liberator.xul @@ -1,4 +1,4 @@ - + @@ -75,39 +58,39 @@ the terms of any one of the MPL, the GPL or the LGPL. + oncommandupdate="if (typeof liberator.modules.events != 'undefined') liberator.modules.events.onFocusChange(event);"/> + oncommandupdate="if (typeof liberator.modules.events != 'undefined') liberator.modules.events.onSelectionChange(event);"/>