diff --git a/common/content/buffer.js b/common/content/buffer.js index 23f50c6b..abbfb23c 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -802,14 +802,24 @@ var Buffer = Module("buffer", { * @param {nsIURI} uri The URI to save * @param {nsIFile} file The file into which to write the result. */ - saveURI: function (uri, file) { + saveURI: function (uri, file, callback, self) { var persist = services.Persist(); persist.persistFlags = persist.PERSIST_FLAGS_FROM_CACHE | persist.PERSIST_FLAGS_REPLACE_EXISTING_FILES; - persist.progressListener = new window.DownloadListener(window, + let downloadListener = new window.DownloadListener(window, services.Transfer(uri, services.io.newFileURI(file), "", null, null, null, persist)); + + persist.progressListener = update(Object.create(downloadListener), { + onStateChange: function onStateChange(progress, request, flag, status) { + if (callback && (flag & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) + dactyl.trapErrors(callback, self, uri, file, progress, request, flag, status); + + return onStateChange.superapply(this, arguments); + } + }); + persist.saveURI(uri, null, null, null, null, file); }, @@ -1130,7 +1140,7 @@ var Buffer = Module("buffer", { }, onStateChange: function (progress, request, flag, status) { - if ((flag & Ci.nsIWebProgressListener.STATE_STOP) && status == 0) { + if ((flag & this.STATE_STOP) && status == 0) { try { var ok = this.callback(this.file, true); } diff --git a/common/content/modes.js b/common/content/modes.js index 0f62e38e..a32011af 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -491,7 +491,7 @@ var Modes = Module("modes", { } }, { mappings: function () { - mappings.add([modes.BASE], + mappings.add([modes.BASE, modes.NORMAL], ["", ""], "Return to NORMAL mode", function () { modes.reset(); }); diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm index 3ff97529..d629dc3f 100644 --- a/common/modules/finder.jsm +++ b/common/modules/finder.jsm @@ -87,7 +87,10 @@ var RangeFinder = Module("rangefinder", { find: function (pattern, backwards) { let str = this.bootstrap(pattern, backwards); if (!this.rangeFind.find(str)) - this.timeout(function () { this.dactyl.echoerr("E486: Pattern not found: " + pattern); }, 0); + this.timeout(function () { + this.dactyl.echoerr("E486: Pattern not found: " + pattern, + this.commandline.FORCE_SINGLELINE); + }); return this.rangeFind.found; }, @@ -96,7 +99,8 @@ var RangeFinder = Module("rangefinder", { if (!this.rangeFind || this.rangeFind.stale) this.find(this.lastFindPattern); else if (!this.rangeFind.find(null, reverse)) - this.dactyl.echoerr("E486: Pattern not found: " + this.lastFindPattern); + this.dactyl.echoerr("E486: Pattern not found: " + this.lastFindPattern, + this.commandline.FORCE_SINGLELINE); else if (this.rangeFind.wrapped) // hack needed, because wrapping causes a "scroll" event which // clears our command line @@ -380,7 +384,7 @@ var RangeFind = Class("RangeFind", { focus: function () { if (this.lastRange) - var node = util.evaluateXPath(RangeFind.selectNodePath, this.range.document, + var node = util.evaluateXPath(RangeFind.selectNodePath, this.lastRange.commonAncestorContainer).snapshotItem(0); if (node) { node.focus() diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 7a53aee5..ea035b80 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -466,12 +466,12 @@ var IO = Module("io", { res = this.run("/bin/sh", ["-e", cmd.path], true); } - let output = stdout.read(); - if (res > 0) - output += "\nshell returned " + res; - else if (output) - output = output.replace(/^(.*)\n$/, "$1"); - return output; + return { + __noSuchMethod__: function (meth, args) this.output[meth].apply(this.output, args), + valueOf: function () this.output, + output: stdout.read().replace(/^(.*)\n$/, "$1"), + returnValue: res + }; }) || ""; }, @@ -831,10 +831,12 @@ unlet s:cpo_save io._lastRunCommand = arg; - let output = io.system(arg); + let result = io.system(arg); + if (result.returnValue != 0) + result.output += "\nshell returned " + res; modules.commandline.command = "!" + arg; - modules.commandline.commandOutput({output}); + modules.commandline.commandOutput({result.output}); modules.autocommands.trigger("ShellCmdPost", {}); }, { @@ -873,7 +875,8 @@ unlet s:cpo_save context.title = ["Environment Variable", "Value"]; context.generate = function () io.system(util.OS.isWindows ? "set" : "env") - .split("\n").filter(function (line) line.indexOf("=") > 0) + .output.split("\n") + .filter(function (line) line.indexOf("=") > 0) .map(function (line) line.match(/([^=]+)=(.*)/).slice(1)); }; diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index c29bb9c9..a0c1df71 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -331,11 +331,6 @@ var File = Class("File", { return f; }, - /** - * Returns a clone of this file. - */ - clone: function () File(this), - /** * Reads this file's entire contents in "text" mode and returns the * content as a string. diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index 3ee8efad..654c11d8 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -450,10 +450,13 @@ var Styles = Module("Styles", { bang: true, completer: function (context, args) { let compl = []; - if (args.completeArg == 0) - Styles.completeSite(context, window.content); + let sheet = styles.user.get(args["-name"]); + if (args.completeArg == 0) { + if (sheet) + context.completions = [[sheet.sites.join(","), "Current Value"]]; + context.fork("sites", 0, Styles, "completeSite", window.content); + } else if (args.completeArg == 1) { - let sheet = styles.user.get(args["-name"]); if (sheet) context.completions = [[sheet.css, "Current Value"]]; context.fork("css", 0, modules.completion, "css"); diff --git a/common/modules/template.jsm b/common/modules/template.jsm index 60259bc9..483cc1d8 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -80,6 +80,9 @@ var Template = Module("Template", { }, helpLink: function (topic, text, type) { + if (!services["dactyl:"].initialized) + util.dactyl.initHelp(); + if (services["dactyl:"].initialized && !set.has(services["dactyl:"].HELP_TAGS, topic)) return {text || topic}; @@ -89,6 +92,9 @@ var Template = Module("Template", { return {text || topic} }, HelpLink: function (topic) { + if (!services["dactyl:"].initialized) + util.dactyl.initHelp(); + if (services["dactyl:"].initialized && !set.has(services["dactyl:"].HELP_TAGS, topic)) return <>{topic}; @@ -220,8 +226,6 @@ var Template = Module("Template", { }, linkifyHelp: function linkifyHelp(str, help) { - util.dactyl.initHelp(); - let re = util.regexp( ) diff --git a/common/modules/util.jsm b/common/modules/util.jsm index 5cad34c4..80816a5a 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -567,35 +567,37 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * namespaces. The result may be used as an iterator. * * @param {string} expression The XPath expression to evaluate. - * @param {Document} doc The document to evaluate the expression in. - * @default The current document. * @param {Node} elem The context element. - * @default *doc* + * @default The current document. * @param {boolean} asIterator Whether to return the results as an * XPath iterator. * @returns {Object} Iterable result of the evaluation. */ evaluateXPath: update( - function evaluateXPath(expression, doc, elem, asIterator) { - if (!doc) - doc = util.activeWindow.content.document; - if (!elem) - elem = doc; - if (isArray(expression)) - expression = util.makeXPath(expression); + function evaluateXPath(expression, elem, asIterator) { + try { + if (!elem) + elem = util.activeWindow.content.document; + let doc = elem.ownerDocument || elem; + if (isArray(expression)) + expression = util.makeXPath(expression); - let result = doc.evaluate(expression, elem, - evaluateXPath.resolver, - asIterator ? Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE : Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE, - null - ); + let result = doc.evaluate(expression, elem, + evaluateXPath.resolver, + asIterator ? Ci.nsIDOMXPathResult.ORDERED_NODE_ITERATOR_TYPE : Ci.nsIDOMXPathResult.ORDERED_NODE_SNAPSHOT_TYPE, + null + ); - return Object.create(result, { - __iterator__: { - value: asIterator ? function () { let elem; while ((elem = this.iterateNext())) yield elem; } - : function () { for (let i = 0; i < this.snapshotLength; i++) yield this.snapshotItem(i); } - } - }); + return Object.create(result, { + __iterator__: { + value: asIterator ? function () { let elem; while ((elem = this.iterateNext())) yield elem; } + : function () { for (let i = 0; i < this.snapshotLength; i++) yield this.snapshotItem(i); } + } + }); + } + catch (e) { + throw e.stack ? e : Error(e); + } }, { resolver: function lookupNamespaceURI(prefix) ({