mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 20:47:58 +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] + " })");
|
") { " + 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".
|
* 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
|
* @property {Window[]} Returns an array of all the host application's
|
||||||
* open windows.
|
* open windows.
|
||||||
|
|||||||
@@ -919,7 +919,7 @@ const Events = Module("events", {
|
|||||||
if (modes.extended & modes.HINTS) {
|
if (modes.extended & modes.HINTS) {
|
||||||
// under HINT mode, certain keys are redirected to hints.onEvent
|
// under HINT mode, certain keys are redirected to hints.onEvent
|
||||||
if (key == "<Return>" || key == "<Tab>" || key == "<S-Tab>"
|
if (key == "<Return>" || key == "<Tab>" || key == "<S-Tab>"
|
||||||
|| key == mappings.getMapLeader()
|
|| key == mappings.mapLeader
|
||||||
|| (key == "<BS>" && hints.prevInput == "number")
|
|| (key == "<BS>" && hints.prevInput == "number")
|
||||||
|| (hints.isHintKey(key) && !hints.escNumbers)) {
|
|| (hints.isHintKey(key) && !hints.escNumbers)) {
|
||||||
hints.onEvent(event);
|
hints.onEvent(event);
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ const Hints = Module("hints", {
|
|||||||
* Display the current status to the user.
|
* Display the current status to the user.
|
||||||
*/
|
*/
|
||||||
_updateStatusline: function () {
|
_updateStatusline: function () {
|
||||||
statusline.updateInputBuffer((hints.escNumbers ? mappings.getMapLeader() : "") +
|
statusline.updateInputBuffer((hints.escNumbers ? mappings.mapLeader : "") +
|
||||||
(this._hintNumber ? this.getHintString(this._hintNumber) : ""));
|
(this._hintNumber ? this.getHintString(this._hintNumber) : ""));
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -849,7 +849,7 @@ const Hints = Module("hints", {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case mappings.getMapLeader():
|
case mappings.mapLeader:
|
||||||
hints.escNumbers = !hints.escNumbers;
|
hints.escNumbers = !hints.escNumbers;
|
||||||
if (hints.escNumbers && this._usedTabKey)
|
if (hints.escNumbers && this._usedTabKey)
|
||||||
this._hintNumber = 0;
|
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
|
// Return all mappings present in all @modes
|
||||||
_mappingsIterator: function (modes, stack) {
|
_mappingsIterator: function (modes, stack) {
|
||||||
@@ -290,16 +290,13 @@ const Mappings = Module("mappings", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns the map leader string used to replace the special token
|
* @property {string} The map leader string used to replace the special
|
||||||
* "<Leader>" when user mappings are defined.
|
* token "<Leader>" when user mappings are defined.
|
||||||
*
|
|
||||||
* @returns {string}
|
|
||||||
*/
|
*/
|
||||||
// FIXME: property
|
get mapLeader() dactyl.globalVariables["mapleader"] || "\\",
|
||||||
getMapLeader: function () {
|
/** @deprecated */
|
||||||
let leaderRef = dactyl.variableReference("mapleader");
|
getMapLeader: function () this.mapLeader,
|
||||||
return leaderRef[0] ? leaderRef[0][leaderRef[1]] : "\\";
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether there is a user-defined mapping <b>cmd</b> for the
|
* 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"],
|
commands.add(["let"],
|
||||||
"Set or list a variable",
|
"Set or list a variable",
|
||||||
function (args) {
|
function (args) {
|
||||||
args = args[0];
|
args = args.literalArg.trim();
|
||||||
|
function fmt(value) (typeof value == "number" ? "#" :
|
||||||
if (!args) {
|
typeof value == "function" ? "*" :
|
||||||
|
" ") + value;
|
||||||
|
if (!args || args == "g:") {
|
||||||
let str =
|
let str =
|
||||||
<table>
|
<table>
|
||||||
{
|
{
|
||||||
template.map(dactyl.globalVariables, function ([i, value]) {
|
template.map(dactyl.globalVariables, function ([i, value]) {
|
||||||
let prefix = typeof value == "number" ? "#" :
|
|
||||||
typeof value == "function" ? "*" :
|
|
||||||
" ";
|
|
||||||
return <tr>
|
return <tr>
|
||||||
<td style="width: 200px;">{i}</td>
|
<td style="width: 200px;">{i}</td>
|
||||||
<td>{prefix}{value}</td>
|
<td>{fmt(value)}</td>
|
||||||
</tr>;
|
</tr>;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -1231,49 +1233,41 @@ const Options = Module("options", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 - type, 2 - name, 3 - +-., 4 - expr
|
let matches = args.match(/^([a-z]:)?([\w]+)(?:\s*([-+.])?=\s*(.*)?)?$/);
|
||||||
let matches = args.match(/([$@&])?([\w:]+)\s*([-+.])?=\s*(.+)/);
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
let [, type, name, stuff, expr] = matches;
|
let [, scope, name, op, expr] = matches;
|
||||||
if (!type) {
|
let fullName = (scope || "") + name;
|
||||||
let reference = dactyl.variableReference(name);
|
|
||||||
dactyl.assert(reference[0] || !stuff,
|
|
||||||
"E121: Undefined variable: " + name);
|
|
||||||
|
|
||||||
expr = dactyl.evalExpression(expr);
|
dactyl.assert(scope == "g:" || scope == null,
|
||||||
dactyl.assert(expr !== undefined, "E15: Invalid expression: " + expr);
|
"E461: Illegal variable name: " + scope + name);
|
||||||
|
dactyl.assert(dactyl.globalVariables.hasOwnProperty(name) || (expr && !op),
|
||||||
|
"E121: Undefined variable: " + fullName);
|
||||||
|
|
||||||
if (!reference[0]) {
|
if (!expr)
|
||||||
if (reference[2] == "g")
|
dactyl.echo(fullName + "\t\t" + fmt(dactyl.globalVariables[name]));
|
||||||
reference[0] = dactyl.globalVariables;
|
else {
|
||||||
|
try {
|
||||||
|
var newValue = dactyl.userEval(expr);
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
dactyl.assert(newValue !== undefined,
|
||||||
|
"E15: Invalid expression: " + expr);
|
||||||
|
|
||||||
|
let value = newValue;
|
||||||
|
if (op) {
|
||||||
|
value = dactyl.globalVariables[name];
|
||||||
|
if (op == "+")
|
||||||
|
value += newValue;
|
||||||
|
else if (op == "-")
|
||||||
|
value -= newValue;
|
||||||
|
else if (op == ".")
|
||||||
|
value += String(newValue);
|
||||||
|
}
|
||||||
|
dactyl.globalVariables[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return; // for now
|
dactyl.echoerr("E18: Unexpected characters in :let");
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
literal: 0
|
literal: 0
|
||||||
@@ -1338,18 +1332,20 @@ const Options = Module("options", {
|
|||||||
}, params.extra || {}));
|
}, params.extra || {}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO: deprecated. This needs to support "g:"-prefixed globals at a
|
||||||
|
// minimum for now.
|
||||||
commands.add(["unl[et]"],
|
commands.add(["unl[et]"],
|
||||||
"Delete a variable",
|
"Delete a variable",
|
||||||
function (args) {
|
function (args) {
|
||||||
for (let [, name] in args) {
|
for (let [, name] in args) {
|
||||||
let reference = dactyl.variableReference(name);
|
name = name.replace(/^g:/, ""); // throw away the scope prefix
|
||||||
if (!reference[0]) {
|
if (!dactyl.globalVariables.hasOwnProperty(name)) {
|
||||||
if (!args.bang)
|
if (!args.bang)
|
||||||
dactyl.echoerr("E108: No such variable: " + name);
|
dactyl.echoerr("E108: No such variable: " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete reference[0][reference[1]];
|
delete dactyl.globalVariables[name];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ BUGS:
|
|||||||
FEATURES:
|
FEATURES:
|
||||||
9 Add quoting help tag
|
9 Add quoting help tag
|
||||||
8 Document Caret and Visual modes.
|
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 fix local options
|
||||||
8 adaptive timeout for auto-completions, :set completions can be updated more often than
|
8 adaptive timeout for auto-completions, :set completions can be updated more often than
|
||||||
:open foo
|
:open foo
|
||||||
|
|||||||
Reference in New Issue
Block a user