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

Fix :com -complete. Allow directly specifying static completion results. Allow command aliases separated by commas.

This commit is contained in:
Kris Maglione
2011-01-19 05:44:27 -05:00
parent c3ff9950bb
commit e594e4ca35
2 changed files with 13 additions and 12 deletions

View File

@@ -1049,7 +1049,7 @@ var Commands = Module("commands", {
]]>) ]]>)
}), }),
validName: Class.memoize(function () RegExp("^" + this.nameRegexp.source + "$")), validName: Class.memoize(function () util.regexp("^" + this.nameRegexp.source + "$")),
commandRegexp: Class.memoize(function () util.regexp(<![CDATA[ commandRegexp: Class.memoize(function () util.regexp(<![CDATA[
^ ^
@@ -1277,7 +1277,8 @@ var Commands = Module("commands", {
function (args) { function (args) {
let cmd = args[0]; let cmd = args[0];
dactyl.assert(!cmd || commands.validName.test(cmd), "E182: Invalid command name"); dactyl.assert(!cmd || cmd.split(",").every(commands.validName.closure.test),
"E182: Invalid command name");
if (args.literalArg) { if (args.literalArg) {
let completer = args["-complete"]; let completer = args["-complete"];
@@ -1286,12 +1287,9 @@ var Commands = Module("commands", {
if (completer) { if (completer) {
if (/^custom,/.test(completer)) { if (/^custom,/.test(completer)) {
completer = completer.substr(7); completer = completer.substr(7);
completerFunc = function () { completerFunc = function (context) {
try { try {
var completer = dactyl.userEval(completer); var result = dactyl.userEval(completer);
if (!callable(completer))
throw new TypeError("User-defined custom completer " + completer.quote() + " is not a function");
} }
catch (e) { catch (e) {
dactyl.echo(":" + this.name + " ..."); dactyl.echo(":" + this.name + " ...");
@@ -1299,14 +1297,17 @@ var Commands = Module("commands", {
dactyl.log(e); dactyl.log(e);
return undefined; return undefined;
} }
return completer.apply(this, Array.slice(arguments)); if (callable(result))
return result.apply(this, Array.slice(arguments));
else
return context.completions = result;
}; };
} }
else else
completerFunc = function (context) completion.closure[completerMap[completer]](context); completerFunc = function (context) completion.closure[completerMap[completer]](context);
} }
let added = commands.addUserCommand([cmd], let added = commands.addUserCommand(cmd.split(","),
args["-description"], args["-description"],
Command.bindMacro(args, "-ex", Command.bindMacro(args, "-ex",
function makeParams(args, modifiers) ({ function makeParams(args, modifiers) ({
@@ -1368,7 +1369,7 @@ var Commands = Module("commands", {
description: "The argument completion function", description: "The argument completion function",
completer: function (context) [[k, ""] for ([k, v] in Iterator(completerMap))], completer: function (context) [[k, ""] for ([k, v] in Iterator(completerMap))],
type: CommandOption.STRING, type: CommandOption.STRING,
validator: function (arg) arg in completerMap || /custom,\w+/.test(arg), validator: function (arg) arg in completerMap || /^custom,/.test(arg),
}, { }, {
names: ["-description", "-desc", "-d"], names: ["-description", "-desc", "-d"],
description: "A user-visible description of the command", description: "A user-visible description of the command",

View File

@@ -17,6 +17,8 @@ var Config = Module("config", ConfigBase, {
Local: function Local(dactyl, modules, window) Local: function Local(dactyl, modules, window)
let ({ config } = modules) ({ let ({ config } = modules) ({
completers: Class.memoize(function () update({ sidebar: "sidebar", window: "window" }, this.__proto__.completers)),
dialogs: { dialogs: {
about: ["About Firefox", about: ["About Firefox",
function () { window.openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }], function () { window.openDialog("chrome://browser/content/aboutDialog.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
@@ -126,8 +128,6 @@ var Config = Module("config", ConfigBase, {
Leave: "Triggered before exiting Firefox" Leave: "Triggered before exiting Firefox"
}, },
completers: Class.memoize(function () update({ sidebar: "sidebar", window: "window" }, this.__proto__.completers)),
defaults: { defaults: {
complete: "slf", complete: "slf",
guioptions: "bCrs", guioptions: "bCrs",