From 195fc10e05dfacb1c9c414f79a1a9a79fe1b4c1f Mon Sep 17 00:00:00 2001 From: Ted Pavlic Date: Thu, 18 Dec 2008 12:34:12 -0500 Subject: [PATCH 1/5] Allows for empty defsearches and prevents red JS errors on bad URLs. --- common/content/liberator.js | 12 ++++++++++-- vimperator/content/bookmarks.js | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/content/liberator.js b/common/content/liberator.js index ab6c9b9f..e2e8f4d1 100644 --- a/common/content/liberator.js +++ b/common/content/liberator.js @@ -1090,7 +1090,11 @@ const liberator = (function () //{{{ switch (where) { case liberator.CURRENT_TAB: - getBrowser().loadURIWithFlags(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, postdata); + try + { + getBrowser().loadURIWithFlags(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, postdata); + } + catch (e) {} break; case liberator.NEW_BACKGROUND_TAB: @@ -1107,7 +1111,11 @@ const liberator = (function () //{{{ const wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); window.open(); whichwindow = wm.getMostRecentWindow("navigator:browser"); - whichwindow.loadURI(url, null, postdata); + try + { + whichwindow.loadURI(url, null, postdata); + } + catch (e) {} break; default: diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 8961f2fc..74cf8669 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -259,7 +259,7 @@ function Bookmarks() //{{{ "string", "google", { completer: function completer(context) completion.search(context, true), - validator: Option.validateCompleter + validator: function validator(value) value == "" || Option.validateCompleter.call(this, value) }); options.add(["preload"], From d6e5bdbe771a60d4264e3d99260da701c09c00ce Mon Sep 17 00:00:00 2001 From: Ted Pavlic Date: Thu, 18 Dec 2008 12:45:46 -0500 Subject: [PATCH 2/5] Updated :help 'defsearch' to reflect empty behavior. --- vimperator/locale/en-US/options.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vimperator/locale/en-US/options.txt b/vimperator/locale/en-US/options.txt index 71056576..ab3b67c0 100644 --- a/vimperator/locale/en-US/options.txt +++ b/vimperator/locale/en-US/options.txt @@ -247,6 +247,9 @@ This means, it you set 'defsearch' to "youtube", then [c]:open arnold schwarzenegger[c] will be exactly the same as [c]:open youtube arnold schwarzenegger[c]. Therefore, you need to add a keyword or search engine "youtube" first. + +If 'defsearch' is empty, then Firefox will always attempt to open the +raw [[arg]]. ____ From 50f73844c8342a192dfa763ad8b2e0038822572d Mon Sep 17 00:00:00 2001 From: Ted Pavlic Date: Thu, 18 Dec 2008 13:20:47 -0500 Subject: [PATCH 3/5] Reverting empty defsearch changes in last two commits. Leaving in JS catches. --- vimperator/content/bookmarks.js | 2 +- vimperator/locale/en-US/options.txt | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 74cf8669..8961f2fc 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -259,7 +259,7 @@ function Bookmarks() //{{{ "string", "google", { completer: function completer(context) completion.search(context, true), - validator: function validator(value) value == "" || Option.validateCompleter.call(this, value) + validator: Option.validateCompleter }); options.add(["preload"], diff --git a/vimperator/locale/en-US/options.txt b/vimperator/locale/en-US/options.txt index ab3b67c0..71056576 100644 --- a/vimperator/locale/en-US/options.txt +++ b/vimperator/locale/en-US/options.txt @@ -247,9 +247,6 @@ This means, it you set 'defsearch' to "youtube", then [c]:open arnold schwarzenegger[c] will be exactly the same as [c]:open youtube arnold schwarzenegger[c]. Therefore, you need to add a keyword or search engine "youtube" first. - -If 'defsearch' is empty, then Firefox will always attempt to open the -raw [[arg]]. ____ From ac0b476988cebdc9032a1a62b3668cd1b0f61fe0 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 18 Dec 2008 13:59:59 -0500 Subject: [PATCH 4/5] Don't anchor help completions. --- common/content/completion.js | 1 + 1 file changed, 1 insertion(+) diff --git a/common/content/completion.js b/common/content/completion.js index f008e7ff..bf4a9622 100644 --- a/common/content/completion.js +++ b/common/content/completion.js @@ -1374,6 +1374,7 @@ function Completion() //{{{ help: function help(context) { context.title = ["Help"]; + context.anchored = false; context.generate = function () { let res = config.helpFiles.map(function (file) { From c094a2dd2b648a3e5717652d6e2439858e5e7108 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 18 Dec 2008 18:21:01 -0500 Subject: [PATCH 5/5] Fix */# --- common/content/buffer.js | 33 ++++++++++++++++------- common/content/commands.js | 46 ++++++++++++++++++--------------- common/content/find.js | 2 ++ common/content/io.js | 3 +-- common/content/options.js | 37 ++++++++++++++++++++++++-- vimperator/content/bookmarks.js | 1 + 6 files changed, 87 insertions(+), 35 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index bfd0b356..66f15316 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -467,21 +467,34 @@ function Buffer() //{{{ "Print current document", function (args) { - let aps = options.getPref("print.always_print_silent"); - let spp = options.getPref("print.show_print_progress"); + options.temporaryContext(function () { + if (args[0]) + { + if (args[0][0] != ">") + return liberator.echoerr("E488: Trailing characters"); + options.setPref("print.print_to_file", "true"); + options.setPref("print.print_to_filename", io.getFile(args[0].substr(1)).path); + liberator.echomsg("Printing to file: " + args[0].substr(1)); + } + else + { + liberator.echomsg("Sending to printer..."); + } - liberator.echomsg("Sending to printer..."); - options.setPref("print.always_print_silent", args.bang); - options.setPref("print.show_print_progress", !args.bang); + options.setPref("print.always_print_silent", args.bang); + options.setPref("print.show_print_progress", !args.bang); - getBrowser().contentWindow.print(); + getBrowser().contentWindow.print(); + }); - options.setPref("print.always_print_silent", aps); - options.setPref("print.show_print_progress", spp); - liberator.echomsg("Print job sent."); + if (args[0]) + liberator.echomsg("Printed: " + args[0].substr(1)); + else + liberator.echomsg("Print job sent."); }, { - argCount: "0", + argCount: "?", + literal: 0, bang: true }); diff --git a/common/content/commands.js b/common/content/commands.js index ff67557e..67540eb9 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -758,9 +758,30 @@ function Commands() //{{{ if (completeOpt) { if (/^custom,/.test(completeOpt)) - completeFunc = completeOpt.substr(7); - else - completeFunc = "completion." + completeOptionMap[completeOpt]; + { + completeFunc = function () + { + try + { + var completer = liberator.eval(completeOpt.substr(7)); + + if (!(completer instanceof Function)) + throw new TypeError("User-defined custom completer '" + completeOpt.substr(7) + "' is not a function"); + } + catch (e) + { + // FIXME: should be pushed to the MOW + liberator.echoerr("E117: Unknown function: " + completeOpt.substr(7)); + liberator.log(e); + return undefined; + } + return completer.apply(this, Array.slice(arguments)); + } + } + else + { + completeFunc = function () completion[completeOptionMap[completeOpt]].apply(this, Array.slice(arguments)); + } } if (!commands.addUserCommand( @@ -773,24 +794,7 @@ function Commands() //{{{ count: countOpt, completer: function (context, args) { if (completeFunc) - { - try - { - var completer = liberator.eval(completeFunc); - - if (!(completer instanceof Function)) - throw new TypeError("User-defined custom completer '" + completeFunc + "' is not a function"); - } - catch (e) - { - // FIXME: should be pushed to the MOW - liberator.echoerr("E117: Unknown function: " + completeFunc); - liberator.log(e); - return; - } - - completer.call(completion, context, args) - } + return completeFunc(context, args) }, replacementText: args.literalArg }, diff --git a/common/content/find.js b/common/content/find.js index b7f9869c..794476ac 100644 --- a/common/content/find.js +++ b/common/content/find.js @@ -288,6 +288,7 @@ function Search() //{{{ "Find word under cursor", function () { + found = false; search.searchSubmitted(buffer.getCurrentWord(), false); search.findAgain(); }); @@ -296,6 +297,7 @@ function Search() //{{{ "Find word under cursor backwards", function () { + found = false; search.searchSubmitted(buffer.getCurrentWord(), true); search.findAgain(); }); diff --git a/common/content/io.js b/common/content/io.js index 0e749456..fd111d52 100644 --- a/common/content/io.js +++ b/common/content/io.js @@ -99,8 +99,7 @@ function IO() //{{{ return []; else // empty list item means the current directory - return list.replace(/,$/, "") - .split(",") + return list.replace(/,$/, "").split(",") .map(function (dir) dir == "" ? io.getCurrentDirectory().path : dir); } diff --git a/common/content/options.js b/common/content/options.js index ed2887f5..460490bb 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -302,7 +302,9 @@ function Options() //{{{ const SAVED = "liberator.saved."; const prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); - var optionHash = {}; + const optionHash = {}; + + const prefContexts = []; function optionObserver(key, event, option) { @@ -320,6 +322,13 @@ function Options() //{{{ function storePreference(name, value) { + if (prefContexts.length) + { + let val = loadPreference(name, null); + if (val != null) + prefContexts[prefContexts.length - 1][name] = val; + } + var type = prefService.getPrefType(name); switch (typeof value) { @@ -988,7 +997,31 @@ function Options() //{{{ this.setPref(name, !this.getPref(name)); else liberator.echoerr("E488: Trailing characters: " + name + "!"); - } + }, + + pushContext: function () + { + prefContexts.push({}); + }, + + popContext: function () + { + for (let [k, v] in Iterator(prefContexts.pop())) + storePreference(k, v); + }, + + temporaryContext: function (fn, self) + { + try + { + this.pushContext(); + return fn.call(self); + } + finally + { + this.popContext(); + } + }, }; //}}} }; //}}} diff --git a/vimperator/content/bookmarks.js b/vimperator/content/bookmarks.js index 8961f2fc..9dd6e9b1 100644 --- a/vimperator/content/bookmarks.js +++ b/vimperator/content/bookmarks.js @@ -728,6 +728,7 @@ function History() //{{{ context.completions = [sh.getEntryAtIndex(i, false) for (i in util.range(sh.index, 0, true))]; context.keys = { text: function (item) item.URI.spec, description: "title" }; + liberator.dump(context.items); }, count: true, literal: 0