diff --git a/content/bookmarks.js b/content/bookmarks.js index 288809b9..7d1cc2c5 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -143,11 +143,11 @@ function Bookmarks() //{{{ }; var observer = { - onBeginUpdateBatch: function () {}, - onEndUpdateBatch: function () {}, - onItemVisited: function () {}, - onItemMoved: function () {}, - onItemAdded: function (itemId, folder, index) + onBeginUpdateBatch: function onBeginUpdateBatch() {}, + onEndUpdateBatch: function onEndUpdateBatch() {}, + onItemVisited: function onItemVisited() {}, + onItemMoved: function onItemMoved() {}, + onItemAdded: function onItemAdded(itemId, folder, index) { // liberator.dump("onItemAdded(" + itemId + ", " + folder + ", " + index + ")\n"); if (bookmarksService.getItemType(itemId) == bookmarksService.TYPE_BOOKMARK) @@ -159,13 +159,13 @@ function Bookmarks() //{{{ } } }, - onItemRemoved: function (itemId, folder, index) + onItemRemoved: function onItemRemoved(itemId, folder, index) { // liberator.dump("onItemRemoved(" + itemId + ", " + folder + ", " + index + ")\n"); if (deleteBookmark(itemId)) storage.fireEvent(name, "remove", itemId); }, - onItemChanged: function (itemId, property, isAnnotation, value) + onItemChanged: function onItemChanged(itemId, property, isAnnotation, value) { if (isAnnotation) return; @@ -180,7 +180,7 @@ function Bookmarks() //{{{ storage.fireEvent(name, "change", itemId); } }, - QueryInterface: function (iid) + QueryInterface: function QueryInterface(iid) { if (iid.equals(Components.interfaces.nsINavBookmarkObserver) || iid.equals(Components.interfaces.nsISupports)) return this; @@ -233,8 +233,8 @@ function Bookmarks() //{{{ "Set the default search engine", "string", "google", { - completer: function (filter) completion.runCompleter("search", filter, true), - validator: function (value) completion.runCompleter("search", "", true).some(function ([s]) s == value) + completer: function completer(filter) completion.runCompleter("search", filter, true), + validator: function validator(value) completion.runCompleter("search", "", true).some(function ([s]) s == value) }); options.add(["preload"], @@ -320,7 +320,7 @@ function Bookmarks() //{{{ }, { bang: true, - completer: function (context, args) completion.bookmark(context, args["-tags"]), + completer: function completer(context, args) completion.bookmark(context, args["-tags"]), options: [[["-tags", "-T"], commands.OPTION_LIST, null, tags]] }); @@ -334,7 +334,7 @@ function Bookmarks() //{{{ liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE); }, { - completer: function (context) completion.bookmark(context), + completer: function completer(context) completion.bookmark(context), literal: true }); @@ -353,7 +353,7 @@ function Bookmarks() //{{{ // if "bypassCache" is true, it will force a reload of the bookmarks database // on my PC, it takes about 1ms for each bookmark to load, so loading 1000 bookmarks // takes about 1 sec - get: function (filter, tags, bypassCache) + get: function get(filter, tags, bypassCache) { if (bypassCache) // Is this really necessary anymore? cache.load(); @@ -361,7 +361,7 @@ function Bookmarks() //{{{ }, // if starOnly = true it is saved in the unfiledBookmarksFolder, otherwise in the bookmarksMenuFolder - add: function (starOnly, title, url, keyword, tags, force) + add: function add(starOnly, title, url, keyword, tags, force) { try { @@ -400,7 +400,7 @@ function Bookmarks() //{{{ return true; }, - toggle: function (url) + toggle: function toggle(url) { if (!url) return; @@ -421,7 +421,7 @@ function Bookmarks() //{{{ } }, - isBookmarked: function (url) + isBookmarked: function isBookmarked(url) { try { @@ -435,7 +435,7 @@ function Bookmarks() //{{{ }, // returns number of deleted bookmarks - remove: function (url) + remove: function remove(url) { if (!url) return 0; @@ -462,11 +462,11 @@ function Bookmarks() //{{{ return count.value; }, - getFavicon: function (url) { return getFavicon(url); }, + getFavicon: function getFavicon(url) { return getFavicon(url); }, // TODO: add filtering // also ensures that each search engine has a Vimperator-friendly alias - getSearchEngines: function () + getSearchEngines: function getSearchEngines() { var searchEngines = []; var firefoxEngines = searchService.getVisibleEngines({}); @@ -497,7 +497,7 @@ function Bookmarks() //{{{ return searchEngines; }, - getSuggestions: function (engine, query) + getSuggestions: function getSuggestions(engine, query) { let ss = Components.classes["@mozilla.org/browser/search-service;1"] .getService(Components.interfaces.nsIBrowserSearchService); @@ -524,7 +524,7 @@ function Bookmarks() //{{{ // TODO: add filtering // format of returned array: // [keyword, helptext, url] - getKeywords: function () + getKeywords: function getKeywords() { return cache.keywords; }, @@ -533,7 +533,7 @@ function Bookmarks() //{{{ // if @param useDefSearch is true, it uses the default search engine // @returns the url for the search string // if the search also requires a postData, [url, postData] is returned - getSearchURL: function (text, useDefsearch) + getSearchURL: function getSearchURL(text, useDefsearch) { var url = null; var aPostDataRef = {}; @@ -554,7 +554,7 @@ function Bookmarks() //{{{ }, // if openItems is true, open the matching bookmarks items in tabs rather than display - list: function (filter, tags, openItems) + list: function list(filter, tags, openItems) { if (!openItems) return completion.listCompleter("bookmark", filter, tags); @@ -647,7 +647,7 @@ function History() //{{{ }, { bang: true, - completer: function (context) + completer: function completer(context) { let filter = context.filter; var sh = getWebNavigation().sessionHistory; @@ -699,7 +699,7 @@ function History() //{{{ }, { bang: true, - completer: function (context) + completer: function completer(context) { let filter = context.filter; var sh = getWebNavigation().sessionHistory; @@ -736,7 +736,7 @@ function History() //{{{ get service() historyService, - get: function (filter, maxItems) + get: function get(filter, maxItems) { // no query parameters will get all history let query = historyService.getNewQuery(); @@ -768,7 +768,7 @@ function History() //{{{ }, // TODO: better names and move to buffer.? - stepTo: function (steps) + stepTo: function stepTo(steps) { let index = getWebNavigation().sessionHistory.index + steps; if (index >= 0 && index < getWebNavigation().sessionHistory.count) @@ -777,7 +777,7 @@ function History() //{{{ liberator.beep(); }, - goToStart: function () + goToStart: function goToStart() { let index = getWebNavigation().sessionHistory.index; if (index == 0) @@ -786,7 +786,7 @@ function History() //{{{ getWebNavigation().gotoIndex(0); }, - goToEnd: function () + goToEnd: function goToEnd() { let index = getWebNavigation().sessionHistory.index; if (index == getWebNavigation().sessionHistory.count - 1) @@ -796,7 +796,7 @@ function History() //{{{ }, // if openItems is true, open the matching history items in tabs rather than display - list: function (filter, openItems) + list: function list(filter, openItems) { if (!openItems) return completion.listCompleter("history", filter); @@ -922,13 +922,13 @@ function QuickMarks() //{{{ return { - add: function (qmark, location) + add: function add(qmark, location) { qmarks.set(qmark, location); liberator.echo("Added Quick Mark '" + qmark + "': " + location); }, - remove: function (filter) + remove: function remove(filter) { var pattern = new RegExp("[" + filter.replace(/\s+/g, "") + "]"); @@ -939,12 +939,12 @@ function QuickMarks() //{{{ } }, - removeAll: function () + removeAll: function removeAll() { qmarks.clear(); }, - jumpTo: function (qmark, where) + jumpTo: function jumpTo(qmark, where) { var url = qmarks.get(qmark); @@ -954,7 +954,7 @@ function QuickMarks() //{{{ liberator.echoerr("E20: QuickMark not set"); }, - list: function (filter) + list: function list(filter) { var marks = [key for ([key, val] in qmarks)]; // This was a lot nicer without the lambda... diff --git a/content/completion.js b/content/completion.js index ec16cd5a..bd5eaa47 100644 --- a/content/completion.js +++ b/content/completion.js @@ -116,7 +116,8 @@ CompletionContext.prototype = { if (!context.hasItems) return []; let prefix = self.value.substring(minStart, context.offset); - return [{ text: prefix + item.text, item: item.item } for ([i, item] in Iterator(context.items))]; + return context.items.map(function makeItem(item) ({ text: prefix + item.text, item: item.item })); + //return [{ text: prefix + item.text, item: item.item } for ([i, item] in Iterator(context.items))]; }); return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring } }, @@ -329,7 +330,7 @@ CompletionContext.prototype = { this._filter = this._filter.substr(count); }, - getItems: function (start, end) + getItems: function getItems(start, end) { let self = this; let items = this.items; @@ -339,7 +340,7 @@ CompletionContext.prototype = { return util.map(util.range(start, end, reverse), function (i) items[i]); }, - getRows: function (start, end, doc) + getRows: function getRows(start, end, doc) { let self = this; let items = this.items; @@ -362,7 +363,7 @@ CompletionContext.prototype = { return context; }, - getText: function (item) + getText: function getText(item) { let text = item[self.keys["text"]]; if (self.quote) @@ -392,7 +393,7 @@ CompletionContext.prototype = { catch (e) {} }, - match: function (str) + match: function match(str) { let filter = this.filter; if (this.ignoreCase) @@ -955,7 +956,7 @@ function Completion() //{{{ }, // FIXME - _runCompleter: function (name, filter) + _runCompleter: function _runCompleter(name, filter) { let context = CompletionContext(filter); if (typeof name == "string") @@ -966,7 +967,7 @@ function Completion() //{{{ return context.allItems; }, - runCompleter: function (name, filter) + runCompleter: function runCompleter(name, filter) { return this._runCompleter(name, filter).items.map(function (i) i.item); }, @@ -1059,7 +1060,7 @@ function Completion() //{{{ return filter.split(/\s+/).every(function strIndex(str) itemsStr.indexOf(str) > -1); }, - listCompleter: function (name, filter) + listCompleter: function listCompleter(name, filter) { let context = CompletionContext(filter || ""); context.fork.apply(context, ["list", 0, completion, name].concat(Array.slice(arguments, 2))); @@ -1230,13 +1231,13 @@ function Completion() //{{{ context.keys = { text: 0, description: 1, icon: 2 }; context.anchored = true; context.key = dir; - context.generate = function generate() + context.generate = function generate_file() { context.cache.dir = dir; try { - let files = io.readDirectory(dir, true); + let files = io.readDirectory(dir); if (options["wildignore"]) { @@ -1273,7 +1274,7 @@ function Completion() //{{{ } }, - history: function (context) + history: function history(context) { context.format = history.format; context.title = ["History"] @@ -1287,7 +1288,7 @@ function Completion() //{{{ javascript: function _javascript(context) javascript.complete(context), - location: function (context) + location: function location(context) { if (!completionService) return @@ -1303,7 +1304,6 @@ function Completion() //{{{ for (i in util.range(0, result.matchCount)) ]; context.incomplete = result.searchResult >= result.RESULT_NOMATCH_ONGOING; - let filter = context.filter; }); completionService.stopSearch(); completionService.startSearch(context.filter, "", context.result, { @@ -1468,7 +1468,7 @@ function Completion() //{{{ urlCompleters: {}, - addUrlCompleter: function (opt) + addUrlCompleter: function addUrlCompleter(opt) { this.urlCompleters[opt] = UrlCompleter.apply(null, Array.slice(arguments)); }, diff --git a/content/util.js b/content/util.js index 05bc3a89..18273661 100644 --- a/content/util.js +++ b/content/util.js @@ -35,7 +35,7 @@ const util = { //{{{ Array: { // [["a", "b"], ["c", "d"]] -> {a: "b", c: "d"} // From Common Lisp, more or less - assocToObj: function (assoc) + assocToObj: function assocToObj(assoc) { let obj = {}; assoc.forEach(function ([k, v]) { obj[k] = v }); @@ -43,9 +43,9 @@ const util = { //{{{ }, // flatten an array: [["foo", ["bar"]], ["baz"], "quux"] -> ["foo", ["bar"], "baz", "quux"] - flatten: function (ary) Array.concat.apply([], ary), + flatten: function flatten(ary) Array.concat.apply([], ary), - iterator: function (ary) + iterator: function iterator(ary) { let length = ary.length; for (let i = 0; i < length; i++) @@ -59,7 +59,7 @@ const util = { //{{{ yield [i, ary[i]]; }, - uniq: function (ary, unsorted) + uniq: function uniq(ary, unsorted) { let ret = []; if (unsorted) @@ -136,7 +136,7 @@ const util = { //{{{ }; }, - cloneObject: function (obj) + cloneObject: function cloneObject(obj) { let newObj = {}; for (let [k, v] in Iterator(obj)) @@ -144,21 +144,21 @@ const util = { //{{{ return newObj; }, - clip: function (str, length) + clip: function clip(str, length) { return str.length <= length ? str : str.substr(0, length - 3) + "..."; }, - compareIgnoreCase: function (a, b) String.localeCompare(a.toLowerCase(), b.toLowerCase()), + compareIgnoreCase: function compareIgnoreCase(a, b) String.localeCompare(a.toLowerCase(), b.toLowerCase()), - computedStyle: function (node) + computedStyle: function computedStyle(node) { while (node instanceof Text && node.parentNode) node = node.parentNode; return node.ownerDocument.defaultView.getComputedStyle(node, null); }, - copyToClipboard: function (str, verbose) + copyToClipboard: function copyToClipboard(str, verbose) { const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"] .getService(Components.interfaces.nsIClipboardHelper); @@ -168,14 +168,14 @@ const util = { //{{{ liberator.echo("Yanked " + str, commandline.FORCE_SINGLELINE); }, - createURI: function (str) + createURI: function createURI(str) { const fixup = Components.classes["@mozilla.org/docshell/urifixup;1"] .getService(Components.interfaces.nsIURIFixup); return fixup.createFixupURI(str, fixup.FIXUP_FLAG_ALLOW_KEYWORD_LOOKUP); }, - escapeHTML: function (str) + escapeHTML: function escapeHTML(str) { // XXX: the following code is _much_ slower than a simple .replace() // :history display went down from 2 to 1 second after changing @@ -186,19 +186,19 @@ const util = { //{{{ return str.replace(/&/g, "&").replace(//g, ">"); }, - escapeRegex: function (str) + escapeRegex: function escapeRegex(str) { return str.replace(/([\\{}()[\].?*+])/g, "\\$1"); }, - escapeString: function (str, delimiter) + escapeString: function escapeString(str, delimiter) { if (delimiter == undefined) delimiter = '"'; return delimiter + str.replace(/([\\'"])/g, "\\$1").replace("\n", "\\n", "g").replace("\t", "\\t", "g") + delimiter; }, - formatBytes: function (num, decimalPlaces, humanReadable) + formatBytes: function formatBytes(num, decimalPlaces, humanReadable) { const unitVal = ["Bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]; let unitIndex = 0; @@ -234,7 +234,7 @@ const util = { //{{{ }, // generates an Asciidoc help entry, "command" can also be a mapping - generateHelp: function (command, extraHelp) + generateHelp: function generateHelp(command, extraHelp) { let start = "", end = ""; if (command instanceof liberator.Command) @@ -285,7 +285,7 @@ const util = { //{{{ return ret; }, - httpGet: function (url) + httpGet: function httpGet(url) { try { @@ -300,9 +300,9 @@ const util = { //{{{ } }, - identity: function (k) k, + identity: function identity(k) k, - map: function (obj, fn) + map: function map(obj, fn) { let ary = []; for (let i in Iterator(obj)) @@ -311,7 +311,7 @@ const util = { //{{{ }, // if color = true it uses HTML markup to color certain items - objectToString: function (object, color) + objectToString: function objectToString(object, color) { /* Use E4X literals so html is automatically quoted * only when it's asked for. Noone wants to see < @@ -380,7 +380,7 @@ const util = { //{{{ return color ? string : [s for each (s in string)].join(""); }, - range: function (start, end, reverse) + range: function range(start, end, reverse) { if (!reverse) { @@ -394,7 +394,7 @@ const util = { //{{{ } }, - interruptableRange: function (start, end, time) + interruptableRange: function interruptableRange(start, end, time) { let endTime = Date.now() + time; while (start < end) @@ -409,7 +409,7 @@ const util = { //{{{ }, // same as Firefox's readFromClipboard function, but needed for apps like Thunderbird - readFromClipboard: function () + readFromClipboard: function readFromClipboard() { let url; @@ -445,7 +445,7 @@ const util = { //{{{ // takes a string like 'google bla, www.osnews.com' // and returns an array ['www.google.com/search?q=bla', 'www.osnews.com'] - stringToURLArray: function (str) + stringToURLArray: function stringToURLArray(str) { let urls = str.split(new RegExp("\s*" + options["urlseparator"] + "\s*")); @@ -500,7 +500,7 @@ const util = { //{{{ return urls; }, - xmlToDom: function (node, doc, nodes) + xmlToDom: function xmlToDom(node, doc, nodes) { XML.prettyPrinting = false; switch (node.nodeKind()) @@ -565,7 +565,7 @@ function Struct() } Struct.prototype = { - clone: function () + clone: function clone() { return this.constructor.apply(null, this.slice()); },