From da3785028d972cbf6781e4790913e85bccb33ff5 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Fri, 30 Nov 2012 20:46:38 -0800 Subject: [PATCH] Death to E4X and stuff. --- common/content/autocommands.js | 1 - common/content/dactyl.js | 130 ++++++++++++++++++++++++++++++--- common/content/modes.js | 22 +++--- common/content/statusline.js | 1 - common/modules/contexts.jsm | 6 +- common/modules/protocol.jsm | 8 +- 6 files changed, 138 insertions(+), 30 deletions(-) diff --git a/common/content/autocommands.js b/common/content/autocommands.js index 040a8ba3..3246efcd 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -103,7 +103,6 @@ var AutoCommands = Module("autocommands", { return cmds; } - XML.prettyPrinting = XML.ignoreWhitespace = false; let table = ( ["table", {}, ["tr", { highlight: "Title" }, diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 4de27eb0..bda77542 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -8,10 +8,6 @@ /** @scope modules */ -default xml namespace = XHTML; -XML.ignoreWhitespace = false; -XML.prettyPrinting = false; - var EVAL_ERROR = "__dactyl_eval_error"; var EVAL_RESULT = "__dactyl_eval_result"; var EVAL_STRING = "__dactyl_eval_string"; @@ -656,12 +652,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { help.initialize(); }, - stringifyXML: function (xml) { - XML.prettyPrinting = false; - XML.ignoreWhitespace = false; - return UTF8(xml.toXMLString()); - }, - /** * Generates a help entry and returns it as a string. * @@ -773,6 +763,105 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { .replace(/^ {12}|[ \t]+$/gm, "") .replace(/^\s*\n|\n\s*$/g, "") + "\n"; }, + _generateHelp: function generateHelp(obj, extraHelp, str, specOnly) { + // E4X-FIXME + + let link, tag, spec; + link = tag = spec = util.identity; + let args = null; + + if (obj instanceof Command) { + link = function (cmd) ["ex", {}, cmd]; + args = obj.parseArgs("", CompletionContext(str || "")); + tag = function (cmd) DOM.DOMString(":" + cmd); + spec = function (cmd) [ + obj.count ? ["oa", {}, "count"] : [], + cmd, + obj.bang ? ["oa", {}, "!"] : [] + ]; + } + else if (obj instanceof Map) { + spec = function (map) obj.count ? [["oa", {}, "count"], map] : DOM.DOMString(map); + tag = function (map) [ + let (c = obj.modes[0].char) c ? c + "_" : "", + map + ] + link = function (map) { + let [, mode, name, extra] = /^(?:(.)_)?(?:<([^>]+)>)?(.*)$/.exec(map); + let k = ["k", {}, extra]; + if (name) + k[1].name = name; + if (mode) + k[1].mode = mode; + return k; + }; + } + else if (obj instanceof Option) { + spec = function () template_.map(obj.names, tag, " "); + tag = function (name) DOM.DOMString("'" + name + "'"); + link = function (opt, name) ["o", {}, name]; + args = { value: "", values: [] }; + } + + let br = "\n\ + "; + + let res = [ + ["dt", {}, link(obj.helpTag || tag(obj.name), obj.name)], " ", + ["dd", {}, + template_.linkifyHelp(obj.description ? obj.description.replace(/\.$/, "") : "", true)]]; + if (specOnly) + return res; + + res.push( + ["item", {}, + ["tags", {}, template_.map(obj.names.slice().reverse(), + tag, + " ")], + ["spec", {}, + let (name = (obj.specs || obj.names)[0]) + spec(template_.highlightRegexp(tag(name), + /\[(.*?)\]/g, + function (m, n0) ["oa", {}, n0]), + name)], + !obj.type ? "" : [ + ["type", {}, obj.type], + ["default", {}, obj.stringDefaultValue], + ["description", {}, + obj.description ? /*br*/ ["p", {}, template_.linkifyHelp(obj.description.replace(/\.?$/, "."), true)] : "", + extraHelp ? /*br*/ extraHelp : "", + !(extraHelp || obj.description) ? /*br*/ ["p", {}, /*L*/ "Sorry, no help available."] : ""]]]); + + function add(ary) { + res.item.description.* += br + + let (br = br + " ") + ["dl", {}, /*br*/ template_.map(ary, + function ([a, b]) [["dt", {}, a], " ", + ["dd", {}, b]], + br)] + } + + if (obj.completer && false) + add(completion._runCompleter(obj.closure.completer, "", null, args).items + .map(function (i) [i.text, i.description])); + + if (obj.options && obj.options.some(function (o) o.description) && false) + add(obj.options.filter(function (o) o.description) + .map(function (o) [ + o.names[0], + [o.description, + o.names.length == 1 ? "" : + ["", " (short name: ", + template_.map(o.names.slice(1), function (n) ["em", {}, n], ", "), + ")"]] + ])); + + util.dump(util.prettifyJSON(res, null, true)); + return DOM.toXML(res) + .replace(' xmlns="' + NS + '"', "", "g") + .replace(/^ {12}|[ \t]+$/gm, "") + .replace(/^\s*\n|\n\s*$/g, "") + "\n"; + }, /** * The map of global variables. @@ -1232,7 +1321,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { cache: function initCache() { cache.register("help/plugins.xml", function () { // Process plugin help entries. - XML.ignoreWhiteSpace = XML.prettyPrinting = false; let body = []; for (let [, context] in Iterator(plugins.contexts)) @@ -1249,10 +1337,28 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (elem[attr].length()) info[attr] = elem[attr]; } - body.push(["h2", { xmlns: NS.uri, tag: info.@name + '-plugin' }, + body.push(["h2", { xmlns: "dactyl", tag: info.@name + '-plugin' }, String(info.@summary)]); body.push(info); } + else if (DOM.isJSONXML(info)) { + let langs = info.slice(2).filter(function (e) isArray(e) && isObject(e[1]) && e[1].leng); + if (langs) { + let lang = config.bestLocale(l[1].lang for each (l in langs)); + + info = info.slice(0, 2).concat( + info.slice(2).filter(function (e) !isArray(e) || !isObject(e[1]) + || e[1].lang == lang)); + + for each (let elem in info.slice(2).filter(function (e) isArray(e) && e[0] == "info" && isObject(e[1]))) + for (let attr in values(["name", "summary", "href"])) + if (attr in elem[1]) + info[attr] = elem[1][attr]; + } + body.push(["h2", { xmlns: "dactyl", tag: info.name + '-plugin' }, + String(info.summary)]); + body.push(info); + } } catch (e) { util.reportError(e); diff --git a/common/content/modes.js b/common/content/modes.js index 799b1259..47ad2562 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -4,7 +4,7 @@ // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; /** @scope modules */ @@ -532,23 +532,23 @@ var Modes = Module("modes", { for (let base in values(mode.bases)) tree[base.name][mode.name] = tree[mode.name]; - let roots = iter([m.name, tree[m.name]] for (m in values(list)) if (!m.bases.length)).toObject(); + let roots = iter([m.name, tree[m.name]] + for (m in values(list)) + if (!m.bases.length)).toObject(); - default xml namespace = NS; function rec(obj) { - XML.ignoreWhitespace = XML.prettyPrinting = false; - - let res =