mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 20:12:27 +01:00
Deprecate :let and dactyl.globalVariables.
This commit is contained in:
@@ -131,6 +131,11 @@ const Command = Class("Command", {
|
||||
* @param {Object} modifiers Any modifiers to be passed to {@link #action}.
|
||||
*/
|
||||
execute: function (args, modifiers) {
|
||||
if (this.deprecated) {
|
||||
let loc = io.sourcing ? io.sourcing.file + ":" + io.sourcing.line + ": " : "";
|
||||
dactyl.echoerr(loc + ":" + this.name + " is deprecated");
|
||||
}
|
||||
|
||||
let self = this;
|
||||
modifiers = modifiers || {};
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"modules",
|
||||
"storage",
|
||||
"util",
|
||||
"dactyl",
|
||||
"modes",
|
||||
"abbreviations",
|
||||
"autocommands",
|
||||
@@ -55,7 +56,6 @@
|
||||
"completion",
|
||||
"configbase",
|
||||
"config",
|
||||
"dactyl",
|
||||
"editor",
|
||||
"events",
|
||||
"finder",
|
||||
|
||||
@@ -25,6 +25,19 @@ const FailedAssertion = Class("FailedAssertion", Error, {
|
||||
}
|
||||
});
|
||||
|
||||
deprecated.seen = {};
|
||||
function deprecated(fn)
|
||||
function deprecatedMethod() {
|
||||
let frame = Components.stack.caller;
|
||||
let caller = frame.filename + ":" + frame.lineNumber;
|
||||
if (frame.filename != "chrome://dactyl/content/javascript.js" &&
|
||||
!set.add(deprecated.seen, caller))
|
||||
dactyl.echoerr(caller + ": " +
|
||||
(this.className || this.constructor.className) + "." + fn.name +
|
||||
" is deprecated");
|
||||
return fn.apply(this, arguments);
|
||||
}
|
||||
|
||||
const Dactyl = Module("dactyl", {
|
||||
init: function () {
|
||||
window.dactyl = this;
|
||||
@@ -689,7 +702,10 @@ const Dactyl = Module("dactyl", {
|
||||
*
|
||||
* These are set and accessed with the "g:" prefix.
|
||||
*/
|
||||
globalVariables: {},
|
||||
_globalVariables: {},
|
||||
globalVariables: Class.Property({
|
||||
get: deprecated(function globalVariables() this._globalVariables)
|
||||
}),
|
||||
|
||||
loadPlugins: function () {
|
||||
function sourceDirectory(dir) {
|
||||
|
||||
@@ -406,6 +406,14 @@
|
||||
<span dactyl:highlight="HelpOptionalArg">[<xsl:apply-templates select="@*|node()" mode="help-1"/>]</span>
|
||||
</xsl:template>
|
||||
|
||||
<xsl:template match="dactyl:deprecated" mode="help-2">
|
||||
<p style="clear: both;">
|
||||
<xsl:apply-templates select="@*" mode="help-1"/>
|
||||
<span dactyl:highlight="HelpWarning">Deprecated:</span>
|
||||
<xsl:text> </xsl:text>
|
||||
<xsl:apply-templates select="node()" mode="help-1"/>
|
||||
</p>
|
||||
</xsl:template>
|
||||
<xsl:template match="dactyl:note" mode="help-2">
|
||||
<p style="clear: both;">
|
||||
<xsl:apply-templates select="@*" mode="help-1"/>
|
||||
|
||||
@@ -1246,6 +1246,7 @@ const Options = Module("options", {
|
||||
commands.add(["let"],
|
||||
"Set or list a variable",
|
||||
function (args) {
|
||||
let globalVariables = dactyl._globalVariables;
|
||||
args = (args[0] || "").trim();
|
||||
function fmt(value) (typeof value == "number" ? "#" :
|
||||
typeof value == "function" ? "*" :
|
||||
@@ -1254,7 +1255,7 @@ const Options = Module("options", {
|
||||
let str =
|
||||
<table>
|
||||
{
|
||||
template.map(dactyl.globalVariables, function ([i, value]) {
|
||||
template.map(globalVariables, function ([i, value]) {
|
||||
return <tr>
|
||||
<td style="width: 200px;">{i}</td>
|
||||
<td>{fmt(value)}</td>
|
||||
@@ -1276,11 +1277,11 @@ const Options = Module("options", {
|
||||
|
||||
dactyl.assert(scope == "g:" || scope == null,
|
||||
"E461: Illegal variable name: " + scope + name);
|
||||
dactyl.assert(dactyl.globalVariables.hasOwnProperty(name) || (expr && !op),
|
||||
dactyl.assert(globalVariables.hasOwnProperty(name) || (expr && !op),
|
||||
"E121: Undefined variable: " + fullName);
|
||||
|
||||
if (!expr)
|
||||
dactyl.echo(fullName + "\t\t" + fmt(dactyl.globalVariables[name]));
|
||||
dactyl.echo(fullName + "\t\t" + fmt(globalVariables[name]));
|
||||
else {
|
||||
try {
|
||||
var newValue = dactyl.userEval(expr);
|
||||
@@ -1291,7 +1292,7 @@ const Options = Module("options", {
|
||||
|
||||
let value = newValue;
|
||||
if (op) {
|
||||
value = dactyl.globalVariables[name];
|
||||
value = globalVariables[name];
|
||||
if (op == "+")
|
||||
value += newValue;
|
||||
else if (op == "-")
|
||||
@@ -1299,13 +1300,14 @@ const Options = Module("options", {
|
||||
else if (op == ".")
|
||||
value += String(newValue);
|
||||
}
|
||||
dactyl.globalVariables[name] = value;
|
||||
globalVariables[name] = value;
|
||||
}
|
||||
}
|
||||
else
|
||||
dactyl.echoerr("E18: Unexpected characters in :let");
|
||||
},
|
||||
{
|
||||
deprecated: true,
|
||||
literal: 0
|
||||
}
|
||||
);
|
||||
@@ -1386,7 +1388,8 @@ const Options = Module("options", {
|
||||
},
|
||||
{
|
||||
argCount: "+",
|
||||
bang: true
|
||||
bang: true,
|
||||
deprecated: true
|
||||
});
|
||||
},
|
||||
completion: function () {
|
||||
|
||||
@@ -140,6 +140,9 @@
|
||||
<spec>:let <a>var-name</a></spec>
|
||||
<spec>:let</spec>
|
||||
<description>
|
||||
<deprecated>All scripts which make use of <ex>:let</ex> should be
|
||||
updated to use the simpler and more powerful options system
|
||||
instead.</deprecated>
|
||||
<p>
|
||||
Sets or lists a variable. Sets the variable <a>var-name</a> to the value of the
|
||||
expression <a>expr1</a>. If no expression is given, the value of the variable is
|
||||
@@ -153,6 +156,9 @@
|
||||
<tags>:unl :unlet</tags>
|
||||
<spec>:unl<oa>et</oa><oa>!</oa> <a>name</a> …</spec>
|
||||
<description>
|
||||
<deprecated>All scripts which make use of <ex>:let</ex> should be
|
||||
updated to use the simpler and more powerful options system
|
||||
instead.</deprecated>
|
||||
<p>
|
||||
Deletes the named variables. When <oa>!</oa> is given, no error
|
||||
message is output for non-existing variables.
|
||||
|
||||
Reference in New Issue
Block a user