1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 10:47:59 +01:00

Serialize :loadplugins command so that options and commands defined by plugins work properly by default.

This commit is contained in:
Kris Maglione
2010-12-22 23:33:57 -05:00
parent 8d9c2cddc0
commit 6cb1c1d659
5 changed files with 37 additions and 14 deletions

View File

@@ -296,6 +296,7 @@ const Command = Class("Command", {
* invocation which should be restored on subsequent @dactyl startups. * invocation which should be restored on subsequent @dactyl startups.
*/ */
serialize: null, serialize: null,
serialGroup: 50,
/** /**
* @property {number} If this command takes another ex command as an * @property {number} If this command takes another ex command as an
* argument, the index of that argument. Used in determining whether to * argument, the index of that argument. Used in determining whether to
@@ -447,7 +448,7 @@ const Commands = Module("commands", {
/** @property {Iterator(Command)} @private */ /** @property {Iterator(Command)} @private */
__iterator__: function () { __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); return array.iterValues(sorted);
}, },

View File

@@ -818,12 +818,16 @@ const Dactyl = Module("dactyl", {
function globalVariables() this._globalVariables) function globalVariables() this._globalVariables)
}), }),
loadPlugins: function () { loadPlugins: function (args) {
function sourceDirectory(dir) { function sourceDirectory(dir) {
dactyl.assert(dir.isReadable(), "E484: Can't open file " + dir.path); dactyl.assert(dir.isReadable(), "E484: Can't open file " + dir.path);
dactyl.log("Sourcing plugin directory: " + dir.path + "...", 3); dactyl.log("Sourcing plugin directory: " + dir.path + "...", 3);
let loadplugins = options.get("loadplugins"); let loadplugins = options.get("loadplugins");
if (args)
loadplugins = { __proto__: loadplugins, value: args.map(Option.parseRegexp) }
dir.readDirectory(true).forEach(function (file) { dir.readDirectory(true).forEach(function (file) {
if (file.isFile() && loadplugins.getKey(file.path) && !(file.path in dactyl.pluginFiles)) { if (file.isFile() && loadplugins.getKey(file.path) && !(file.path in dactyl.pluginFiles)) {
try { try {
@@ -1786,8 +1790,20 @@ const Dactyl = Module("dactyl", {
commands.add(["loadplugins", "lpl"], commands.add(["loadplugins", "lpl"],
"Load all plugins immediately", "Load all plugins immediately",
function () { dactyl.loadPlugins(); }, function (args) {
{ argCount: "0" }); dactyl.loadPlugins(args.length ? args : null);
},
{
argCount: "*",
keepQuotes: true,
serialGroup: 10,
serialize: function () [
{
command: this.name,
literalArg: options["loadplugins"].join(" ")
}
]
});
commands.add(["norm[al]"], commands.add(["norm[al]"],
"Execute Normal mode commands", "Execute Normal mode commands",

View File

@@ -1031,7 +1031,7 @@ const Events = Module("events", {
dactyl.trapErrors(commandline.onEvent, commandline, event); dactyl.trapErrors(commandline.onEvent, commandline, event);
} }
// Unconsumed events // Reprocess unconsumed events
for (let event in values(res.slice(1))) for (let event in values(res.slice(1)))
if (!event.skipmap) if (!event.skipmap)
if (event.originalTarget) if (event.originalTarget)
@@ -1056,9 +1056,8 @@ const Events = Module("events", {
const self = this; const self = this;
let key = events.toString(event); let key = events.toString(event);
let inputStr = this.buffer + key; let [, countStr, candidateCommand] = /^((?:[1-9][0-9]*)?)(.*)/.exec(this.buffer + key);
let countStr = inputStr.match(/^[1-9][0-9]*|/)[0];
let candidateCommand = inputStr.substr(countStr.length);
let map = mappings[event.noremap ? "getDefault" : "get"](this.main, candidateCommand); let map = mappings[event.noremap ? "getDefault" : "get"](this.main, candidateCommand);
function execute(map) { function execute(map) {
@@ -1104,9 +1103,8 @@ const Events = Module("events", {
if (isNaN(this[count])) if (isNaN(this[count]))
this[count] = null; this[count] = null;
this.buffer = "";
if (map.arg) { if (map.arg) {
this.buffer = inputStr; this.append(event);
this.pendingArgMap = map; this.pendingArgMap = map;
} }
else if (this.pendingMotionMap) { else if (this.pendingMotionMap) {
@@ -1114,9 +1112,10 @@ const Events = Module("events", {
execute(this.pendingMotionMap, candidateCommand, this.motionCount || this.count, null); execute(this.pendingMotionMap, candidateCommand, this.motionCount || this.count, null);
return true; return true;
} }
// no count support for these commands yet else if (map.motion) {
else if (map.motion) this.buffer = "";
this.pendingMotionMap = map; this.pendingMotionMap = map;
}
else { else {
if (modes.isReplaying && !this.waitForPageLoad()) if (modes.isReplaying && !this.waitForPageLoad())
return true; return true;
@@ -1126,8 +1125,8 @@ const Events = Module("events", {
} }
} }
else if (mappings.getCandidates(this.main, candidateCommand).length > 0 && !event.skipmap) { else if (mappings.getCandidates(this.main, candidateCommand).length > 0 && !event.skipmap) {
this.pendingMap = map;
this.append(event); this.append(event);
this.pendingMap = map;
} }
else { else {
this.append(event); this.append(event);

View File

@@ -391,6 +391,9 @@ const Option = Class("Option", {
}, },
parseRegexp: function (value, result, flags) { parseRegexp: function (value, result, flags) {
if (isArray(flags)) // Called by map
result = flags = undefined;
let [, bang, val] = /^(!?)(.*)/.exec(value); let [, bang, val] = /^(!?)(.*)/.exec(value);
let re = RegExp(Option.dequote(val), flags); let re = RegExp(Option.dequote(val), flags);
re.bang = bang; re.bang = bang;

View File

@@ -183,7 +183,7 @@
<item> <item>
<tags>:lpl :loadplugins</tags> <tags>:lpl :loadplugins</tags>
<strut/> <strut/>
<spec>:loadplugins</spec> <spec>:loadplugins <oa>pattern</oa></spec>
<description> <description>
<p> <p>
Immediately load all plugins which have yet to be loaded. Because Immediately load all plugins which have yet to be loaded. Because
@@ -194,6 +194,10 @@
newly installed plugins to be easily loaded without restarting newly installed plugins to be easily loaded without restarting
&dactyl.appName;. See also <o>loadplugins</o>. &dactyl.appName;. See also <o>loadplugins</o>.
</p> </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> </description>
</item> </item>