mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 22:47: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 () {
|
commands: function () {
|
||||||
// TODO: offer completion.ex?
|
let completerMap = config.completers;
|
||||||
// : 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"
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Vim allows commands to be defined without {rep} if there are {attr}s
|
// TODO: Vim allows commands to be defined without {rep} if there are {attr}s
|
||||||
// specified - useful?
|
// specified - useful?
|
||||||
@@ -1288,22 +1276,22 @@ var Commands = Module("commands", {
|
|||||||
dactyl.assert(!cmd || commands.validName.test(cmd), "E182: Invalid command name");
|
dactyl.assert(!cmd || commands.validName.test(cmd), "E182: Invalid command name");
|
||||||
|
|
||||||
if (args.literalArg) {
|
if (args.literalArg) {
|
||||||
let completeOpt = args["-complete"];
|
let completer = args["-complete"];
|
||||||
let completeFunc = null; // default to no completion for user commands
|
let completerFunc = null; // default to no completion for user commands
|
||||||
|
|
||||||
if (completeOpt) {
|
if (completer) {
|
||||||
if (/^custom,/.test(completeOpt)) {
|
if (/^custom,/.test(completer)) {
|
||||||
completeOpt = completeOpt.substr(7);
|
completer = completer.substr(7);
|
||||||
completeFunc = function () {
|
completerFunc = function () {
|
||||||
try {
|
try {
|
||||||
var completer = dactyl.userEval(completeOpt);
|
var completer = dactyl.userEval(completer);
|
||||||
|
|
||||||
if (!callable(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) {
|
catch (e) {
|
||||||
dactyl.echo(":" + this.name + " ...");
|
dactyl.echo(":" + this.name + " ...");
|
||||||
dactyl.echoerr("E117: Unknown function: " + completeOpt);
|
dactyl.echoerr("E117: Unknown function: " + completer);
|
||||||
dactyl.log(e);
|
dactyl.log(e);
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@@ -1311,7 +1299,7 @@ var Commands = Module("commands", {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
completeFunc = completion.closure[completeOptionMap[completeOpt]];
|
completerFunc = function (context) completion.closure[completerMap[completer]](context);
|
||||||
}
|
}
|
||||||
|
|
||||||
let added = commands.addUserCommand([cmd],
|
let added = commands.addUserCommand([cmd],
|
||||||
@@ -1326,7 +1314,7 @@ var Commands = Module("commands", {
|
|||||||
argCount: args["-nargs"],
|
argCount: args["-nargs"],
|
||||||
bang: args["-bang"],
|
bang: args["-bang"],
|
||||||
count: args["-count"],
|
count: args["-count"],
|
||||||
completer: function (context) completeFunc(context),
|
completer: completerFunc,
|
||||||
persist: !args["-nopersist"],
|
persist: !args["-nopersist"],
|
||||||
replacementText: args.literalArg,
|
replacementText: args.literalArg,
|
||||||
sourcing: io.sourcing && update({}, io.sourcing)
|
sourcing: io.sourcing && update({}, io.sourcing)
|
||||||
@@ -1338,13 +1326,11 @@ var Commands = Module("commands", {
|
|||||||
else {
|
else {
|
||||||
function completerToString(completer) {
|
function completerToString(completer) {
|
||||||
if (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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: using an array comprehension here generates flakey results across repeated calls
|
// TODO: perhaps we shouldn't allow options in a list call but just ignore them for now
|
||||||
// : 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
|
|
||||||
let cmds = commands._exCommands.filter(function (c) c.user && (!cmd || c.name.match("^" + cmd)));
|
let cmds = commands._exCommands.filter(function (c) c.user && (!cmd || c.name.match("^" + cmd)));
|
||||||
|
|
||||||
if (cmds.length > 0)
|
if (cmds.length > 0)
|
||||||
@@ -1376,9 +1362,9 @@ var Commands = Module("commands", {
|
|||||||
// TODO: "E180: invalid complete value: " + arg
|
// TODO: "E180: invalid complete value: " + arg
|
||||||
names: ["-complete", "-C"],
|
names: ["-complete", "-C"],
|
||||||
description: "The argument completion function",
|
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,
|
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"],
|
names: ["-description", "-desc", "-d"],
|
||||||
description: "A user-visible description of the command",
|
description: "A user-visible description of the command",
|
||||||
|
|||||||
@@ -610,32 +610,7 @@
|
|||||||
-complete option when defining the command.
|
-complete option when defining the command.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<dl>
|
<dl tag=":command-complete-arg-list"/>
|
||||||
<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>
|
|
||||||
|
|
||||||
<h3 tag="E467 E468 :command-completion-custom">Custom completion</h3>
|
<h3 tag="E467 E468 :command-completion-custom">Custom completion</h3>
|
||||||
|
|
||||||
|
|||||||
@@ -98,6 +98,43 @@ var ConfigBase = Class("ConfigBase", {
|
|||||||
|
|
||||||
commandContainer: "browser-bottombox",
|
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 {Object} Application specific defaults for option values. The
|
||||||
* property names must be the options' canonical names, and the values
|
* 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"
|
Leave: "Triggered before exiting Songbird"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
completers: Class.memoize(function () update({
|
||||||
|
displaypane: "displayPane",
|
||||||
|
playlist: "playlist",
|
||||||
|
mediaview: "mediaView",
|
||||||
|
mediasort: "mediaListSort",
|
||||||
|
song: "song"
|
||||||
|
}, this.__proto__.completers)),
|
||||||
|
|
||||||
dialogs: {
|
dialogs: {
|
||||||
about: ["About Songbird",
|
about: ["About Songbird",
|
||||||
function () { window.openDialog("chrome://songbird/content/xul/about.xul", "_blank", "chrome,dialog,modal,centerscreen"); }],
|
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"
|
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",
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ const Config = Module("config", ConfigBase, {
|
|||||||
|
|
||||||
get browser() getBrowser(),
|
get browser() getBrowser(),
|
||||||
|
|
||||||
|
completers: Class.memoize(function () update({ mailfolder: "mailFolder" }, this.__proto__.completers)),
|
||||||
|
|
||||||
dialogs: {
|
dialogs: {
|
||||||
about: ["About Thunderbird",
|
about: ["About Thunderbird",
|
||||||
function () { window.openAboutDialog(); }],
|
function () { window.openAboutDialog(); }],
|
||||||
|
|||||||
Reference in New Issue
Block a user