mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 12:07:59 +01:00
Make the :command-complete completers config specific.
Adds a few missing completers for Pentadactyl.
This commit is contained in:
@@ -1264,19 +1264,7 @@ var Commands = Module("commands", {
|
||||
},
|
||||
|
||||
commands: function () {
|
||||
// TODO: offer completion.ex?
|
||||
// : make this config specific
|
||||
var completeOptionMap = {
|
||||
abbreviation: "abbreviation", altstyle: "alternateStyleSheet",
|
||||
bookmark: "bookmark", buffer: "buffer", color: "colorScheme",
|
||||
command: "command", dialog: "dialog", dir: "directory",
|
||||
environment: "environment", event: "autocmdEvent", file: "file",
|
||||
help: "help", highlight: "highlightGroup", history: "history",
|
||||
javascript: "javascript", macro: "macro", mapping: "userMapping",
|
||||
menu: "menuItem", option: "option", preference: "preference",
|
||||
search: "search", shellcmd: "shellCommand", sidebar: "sidebar",
|
||||
url: "url", usercommand: "userCommand"
|
||||
};
|
||||
let completerMap = config.completers;
|
||||
|
||||
// TODO: Vim allows commands to be defined without {rep} if there are {attr}s
|
||||
// specified - useful?
|
||||
@@ -1288,22 +1276,22 @@ var Commands = Module("commands", {
|
||||
dactyl.assert(!cmd || commands.validName.test(cmd), "E182: Invalid command name");
|
||||
|
||||
if (args.literalArg) {
|
||||
let completeOpt = args["-complete"];
|
||||
let completeFunc = null; // default to no completion for user commands
|
||||
let completer = args["-complete"];
|
||||
let completerFunc = null; // default to no completion for user commands
|
||||
|
||||
if (completeOpt) {
|
||||
if (/^custom,/.test(completeOpt)) {
|
||||
completeOpt = completeOpt.substr(7);
|
||||
completeFunc = function () {
|
||||
if (completer) {
|
||||
if (/^custom,/.test(completer)) {
|
||||
completer = completer.substr(7);
|
||||
completerFunc = function () {
|
||||
try {
|
||||
var completer = dactyl.userEval(completeOpt);
|
||||
var completer = dactyl.userEval(completer);
|
||||
|
||||
if (!callable(completer))
|
||||
throw new TypeError("User-defined custom completer " + completeOpt.quote() + " is not a function");
|
||||
throw new TypeError("User-defined custom completer " + completer.quote() + " is not a function");
|
||||
}
|
||||
catch (e) {
|
||||
dactyl.echo(":" + this.name + " ...");
|
||||
dactyl.echoerr("E117: Unknown function: " + completeOpt);
|
||||
dactyl.echoerr("E117: Unknown function: " + completer);
|
||||
dactyl.log(e);
|
||||
return undefined;
|
||||
}
|
||||
@@ -1311,7 +1299,7 @@ var Commands = Module("commands", {
|
||||
};
|
||||
}
|
||||
else
|
||||
completeFunc = completion.closure[completeOptionMap[completeOpt]];
|
||||
completerFunc = function (context) completion.closure[completerMap[completer]](context);
|
||||
}
|
||||
|
||||
let added = commands.addUserCommand([cmd],
|
||||
@@ -1326,7 +1314,7 @@ var Commands = Module("commands", {
|
||||
argCount: args["-nargs"],
|
||||
bang: args["-bang"],
|
||||
count: args["-count"],
|
||||
completer: function (context) completeFunc(context),
|
||||
completer: completerFunc,
|
||||
persist: !args["-nopersist"],
|
||||
replacementText: args.literalArg,
|
||||
sourcing: io.sourcing && update({}, io.sourcing)
|
||||
@@ -1338,13 +1326,11 @@ var Commands = Module("commands", {
|
||||
else {
|
||||
function completerToString(completer) {
|
||||
if (completer)
|
||||
return [k for ([k, v] in Iterator(completeOptionMap)) if (completer == completion.closure[v])][0] || "custom";
|
||||
return [k for ([k, v] in Iterator(completerMap)) if (completer == completion.closure[v])][0] || "custom";
|
||||
return "";
|
||||
}
|
||||
|
||||
// TODO: using an array comprehension here generates flakey results across repeated calls
|
||||
// : perhaps we shouldn't allow options in a list call but just ignore them for now
|
||||
// : No, array comprehensions are fine, generator statements aren't. --Kris
|
||||
// TODO: perhaps we shouldn't allow options in a list call but just ignore them for now
|
||||
let cmds = commands._exCommands.filter(function (c) c.user && (!cmd || c.name.match("^" + cmd)));
|
||||
|
||||
if (cmds.length > 0)
|
||||
@@ -1376,9 +1362,9 @@ var Commands = Module("commands", {
|
||||
// TODO: "E180: invalid complete value: " + arg
|
||||
names: ["-complete", "-C"],
|
||||
description: "The argument completion function",
|
||||
completer: function (context) [[k, ""] for ([k, v] in Iterator(completeOptionMap))],
|
||||
completer: function (context) [[k, ""] for ([k, v] in Iterator(completerMap))],
|
||||
type: CommandOption.STRING,
|
||||
validator: function (arg) arg in completeOptionMap || /custom,\w+/.test(arg),
|
||||
validator: function (arg) arg in completerMap || /custom,\w+/.test(arg),
|
||||
}, {
|
||||
names: ["-description", "-desc", "-d"],
|
||||
description: "A user-visible description of the command",
|
||||
|
||||
@@ -610,32 +610,7 @@
|
||||
-complete option when defining the command.
|
||||
</p>
|
||||
|
||||
<dl>
|
||||
<dt>altstyle</dt> <dd>alternate author style sheets</dd>
|
||||
<dt>bookmark</dt> <dd>bookmarks</dd>
|
||||
<dt>buffer</dt> <dd>buffers</dd>
|
||||
<dt>color</dt> <dd>color schemes</dd>
|
||||
<dt>command</dt> <dd>Ex commands</dd>
|
||||
<dt>dialog</dt> <dd>&dactyl.host; dialogs</dd>
|
||||
<dt>dir</dt> <dd>directories</dd>
|
||||
<dt>environment</dt> <dd>environment variables</dd>
|
||||
<dt>event</dt> <dd>autocommand events</dd>
|
||||
<dt>file</dt> <dd>files</dd>
|
||||
<dt>help</dt> <dd>help tags</dd>
|
||||
<dt>highlight</dt> <dd>highlight groups</dd>
|
||||
<dt>javascript</dt> <dd>JavaScript expressions</dd>
|
||||
<dt>macro</dt> <dd>named macros</dd>
|
||||
<dt>mapping</dt> <dd>user mappings</dd>
|
||||
<dt>menu</dt> <dd>menu items</dd>
|
||||
<dt>option</dt> <dd>&dactyl.appName; options</dd>
|
||||
<dt>preference</dt> <dd>&dactyl.host; preferences</dd>
|
||||
<dt>search</dt> <dd>search engines and keywords</dd>
|
||||
<dt>shellcmd</dt> <dd>shell commands</dd>
|
||||
<dt>sidebar</dt> <dd>sidebar panels</dd>
|
||||
<dt>url</dt> <dd>URLs</dd>
|
||||
<dt>usercommand</dt> <dd>user commands</dd>
|
||||
<dt>custom,<a>func</a></dt><dd>custom completion, provided by <a>func</a></dd>
|
||||
</dl>
|
||||
<dl tag=":command-complete-arg-list"/>
|
||||
|
||||
<h3 tag="E467 E468 :command-completion-custom">Custom completion</h3>
|
||||
|
||||
|
||||
@@ -98,6 +98,43 @@ var ConfigBase = Class("ConfigBase", {
|
||||
|
||||
commandContainer: "browser-bottombox",
|
||||
|
||||
/**
|
||||
* @property {Object} A map of :command-complete option values to completer
|
||||
* function names.
|
||||
*/
|
||||
completers: {
|
||||
abbreviation: "abbreviation",
|
||||
altstyle: "alternateStyleSheet",
|
||||
bookmark: "bookmark",
|
||||
buffer: "buffer",
|
||||
charset: "charset",
|
||||
color: "colorScheme",
|
||||
command: "command",
|
||||
dialog: "dialog",
|
||||
dir: "directory",
|
||||
environment: "environment",
|
||||
event: "autocmdEvent",
|
||||
extension: "extension",
|
||||
file: "file",
|
||||
help: "help",
|
||||
highlight: "highlightGroup",
|
||||
history: "history",
|
||||
javascript: "javascript",
|
||||
macro: "macro",
|
||||
mapping: "userMapping",
|
||||
mark: "mark",
|
||||
menu: "menuItem",
|
||||
option: "option",
|
||||
preference: "preference",
|
||||
qmark: "quickmark",
|
||||
runtime: "runtime",
|
||||
search: "search",
|
||||
shellcmd: "shellCommand",
|
||||
toolbar: "toolbar",
|
||||
url: "url",
|
||||
usercommand: "userCommand"
|
||||
},
|
||||
|
||||
/**
|
||||
* @property {Object} Application specific defaults for option values. The
|
||||
* property names must be the options' canonical names, and the values
|
||||
|
||||
@@ -63,6 +63,14 @@ const Config = Module("config", ConfigBase, {
|
||||
Leave: "Triggered before exiting Songbird"
|
||||
},
|
||||
|
||||
completers: Class.memoize(function () update({
|
||||
displaypane: "displayPane",
|
||||
playlist: "playlist",
|
||||
mediaview: "mediaView",
|
||||
mediasort: "mediaListSort",
|
||||
song: "song"
|
||||
}, this.__proto__.completers)),
|
||||
|
||||
dialogs: {
|
||||
about: ["About Songbird",
|
||||
function () { window.openDialog("chrome://songbird/content/xul/about.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
|
||||
|
||||
@@ -126,6 +126,8 @@ var Config = Module("config", ConfigBase, {
|
||||
Leave: "Triggered before exiting Firefox"
|
||||
},
|
||||
|
||||
completers: Class.memoize(function () update({ sidebar: "sidebar", window: "window" }, this.__proto__.completers)),
|
||||
|
||||
defaults: {
|
||||
complete: "slf",
|
||||
guioptions: "bCrs",
|
||||
|
||||
@@ -23,6 +23,8 @@ const Config = Module("config", ConfigBase, {
|
||||
|
||||
get browser() getBrowser(),
|
||||
|
||||
completers: Class.memoize(function () update({ mailfolder: "mailFolder" }, this.__proto__.completers)),
|
||||
|
||||
dialogs: {
|
||||
about: ["About Thunderbird",
|
||||
function () { window.openAboutDialog(); }],
|
||||
|
||||
Reference in New Issue
Block a user