mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 23:08:00 +01:00
Junk dactyl.{evalExpression,variableReference}.
Replace mappings.getMapLeader() with a mappings.mapLeader property.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 == "<Return>" || key == "<Tab>" || key == "<S-Tab>"
|
||||
|| key == mappings.getMapLeader()
|
||||
|| key == mappings.mapLeader
|
||||
|| (key == "<BS>" && hints.prevInput == "number")
|
||||
|| (hints.isHintKey(key) && !hints.escNumbers)) {
|
||||
hints.onEvent(event);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -174,7 +174,7 @@ const Mappings = Module("mappings", {
|
||||
}
|
||||
},
|
||||
|
||||
_expandLeader: function (keyString) keyString.replace(/<Leader>/i, mappings.getMapLeader()),
|
||||
_expandLeader: function (keyString) keyString.replace(/<Leader>/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
|
||||
* "<Leader>" when user mappings are defined.
|
||||
*
|
||||
* @returns {string}
|
||||
* @property {string} The map leader string used to replace the special
|
||||
* token "<Leader>" 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 <b>cmd</b> for the
|
||||
|
||||
@@ -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 =
|
||||
<table>
|
||||
{
|
||||
template.map(dactyl.globalVariables, function ([i, value]) {
|
||||
let prefix = typeof value == "number" ? "#" :
|
||||
typeof value == "function" ? "*" :
|
||||
" ";
|
||||
return <tr>
|
||||
<td style="width: 200px;">{i}</td>
|
||||
<td>{prefix}{value}</td>
|
||||
<td>{fmt(value)}</td>
|
||||
</tr>;
|
||||
})
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user