diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 3412a27c..57836873 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -341,46 +341,6 @@ const Dactyl = Module("dactyl", { ") { " + arguments[arguments.length - 1] + " })"); }, - // partial sixth level expression evaluation - // TODO: what is that really needed for, and where could it be used? - // Or should it be removed? (c) Viktor - // Better name? See other dactyl.userEval() - // I agree, the name is confusing, and so is the - // description --Kris - evalExpression: function (str) { - str = str.trim(); // XXX - - let matches = str.match(/^&(\w+)/); - if (matches) { - let opt = this.options.get(matches[1]); - - dactyl.assert(opt, "E113: Unknown option: " + matches[1]); - - let type = opt.type; - let value = opt.getter(); - - if (type != "boolean" && type != "number") - value = value.toString(); - - return value; - } - // String - else if ((matches = str.match(/^(['"])([^\1]*?[^\\]?)\1/))) { - return matches[2].toString(); - } - // Number - else if ((matches = str.match(/^(\d+)$/))) - return parseInt(matches[1], 10); - - let reference = this.variableReference(str); - - if (!reference[0]) - this.echoerr("E121: Undefined variable: " + str); - else - return reference[0][reference[1]]; - return null; - }, - /** * Execute an Ex command string. E.g. ":zoom 300". * @@ -1113,29 +1073,6 @@ const Dactyl = Module("dactyl", { } }, - variableReference: function (string) { - if (!string) - return [null, null, null]; - - let matches = string.match(/^([bwtglsv]):(\w+)/); - if (matches) { // Variable - // Other variables should be implemented - if (matches[1] == "g") { - if (matches[2] in this.globalVariables) - return [this.globalVariables, matches[2], matches[1]]; - else - return [null, matches[2], matches[1]]; - } - } - else { // Global variable - if (string in this.globalVariables) - return [this.globalVariables, string, "g"]; - else - return [null, string, "g"]; - } - throw Error("What the fuck?"); - }, - /** * @property {Window[]} Returns an array of all the host application's * open windows. diff --git a/common/content/events.js b/common/content/events.js index a038a9e5..a1f4a594 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -919,7 +919,7 @@ const Events = Module("events", { if (modes.extended & modes.HINTS) { // under HINT mode, certain keys are redirected to hints.onEvent if (key == "" || key == "" || key == "" - || key == mappings.getMapLeader() + || key == mappings.mapLeader || (key == "" && hints.prevInput == "number") || (hints.isHintKey(key) && !hints.escNumbers)) { hints.onEvent(event); diff --git a/common/content/hints.js b/common/content/hints.js index a3eab983..f9780551 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -93,7 +93,7 @@ const Hints = Module("hints", { * Display the current status to the user. */ _updateStatusline: function () { - statusline.updateInputBuffer((hints.escNumbers ? mappings.getMapLeader() : "") + + statusline.updateInputBuffer((hints.escNumbers ? mappings.mapLeader : "") + (this._hintNumber ? this.getHintString(this._hintNumber) : "")); }, @@ -849,7 +849,7 @@ const Hints = Module("hints", { } break; - case mappings.getMapLeader(): + case mappings.mapLeader: hints.escNumbers = !hints.escNumbers; if (hints.escNumbers && this._usedTabKey) this._hintNumber = 0; diff --git a/common/content/mappings.js b/common/content/mappings.js index cc531756..040d552b 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -174,7 +174,7 @@ const Mappings = Module("mappings", { } }, - _expandLeader: function (keyString) keyString.replace(//i, mappings.getMapLeader()), + _expandLeader: function (keyString) keyString.replace(//i, mappings.mapLeader), // Return all mappings present in all @modes _mappingsIterator: function (modes, stack) { @@ -290,16 +290,13 @@ const Mappings = Module("mappings", { }, /* - * Returns the map leader string used to replace the special token - * "" when user mappings are defined. - * - * @returns {string} + * @property {string} The map leader string used to replace the special + * token "" when user mappings are defined. */ - // FIXME: property - getMapLeader: function () { - let leaderRef = dactyl.variableReference("mapleader"); - return leaderRef[0] ? leaderRef[0][leaderRef[1]] : "\\"; - }, + get mapLeader() dactyl.globalVariables["mapleader"] || "\\", + /** @deprecated */ + getMapLeader: function () this.mapLeader, + /** * Returns whether there is a user-defined mapping cmd for the diff --git a/common/content/options.js b/common/content/options.js index 95263f57..b6d62cd3 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -1204,22 +1204,24 @@ const Options = Module("options", { } } + // TODO: deprecated. This needs to support "g:"-prefixed globals at a + // minimum for now. The coderepos plugins make extensive use of global + // variables. commands.add(["let"], "Set or list a variable", function (args) { - args = args[0]; - - if (!args) { + args = args.literalArg.trim(); + function fmt(value) (typeof value == "number" ? "#" : + typeof value == "function" ? "*" : + " ") + value; + if (!args || args == "g:") { let str = { template.map(dactyl.globalVariables, function ([i, value]) { - let prefix = typeof value == "number" ? "#" : - typeof value == "function" ? "*" : - " "; return - + ; }) } @@ -1231,49 +1233,41 @@ const Options = Module("options", { return; } - // 1 - type, 2 - name, 3 - +-., 4 - expr - let matches = args.match(/([$@&])?([\w:]+)\s*([-+.])?=\s*(.+)/); + let matches = args.match(/^([a-z]:)?([\w]+)(?:\s*([-+.])?=\s*(.*)?)?$/); if (matches) { - let [, type, name, stuff, expr] = matches; - if (!type) { - let reference = dactyl.variableReference(name); - dactyl.assert(reference[0] || !stuff, - "E121: Undefined variable: " + name); + let [, scope, name, op, expr] = matches; + let fullName = (scope || "") + name; - expr = dactyl.evalExpression(expr); - dactyl.assert(expr !== undefined, "E15: Invalid expression: " + expr); + dactyl.assert(scope == "g:" || scope == null, + "E461: Illegal variable name: " + scope + name); + dactyl.assert(dactyl.globalVariables.hasOwnProperty(name) || (expr && !op), + "E121: Undefined variable: " + fullName); - if (!reference[0]) { - if (reference[2] == "g") - reference[0] = dactyl.globalVariables; - else - return; // for now + if (!expr) + dactyl.echo(fullName + "\t\t" + fmt(dactyl.globalVariables[name])); + else { + try { + var newValue = dactyl.userEval(expr); } + catch (e) {} + dactyl.assert(newValue !== undefined, + "E15: Invalid expression: " + expr); - if (stuff) { - if (stuff == "+") - reference[0][reference[1]] += expr; - else if (stuff == "-") - reference[0][reference[1]] -= expr; - else if (stuff == ".") - reference[0][reference[1]] += expr.toString(); + let value = newValue; + if (op) { + value = dactyl.globalVariables[name]; + if (op == "+") + value += newValue; + else if (op == "-") + value -= newValue; + else if (op == ".") + value += String(newValue); } - - else - reference[0][reference[1]] = expr; - } - } - // 1 - name - else if ((matches = args.match(/^\s*([\w:]+)\s*$/))) { - let reference = dactyl.variableReference(matches[1]); - dactyl.assert(reference[0], "E121: Undefined variable: " + matches[1]); - - let value = reference[0][reference[1]]; - let prefix = typeof value == "number" ? "#" : - typeof value == "function" ? "*" : - " "; - dactyl.echo(reference[1] + "\t\t" + prefix + value); + dactyl.globalVariables[name] = value; + } } + else + dactyl.echoerr("E18: Unexpected characters in :let"); }, { literal: 0 @@ -1338,18 +1332,20 @@ const Options = Module("options", { }, params.extra || {})); }); + // TODO: deprecated. This needs to support "g:"-prefixed globals at a + // minimum for now. commands.add(["unl[et]"], "Delete a variable", function (args) { for (let [, name] in args) { - let reference = dactyl.variableReference(name); - if (!reference[0]) { + name = name.replace(/^g:/, ""); // throw away the scope prefix + if (!dactyl.globalVariables.hasOwnProperty(name)) { if (!args.bang) dactyl.echoerr("E108: No such variable: " + name); return; } - delete reference[0][reference[1]]; + delete dactyl.globalVariables[name]; } }, { diff --git a/pentadactyl/TODO b/pentadactyl/TODO index 651a83cf..98c0aeaf 100644 --- a/pentadactyl/TODO +++ b/pentadactyl/TODO @@ -28,7 +28,8 @@ BUGS: FEATURES: 9 Add quoting help tag 8 Document Caret and Visual modes. -8 finish :help TODOs +8 make 'mapleader' an option +8 replace global variables with plugin scoped user options 8 fix local options 8 adaptive timeout for auto-completions, :set completions can be updated more often than :open foo
{i}{prefix}{value}{fmt(value)}