diff --git a/common/content/buffer.js b/common/content/buffer.js index e6a15cd7..4a95beb5 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -483,21 +483,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 c5d7c3ae..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); + { + 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 = "completion." + completeOptionMap[completeOpt]; + { + 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/io.js b/common/content/io.js index 427a9a2a..0932f5a4 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 34828e18..54cc90a2 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 4926cea4..7d749c57 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