mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 21:37:57 +01:00
Serialize :loadplugins command so that options and commands defined by plugins work properly by default.
This commit is contained in:
@@ -296,6 +296,7 @@ const Command = Class("Command", {
|
||||
* invocation which should be restored on subsequent @dactyl startups.
|
||||
*/
|
||||
serialize: null,
|
||||
serialGroup: 50,
|
||||
/**
|
||||
* @property {number} If this command takes another ex command as an
|
||||
* argument, the index of that argument. Used in determining whether to
|
||||
@@ -447,7 +448,7 @@ const Commands = Module("commands", {
|
||||
|
||||
/** @property {Iterator(Command)} @private */
|
||||
__iterator__: function () {
|
||||
let sorted = this._exCommands.sort(function (a, b) a.name > b.name);
|
||||
let sorted = this._exCommands.sort(function (a, b) a.serialGroup - b.serialGroup || a.name > b.name);
|
||||
return array.iterValues(sorted);
|
||||
},
|
||||
|
||||
|
||||
@@ -818,12 +818,16 @@ const Dactyl = Module("dactyl", {
|
||||
function globalVariables() this._globalVariables)
|
||||
}),
|
||||
|
||||
loadPlugins: function () {
|
||||
loadPlugins: function (args) {
|
||||
function sourceDirectory(dir) {
|
||||
dactyl.assert(dir.isReadable(), "E484: Can't open file " + dir.path);
|
||||
|
||||
dactyl.log("Sourcing plugin directory: " + dir.path + "...", 3);
|
||||
|
||||
let loadplugins = options.get("loadplugins");
|
||||
if (args)
|
||||
loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) }
|
||||
|
||||
dir.readDirectory(true).forEach(function (file) {
|
||||
if (file.isFile() && loadplugins.getKey(file.path) && !(file.path in dactyl.pluginFiles)) {
|
||||
try {
|
||||
@@ -1786,8 +1790,20 @@ const Dactyl = Module("dactyl", {
|
||||
|
||||
commands.add(["loadplugins", "lpl"],
|
||||
"Load all plugins immediately",
|
||||
function () { dactyl.loadPlugins(); },
|
||||
{ argCount: "0" });
|
||||
function (args) {
|
||||
dactyl.loadPlugins(args.length ? args : null);
|
||||
},
|
||||
{
|
||||
argCount: "*",
|
||||
keepQuotes: true,
|
||||
serialGroup: 10,
|
||||
serialize: function () [
|
||||
{
|
||||
command: this.name,
|
||||
literalArg: options["loadplugins"].join(" ")
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
commands.add(["norm[al]"],
|
||||
"Execute Normal mode commands",
|
||||
|
||||
@@ -1031,7 +1031,7 @@ const Events = Module("events", {
|
||||
dactyl.trapErrors(commandline.onEvent, commandline, event);
|
||||
}
|
||||
|
||||
// Unconsumed events
|
||||
// Reprocess unconsumed events
|
||||
for (let event in values(res.slice(1)))
|
||||
if (!event.skipmap)
|
||||
if (event.originalTarget)
|
||||
@@ -1056,9 +1056,8 @@ const Events = Module("events", {
|
||||
const self = this;
|
||||
|
||||
let key = events.toString(event);
|
||||
let inputStr = this.buffer + key;
|
||||
let countStr = inputStr.match(/^[1-9][0-9]*|/)[0];
|
||||
let candidateCommand = inputStr.substr(countStr.length);
|
||||
let [, countStr, candidateCommand] = /^((?:[1-9][0-9]*)?)(.*)/.exec(this.buffer + key);
|
||||
|
||||
let map = mappings[event.noremap ? "getDefault" : "get"](this.main, candidateCommand);
|
||||
|
||||
function execute(map) {
|
||||
@@ -1104,9 +1103,8 @@ const Events = Module("events", {
|
||||
if (isNaN(this[count]))
|
||||
this[count] = null;
|
||||
|
||||
this.buffer = "";
|
||||
if (map.arg) {
|
||||
this.buffer = inputStr;
|
||||
this.append(event);
|
||||
this.pendingArgMap = map;
|
||||
}
|
||||
else if (this.pendingMotionMap) {
|
||||
@@ -1114,9 +1112,10 @@ const Events = Module("events", {
|
||||
execute(this.pendingMotionMap, candidateCommand, this.motionCount || this.count, null);
|
||||
return true;
|
||||
}
|
||||
// no count support for these commands yet
|
||||
else if (map.motion)
|
||||
else if (map.motion) {
|
||||
this.buffer = "";
|
||||
this.pendingMotionMap = map;
|
||||
}
|
||||
else {
|
||||
if (modes.isReplaying && !this.waitForPageLoad())
|
||||
return true;
|
||||
@@ -1126,8 +1125,8 @@ const Events = Module("events", {
|
||||
}
|
||||
}
|
||||
else if (mappings.getCandidates(this.main, candidateCommand).length > 0 && !event.skipmap) {
|
||||
this.pendingMap = map;
|
||||
this.append(event);
|
||||
this.pendingMap = map;
|
||||
}
|
||||
else {
|
||||
this.append(event);
|
||||
|
||||
@@ -391,6 +391,9 @@ const Option = Class("Option", {
|
||||
},
|
||||
|
||||
parseRegexp: function (value, result, flags) {
|
||||
if (isArray(flags)) // Called by map
|
||||
result = flags = undefined;
|
||||
|
||||
let [, bang, val] = /^(!?)(.*)/.exec(value);
|
||||
let re = RegExp(Option.dequote(val), flags);
|
||||
re.bang = bang;
|
||||
|
||||
@@ -183,7 +183,7 @@
|
||||
<item>
|
||||
<tags>:lpl :loadplugins</tags>
|
||||
<strut/>
|
||||
<spec>:loadplugins</spec>
|
||||
<spec>:loadplugins <oa>pattern</oa> …</spec>
|
||||
<description>
|
||||
<p>
|
||||
Immediately load all plugins which have yet to be loaded. Because
|
||||
@@ -194,6 +194,10 @@
|
||||
newly installed plugins to be easily loaded without restarting
|
||||
&dactyl.appName;. See also <o>loadplugins</o>.
|
||||
</p>
|
||||
<p>
|
||||
If <oa>pattern</oa>s are provided, the given regular expressions are
|
||||
used as filters rather than those in <o>loadplugins</o>.
|
||||
</p>
|
||||
</description>
|
||||
</item>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user