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

Replace expression closures (command/option/mapping definitions).

Expression closures are to be axed. See https://bugzil.la/1083458.
This commit is contained in:
Doug Kearns
2015-07-23 01:15:41 +10:00
parent 85eede1ee2
commit 779752d776
33 changed files with 518 additions and 339 deletions

View File

@@ -341,9 +341,9 @@ var Abbreviations = Module("abbreviations", {
identifier: "abbreviate", identifier: "abbreviate",
completer: function (context, args) { completer: function (context, args) {
if (args.length == 1) if (args.length == 1)
return completion.abbreviation(context, modes, args["-group"]); completion.abbreviation(context, modes, args["-group"]);
else if (args["-javascript"]) else if (args["-javascript"])
return completion.javascript(context); completion.javascript(context);
}, },
hereDoc: true, hereDoc: true,
literal: 1, literal: 1,
@@ -354,7 +354,8 @@ var Abbreviations = Module("abbreviations", {
description: "Expand this abbreviation by evaluating its right-hand-side as JavaScript" description: "Expand this abbreviation by evaluating its right-hand-side as JavaScript"
} }
], ],
serialize: function () Ary(abbreviations.userHives) serialize: function () {
return Ary(abbreviations.userHives)
.filter(h => h.persist) .filter(h => h.persist)
.map(hive => [ .map(hive => [
{ {
@@ -369,7 +370,8 @@ var Abbreviations = Module("abbreviations", {
for (abbr of hive.merged) for (abbr of hive.merged)
if (abbr.modesEqual(modes)) if (abbr.modesEqual(modes))
]). ]).
flatten().array flatten().array;
}
}); });
commands.add([ch + "una[bbreviate]"], commands.add([ch + "una[bbreviate]"],
@@ -384,7 +386,9 @@ var Abbreviations = Module("abbreviations", {
}, { }, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context, args) completion.abbreviation(context, modes, args["-group"]), completer: function (context, args) {
completion.abbreviation(context, modes, args["-group"]);
},
literal: 0, literal: 0,
options: [contexts.GroupFlag("abbrevs")] options: [contexts.GroupFlag("abbrevs")]
}); });

View File

@@ -213,9 +213,9 @@ var AutoCommands = Module("autocommands", {
bang: true, bang: true,
completer: function (context, args) { completer: function (context, args) {
if (args.length == 1) if (args.length == 1)
return completion.autocmdEvent(context); completion.autocmdEvent(context);
if (args.length == 3) else if (args.length == 3)
return args["-javascript"] ? completion.javascript(context) : completion.ex(context); args["-javascript"] ? completion.javascript(context) : completion.ex(context);
}, },
hereDoc: true, hereDoc: true,
keepQuotes: true, keepQuotes: true,
@@ -273,7 +273,9 @@ var AutoCommands = Module("autocommands", {
autocommands.trigger(event, { url: uri.spec }); autocommands.trigger(event, { url: uri.spec });
}, { }, {
argCount: "*", // FIXME: kludged for proper error message should be "1". argCount: "*", // FIXME: kludged for proper error message should be "1".
completer: function (context) completion.autocmdEvent(context), completer: function (context) {
completion.autocmdEvent(context);
},
keepQuotes: true keepQuotes: true
}); });
}); });

View File

@@ -516,8 +516,8 @@ var Bookmarks = Module("bookmarks", {
context.completions = [ context.completions = [
[win.document.documentURI, frames.length == 1 ? /*L*/"Current Location" : /*L*/"Frame: " + win.document.title] [win.document.documentURI, frames.length == 1 ? /*L*/"Current Location" : /*L*/"Frame: " + win.document.title]
for (win of frames)]; for (win of frames)];
return;
} }
else
completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] }); completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] });
}, },
options: [keyword, title, tags, post, options: [keyword, title, tags, post,
@@ -525,7 +525,9 @@ var Bookmarks = Module("bookmarks", {
names: ["-charset", "-c"], names: ["-charset", "-c"],
description: "The character encoding of the bookmark", description: "The character encoding of the bookmark",
type: CommandOption.STRING, type: CommandOption.STRING,
completer: function (context) completion.charset(context), completer: function (context) {
completion.charset(context);
},
validator: io.bound.validateCharset validator: io.bound.validateCharset
}, },
{ {
@@ -541,8 +543,7 @@ var Bookmarks = Module("bookmarks", {
function (args) { function (args) {
bookmarks.list(args.join(" "), args["-tags"] || [], args.bang, args["-max"], bookmarks.list(args.join(" "), args["-tags"] || [], args.bang, args["-max"],
{ keyword: args["-keyword"], title: args["-title"] }); { keyword: args["-keyword"], title: args["-title"] });
}, }, {
{
bang: true, bang: true,
completer: function completer(context, args) { completer: function completer(context, args) {
context.filter = args.join(" "); context.filter = args.join(" ");
@@ -584,13 +585,15 @@ var Bookmarks = Module("bookmarks", {
dactyl.echomsg({ message: _("bookmark.deleted", deletedCount) }); dactyl.echomsg({ message: _("bookmark.deleted", deletedCount) });
} }
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function completer(context, args) completer: function completer(context, args) {
completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] }), completion.bookmark(context, args["-tags"], { keyword: args["-keyword"], title: args["-title"] });
domains: function (args) Ary.compact(args.map(util.getHost)), },
domains: function (args) {
return Ary.compact(args.map(util.getHost));
},
literal: 0, literal: 0,
options: [tags, title, keyword], options: [tags, title, keyword],
privateData: true privateData: true
@@ -643,14 +646,21 @@ var Bookmarks = Module("bookmarks", {
{ {
completer: function completer(context) { completer: function completer(context) {
completion.search(context, true); completion.search(context, true);
context.completions = [{ keyword: "", title: "Don't perform searches by default" }].concat(context.completions); context.completions = [{
keyword: "",
title: "Don't perform searches by default"
}].concat(context.completions);
} }
}); });
options.add(["suggestengines"], options.add(["suggestengines"],
"Search engines used for search suggestions", "Search engines used for search suggestions",
"stringlist", "google", "stringlist", "google",
{ completer: function completer(context) completion.searchEngine(context, true) }); {
completer: function completer(context) {
completion.searchEngine(context, true);
}
});
}, },
completion: function initCompletion() { completion: function initCompletion() {

View File

@@ -208,11 +208,14 @@ var Browser = Module("browser", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
commands: function initCommands(dactyl, modules, window) { commands: function initCommands(dactyl, modules, window) {
commands.add(["o[pen]"], commands.add(["o[pen]"],
"Open one or more URLs in the current tab", "Open one or more URLs in the current tab",
function (args) { dactyl.open(args[0] || "about:blank"); }, function (args) {
{ dactyl.open(args[0] || "about:blank");
completer: function (context) completion.url(context), }, {
domains: function (args) Ary.compact(dactyl.parseURLs(args[0] || "") completer: function (context) { completion.url(context); },
.map(url => util.getHost(url))), domains: function (args) {
return Ary.compact(dactyl.parseURLs(args[0] || "")
.map(url => util.getHost(url)));
},
literal: 0, literal: 0,
privateData: true privateData: true
}); });

View File

@@ -1690,7 +1690,9 @@ var CommandLine = Module("commandline", {
function (args) { function (args) {
command.action(CommandLine.echoArgumentToString(args[0] || "", true)); command.action(CommandLine.echoArgumentToString(args[0] || "", true));
}, { }, {
completer: function (context) completion.javascript(context), completer: function (context) {
completion.javascript(context);
},
literal: 0 literal: 0
}); });
}); });
@@ -1723,7 +1725,7 @@ var CommandLine = Module("commandline", {
function (args) { function (args) {
commandline.runSilently(() => { commands.execute(args[0] || "", null, true); }); commandline.runSilently(() => { commands.execute(args[0] || "", null, true); });
}, { }, {
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
subCommand: 0 subCommand: 0
}); });
@@ -1884,17 +1886,17 @@ var CommandLine = Module("commandline", {
options.add(["history", "hi"], options.add(["history", "hi"],
"Number of Ex commands and search patterns to store in the command-line history", "Number of Ex commands and search patterns to store in the command-line history",
"number", 500, "number", 500,
{ validator: function (value) value >= 0 }); { validator: function (value) { return value >= 0; } });
options.add(["maxitems"], options.add(["maxitems"],
"Maximum number of completion items to display at once", "Maximum number of completion items to display at once",
"number", 20, "number", 20,
{ validator: function (value) value >= 1 }); { validator: function (value) { return value >= 1; } });
options.add(["messages", "msgs"], options.add(["messages", "msgs"],
"Number of messages to store in the :messages history", "Number of messages to store in the :messages history",
"number", 100, "number", 100,
{ validator: function (value) value >= 0 }); { validator: function (value) { return value >= 0; } });
}, },
sanitizer: function initSanitizer() { sanitizer: function initSanitizer() {
sanitizer.addItem("commandline", { sanitizer.addItem("commandline", {

View File

@@ -252,8 +252,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
commandline.commandOutput( commandline.commandOutput(
template.usage(results, params.format)); template.usage(results, params.format));
}, }, {
{
argCount: "*", argCount: "*",
completer: function (context, args) { completer: function (context, args) {
context.keys.text = identity; context.keys.text = identity;
@@ -1332,8 +1331,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
options.add(["fullscreen", "fs"], options.add(["fullscreen", "fs"],
"Show the current window fullscreen", "Show the current window fullscreen",
"boolean", false, { "boolean", false, {
setter: function (value) window.fullScreen = value, setter: function (value) { return window.fullScreen = value; },
getter: function () window.fullScreen getter: function () { return window.fullScreen; }
}); });
const groups = [ const groups = [
@@ -1382,8 +1381,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
prefs.safeSet("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2, prefs.safeSet("layout.scrollbar.side", opts.indexOf("l") >= 0 ? 3 : 2,
_("option.guioptions.safeSet")); _("option.guioptions.safeSet"));
}, },
validator: function (opts) Option.validIf(!(opts.indexOf("l") >= 0 && opts.indexOf("r") >= 0), validator: function (opts) {
UTF8("Only one of l or r allowed")) return Option.validIf(!(opts.indexOf("l") >= 0 && opts.indexOf("r") >= 0),
UTF8("Only one of l or r allowed"));
}
}, },
{ {
feature: "tabs", feature: "tabs",
@@ -1421,8 +1422,10 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
events.checkFocus(); events.checkFocus();
return value; return value;
}, },
validator: function (val) Option.validateCompleter.call(this, val) validator: function (val) {
&& groups.every(g => !g.validator || g.validator(val)) return Option.validateCompleter.call(this, val) &&
groups.every(g => !g.validator || g.validator(val));
}
}); });
options.add(["loadplugins", "lpl"], options.add(["loadplugins", "lpl"],
@@ -1466,13 +1469,17 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
options.add(["urlseparator", "urlsep", "us"], options.add(["urlseparator", "urlsep", "us"],
"The regular expression used to separate multiple URLs in :open and friends", "The regular expression used to separate multiple URLs in :open and friends",
"string", " \\| ", "string", " \\| ",
{ validator: function (value) RegExp(value) }); { validator: function (value) { return RegExp(value); } });
options.add(["verbose", "vbs"], options.add(["verbose", "vbs"],
"Define which info messages are displayed", "Define which info messages are displayed",
"number", 1, "number", 1,
{ validator: function (value) Option.validIf(value >= 0 && value <= 15, {
"Value must be between 0 and 15") }); validator: function (value) {
return Option.validIf(value >= 0 && value <= 15,
"Value must be between 0 and 15");
}
});
options.add(["visualbell", "vb"], options.add(["visualbell", "vb"],
"Use visual bell instead of beeping on errors", "Use visual bell instead of beeping on errors",
@@ -1538,7 +1545,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
} }
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.menuItem(context), completer: function (context) {
completion.menuItem(context);
},
literal: 0 literal: 0
}); });
@@ -1553,7 +1562,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
dactyl.echoerr(e); dactyl.echoerr(e);
} }
}, { }, {
completer: function (context) completion.javascript(context), completer: function (context) {
completion.javascript(context);
},
literal: 0 literal: 0
}); });
@@ -1561,18 +1572,17 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
"Load all or matching plugins", "Load all or matching plugins",
function (args) { function (args) {
dactyl.loadPlugins(args.length ? args : null, args.bang); dactyl.loadPlugins(args.length ? args : null, args.bang);
}, }, {
{
argCount: "*", argCount: "*",
bang: true, bang: true,
keepQuotes: true, keepQuotes: true,
serialGroup: 10, serialGroup: 10,
serialize: function () [ serialize: function () {
{ return [{
command: this.name, command: this.name,
literalArg: options["loadplugins"].join(" ") literalArg: options["loadplugins"].join(" ")
}];
} }
]
}); });
commands.add(["norm[al]"], commands.add(["norm[al]"],
@@ -1593,7 +1603,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
}); });
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
privateData: "never-save", privateData: "never-save",
subCommand: 0 subCommand: 0
@@ -1799,9 +1809,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
bang: true, bang: true,
completer: function (context) { completer: function (context) {
if (/^:/.test(context.filter)) if (/^:/.test(context.filter))
return completion.ex(context); completion.ex(context);
else else
return completion.javascript(context); completion.javascript(context);
}, },
count: true, count: true,
hereDoc: true, hereDoc: true,
@@ -1827,7 +1837,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
} }
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
count: true, count: true,
literal: 0, literal: 0,
subCommand: 0 subCommand: 0

View File

@@ -1382,7 +1382,9 @@ var Editor = Module("editor", XPCOM(Ci.nsIEditActionListener, ModuleBase), {
args.push(obj["file"]); args.push(obj["file"]);
return args; return args;
}, },
has: function (key) util.compileMacro(this.value).seen.has(key), has: function (key) {
return util.compileMacro(this.value).seen.has(key);
},
validator: function (value) { validator: function (value) {
this.format({}, value); this.format({}, value);
let allowed = new RealSet(["column", "file", "line"]); let allowed = new RealSet(["column", "file", "line"]);

View File

@@ -1033,15 +1033,17 @@ var Events = Module("events", {
}, { }, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) completion.macro(context), completer: function (context) { completion.macro(context); },
literal: 0 literal: 0
}); });
commands.add(["mac[ros]"], commands.add(["mac[ros]"],
"List all macros", "List all macros",
function (args) { completion.listCompleter("macro", args[0]); }, { function (args) {
completion.listCompleter("macro", args[0]);
}, {
argCount: "?", argCount: "?",
completer: function (context) completion.macro(context) completer: function (context) { completion.macro(context); }
}); });
}, },
completion: function initCompletion() { completion: function initCompletion() {
@@ -1168,7 +1170,10 @@ var Events = Module("events", {
}); });
}, },
has: function (key) this.pass.has(key) || hasOwnProperty(this.commandHive.stack.mappings, key), has: function (key) {
return this.pass.has(key) ||
hasOwnProperty(this.commandHive.stack.mappings, key);
},
get pass() { this.flush(); return this.pass; }, get pass() { this.flush(); return this.pass; },

View File

@@ -1381,7 +1381,7 @@ var Hints = Module("hints", {
options.add(["hinttimeout", "hto"], options.add(["hinttimeout", "hto"],
"Timeout before automatically following a non-unique numerical hint", "Timeout before automatically following a non-unique numerical hint",
"number", 0, "number", 0,
{ validator: function (value) value >= 0 }); { validator: function (value) { return value >= 0; } });
options.add(["followhints", "fh"], options.add(["followhints", "fh"],
"Define the conditions under which selected hints are followed", "Define the conditions under which selected hints are followed",
@@ -1404,15 +1404,17 @@ var Hints = Module("hints", {
"wordstartswith": "The typed characters are split on whitespace. The resulting groups must all match the beginnings of words, in order.", "wordstartswith": "The typed characters are split on whitespace. The resulting groups must all match the beginnings of words, in order.",
"transliterated": UTF8("When true, special latin characters are translated to their ASCII equivalents (e.g., é ⇒ e)") "transliterated": UTF8("When true, special latin characters are translated to their ASCII equivalents (e.g., é ⇒ e)")
}, },
validator: function (values) Option.validateCompleter.call(this, values) && validator: function (values) {
return Option.validateCompleter.call(this, values) &&
1 === values.reduce((acc, v) => acc + (["contains", "custom", "firstletters", "wordstartswith"].indexOf(v) >= 0), 1 === values.reduce((acc, v) => acc + (["contains", "custom", "firstletters", "wordstartswith"].indexOf(v) >= 0),
0) 0);
}
}); });
options.add(["wordseparators", "wsp"], options.add(["wordseparators", "wsp"],
"Regular expression defining which characters separate words when matching hints", "Regular expression defining which characters separate words when matching hints",
"string", '[.,!?:;/"^$%&?()[\\]{}<>#*+|=~ _-]', "string", '[.,!?:;/"^$%&?()[\\]{}<>#*+|=~ _-]',
{ validator: function (value) RegExp(value) }); { validator: function (value) { return RegExp(value); } });
options.add(["hintinputs", "hin"], options.add(["hintinputs", "hin"],
"Which text is used to filter hints for input elements", "Which text is used to filter hints for input elements",

View File

@@ -200,8 +200,7 @@ var History = Module("history", {
history.stepTo(-Math.max(args.count, 1)); history.stepTo(-Math.max(args.count, 1));
} }
return null; return null;
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function completer(context) { completer: function completer(context) {
@@ -211,9 +210,13 @@ var History = Module("history", {
context.compare = CompletionContext.Sort.unsorted; context.compare = CompletionContext.Sort.unsorted;
context.filters = [CompletionContext.Filter.textDescription]; context.filters = [CompletionContext.Filter.textDescription];
context.completions = sh.slice(0, sh.index).reverse(); context.completions = sh.slice(0, sh.index).reverse();
context.keys = { text: function (item) (sh.index - item.index) + ": " + item.URI.spec, context.keys = {
text: function (item) {
return (sh.index - item.index) + ": " + item.URI.spec;
},
description: "title", description: "title",
icon: "icon" }; icon: "icon"
};
}, },
count: true, count: true,
literal: 0, literal: 0,
@@ -242,8 +245,7 @@ var History = Module("history", {
history.stepTo(Math.max(args.count, 1)); history.stepTo(Math.max(args.count, 1));
} }
return null; return null;
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function completer(context) { completer: function completer(context) {
@@ -253,9 +255,13 @@ var History = Module("history", {
context.compare = CompletionContext.Sort.unsorted; context.compare = CompletionContext.Sort.unsorted;
context.filters = [CompletionContext.Filter.textDescription]; context.filters = [CompletionContext.Filter.textDescription];
context.completions = sh.slice(sh.index + 1); context.completions = sh.slice(sh.index + 1);
context.keys = { text: function (item) (item.index - sh.index) + ": " + item.URI.spec, context.keys = {
text: function (item) {
return (item.index - sh.index) + ": " + item.URI.spec;
},
description: "title", description: "title",
icon: "icon" }; icon: "icon"
};
}, },
count: true, count: true,
literal: 0, literal: 0,
@@ -264,9 +270,13 @@ var History = Module("history", {
commands.add(["hist[ory]", "hs"], commands.add(["hist[ory]", "hs"],
"Show recently visited URLs", "Show recently visited URLs",
function (args) { history.list(args.join(" "), args.bang, args["-max"], args["-sort"]); }, { function (args) {
history.list(args.join(" "), args.bang, args["-max"], args["-sort"]);
}, {
bang: true, bang: true,
completer: function (context, args) completion.history(context, args["-max"], args["-sort"]), completer: function (context, args) {
completion.history(context, args["-max"], args["-sort"]);
},
options: [ options: [
{ {
names: ["-max", "-m"], names: ["-max", "-m"],

View File

@@ -575,12 +575,12 @@ var Mappings = Module("mappings", {
completer: function (context, args) { completer: function (context, args) {
let mapmodes = Ary.uniq(args["-modes"].map(findMode)); let mapmodes = Ary.uniq(args["-modes"].map(findMode));
if (args.length == 1) if (args.length == 1)
return completion.userMapping(context, mapmodes, args["-group"]); completion.userMapping(context, mapmodes, args["-group"]);
if (args.length == 2) { else if (args.length == 2) {
if (args["-javascript"]) if (args["-javascript"])
return completion.javascript(context); completion.javascript(context);
if (args["-ex"]) else if (args["-ex"])
return completion.ex(context); completion.ex(context);
} }
}, },
hereDoc: true, hereDoc: true,
@@ -629,8 +629,10 @@ var Mappings = Module("mappings", {
} }
], ],
serialize: function () { serialize: function () {
return this.name != "map" ? [] : if (this.name != "map")
Ary(mappings.userHives) return [];
else
return Ary(mappings.userHives)
.filter(h => h.persist) .filter(h => h.persist)
.map(hive => [ .map(hive => [
{ {
@@ -691,8 +693,7 @@ var Mappings = Module("mappings", {
if (!found && !args.bang) if (!found && !args.bang)
dactyl.echoerr(_("map.noSuch", args[0])); dactyl.echoerr(_("map.noSuch", args[0]));
}, }, {
{
identifier: "unmap", identifier: "unmap",
argCount: "?", argCount: "?",
bang: true, bang: true,
@@ -712,10 +713,14 @@ var Mappings = Module("mappings", {
let modeFlag = { let modeFlag = {
names: ["-mode", "-m"], names: ["-mode", "-m"],
type: CommandOption.STRING, type: CommandOption.STRING,
validator: function (value) Array.concat(value).every(findMode), validator: function (value) {
completer: function () [[Ary.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description] return Array.concat(value).every(findMode);
},
completer: function () {
return [[Ary.compact([mode.name.toLowerCase().replace(/_/g, "-"), mode.char]), mode.description]
for (mode of modes.all) for (mode of modes.all)
if (!mode.hidden)] if (!mode.hidden)];
}
}; };
function findMode(name) { function findMode(name) {

View File

@@ -349,10 +349,9 @@ var Marks = Module("marks", {
dactyl.assert(!special || !arg, _("error.invalidArgument")); dactyl.assert(!special || !arg, _("error.invalidArgument"));
marks.remove(arg, special); marks.remove(arg, special);
}, }, {
{
bang: true, bang: true,
completer: function (context) completion.mark(context), completer: function (context) { completion.mark(context); },
literal: 0 literal: 0
}); });
@@ -372,7 +371,7 @@ var Marks = Module("marks", {
function (args) { function (args) {
marks.list(args[0] || ""); marks.list(args[0] || "");
}, { }, {
completer: function (context) completion.mark(context), completer: function (context) { completion.mark(context); },
literal: 0 literal: 0
}); });
}, },

View File

@@ -659,8 +659,10 @@ var Modes = Module("modes", {
return vals; return vals;
}, },
validator: function validator(vals) vals.map(v => v.replace(/^!/, "")) validator: function validator(vals) {
.every(k => hasOwnProperty(this.values, k)), return vals.map(v => v.replace(/^!/, ""))
.every(k => hasOwnProperty(this.values, k));
},
get values() { get values() {
return Ary.toObject([[m.name.toLowerCase(), m.description] return Ary.toObject([[m.name.toLowerCase(), m.description]

View File

@@ -131,11 +131,12 @@ var QuickMarks = Module("quickmarks", {
quickmarks.removeAll(); quickmarks.removeAll();
else else
quickmarks.remove(args[0]); quickmarks.remove(args[0]);
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) completion.quickmark(context) completer: function (context) {
completion.quickmark(context);
}
}); });
commands.add(["qma[rk]"], commands.add(["qma[rk]"],
@@ -147,13 +148,12 @@ var QuickMarks = Module("quickmarks", {
quickmarks.add(args[0], buffer.uri.spec); quickmarks.add(args[0], buffer.uri.spec);
else else
quickmarks.add(args[0], args[1]); quickmarks.add(args[0], args[1]);
}, }, {
{
argCount: "+", argCount: "+",
completer: function (context, args) { completer: function (context, args) {
if (args.length == 1) if (args.length == 1)
return completion.quickmark(context); completion.quickmark(context);
if (args.length == 2) { else if (args.length == 2) {
context.fork("current", 0, this, context => { context.fork("current", 0, this, context => {
context.title = ["Extra Completions"]; context.title = ["Extra Completions"];
context.completions = [ context.completions = [
@@ -172,7 +172,9 @@ var QuickMarks = Module("quickmarks", {
quickmarks.list(args[0] || ""); quickmarks.list(args[0] || "");
}, { }, {
argCount: "?", argCount: "?",
completer: function (context) completion.quickmark(context) completer: function (context) {
completion.quickmark(context);
}
}); });
}, },
completion: function initCompletion() { completion: function initCompletion() {

View File

@@ -650,7 +650,9 @@ var Tabs = Module("tabs", {
argCount: "?", argCount: "?",
bang: true, bang: true,
count: true, count: true,
completer: function (context) completion.buffer(context), completer: function (context) {
completion.buffer(context);
},
literal: 0, literal: 0,
privateData: true privateData: true
}); });
@@ -661,8 +663,7 @@ var Tabs = Module("tabs", {
function (args) { function (args) {
for (let tab of tabs.match(args[0], args.count)) for (let tab of tabs.match(args[0], args.count))
config.browser[!args.bang || !tab.pinned ? "pinTab" : "unpinTab"](tab); config.browser[!args.bang || !tab.pinned ? "pinTab" : "unpinTab"](tab);
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
count: true, count: true,
@@ -678,8 +679,7 @@ var Tabs = Module("tabs", {
function (args) { function (args) {
for (let tab of tabs.match(args[0], args.count)) for (let tab of tabs.match(args[0], args.count))
config.browser.unpinTab(tab); config.browser.unpinTab(tab);
}, }, {
{
argCount: "?", argCount: "?",
count: true, count: true,
completer: function (context) { completer: function (context) {
@@ -699,7 +699,7 @@ var Tabs = Module("tabs", {
} }
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
subCommand: 0 subCommand: 0
}); });
@@ -713,7 +713,7 @@ var Tabs = Module("tabs", {
}); });
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
subCommand: 0 subCommand: 0
}); });
@@ -727,7 +727,7 @@ var Tabs = Module("tabs", {
}); });
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
subCommand: 0 subCommand: 0
}); });
@@ -741,7 +741,7 @@ var Tabs = Module("tabs", {
} }
}, { }, {
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
subCommand: 0 subCommand: 0
}); });
@@ -821,7 +821,9 @@ var Tabs = Module("tabs", {
argCount: "?", argCount: "?",
bang: true, bang: true,
count: true, count: true,
completer: function (context) completion.buffer(context), completer: function (context) {
completion.buffer(context);
},
literal: 0, literal: 0,
privateData: true privateData: true
}); });
@@ -866,7 +868,9 @@ var Tabs = Module("tabs", {
}, { }, {
argCount: "1", argCount: "1",
bang: true, bang: true,
completer: function (context) completion.buffer(context, true), completer: function (context) {
completion.buffer(context, true);
},
literal: 0 literal: 0
}); });
@@ -882,8 +886,12 @@ var Tabs = Module("tabs", {
{ from: "tabopen", where: dactyl.NEW_TAB, background: args.bang }); { from: "tabopen", where: dactyl.NEW_TAB, background: args.bang });
}, { }, {
bang: true, bang: true,
completer: function (context) completion.url(context), completer: function (context) {
domains: function (args) commands.get("open").domains(args), completion.url(context);
},
domains: function (args) {
return commands.get("open").domains(args);
},
literal: 0, literal: 0,
privateData: true privateData: true
}); });
@@ -1012,9 +1020,13 @@ var Tabs = Module("tabs", {
context.anchored = false; context.anchored = false;
context.compare = CompletionContext.Sort.unsorted; context.compare = CompletionContext.Sort.unsorted;
context.filters = [CompletionContext.Filter.textDescription]; context.filters = [CompletionContext.Filter.textDescription];
context.keys = { text: function ([i, { state: s }]) (i + 1) + ": " + s.entries[s.index - 1].url, context.keys = {
text: function ([i, { state: s }]) {
return (i + 1) + ": " + s.entries[s.index - 1].url;
},
description: "[1].title", description: "[1].title",
icon: "[1].image" }; icon: "[1].image"
};
context.completions = tabs.closedTabs.entries(); context.completions = tabs.closedTabs.entries();
}, },
count: true, count: true,

View File

@@ -365,15 +365,16 @@ var Addons = Module("addons", {
if (modules.commandline.savingOutput) if (modules.commandline.savingOutput)
util.waitFor(() => addons.ready); util.waitFor(() => addons.ready);
}, }, {
{
argCount: "?", argCount: "?",
options: [ options: [
{ {
names: ["-types", "-type", "-t"], names: ["-types", "-type", "-t"],
description: "The add-on types to list", description: "The add-on types to list",
default: ["extension"], default: ["extension"],
completer: function (context) completion.addonType(context), completer: function (context) {
completion.addonType(context);
},
type: CommandOption.LIST type: CommandOption.LIST
} }
] ]
@@ -450,7 +451,9 @@ var Addons = Module("addons", {
names: ["-types", "-type", "-t"], names: ["-types", "-type", "-t"],
description: "The add-on types to operate on", description: "The add-on types to operate on",
default: ["extension"], default: ["extension"],
completer: function (context) completion.addonType(context), completer: function (context) {
completion.addonType(context);
},
type: CommandOption.LIST type: CommandOption.LIST
} }
] ]

View File

@@ -815,7 +815,9 @@ var Buffer = Module("Buffer", {
self.saveURI({ uri: uri, file: file, context: elem }); self.saveURI({ uri: uri, file: file, context: elem });
}, },
completer: function (context) completion.savePage(context, elem) completer: function (context) {
completion.savePage(context, elem);
}
}).open(); }).open();
} }
catch (e) { catch (e) {
@@ -1891,8 +1893,7 @@ var Buffer = Module("Buffer", {
.getInterface(Ci.nsIWebBrowserPrint).print(settings, null); .getInterface(Ci.nsIWebBrowserPrint).print(settings, null);
dactyl.echomsg(_("print.sent")); dactyl.echomsg(_("print.sent"));
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context, args) { completer: function (context, args) {
@@ -1911,8 +1912,7 @@ var Buffer = Module("Buffer", {
dactyl.assert(!arg || opt.validator(opt.parse(arg)), dactyl.assert(!arg || opt.validator(opt.parse(arg)),
_("error.invalidArgument", arg)); _("error.invalidArgument", arg));
buffer.showPageInfo(true, arg); buffer.showPageInfo(true, arg);
}, }, {
{
argCount: "?", argCount: "?",
completer: function (context) { completer: function (context) {
modules.completion.optionValue(context, "pageinfo", "+", ""); modules.completion.optionValue(context, "pageinfo", "+", "");
@@ -1934,10 +1934,11 @@ var Buffer = Module("Buffer", {
options["usermode"] = false; options["usermode"] = false;
window.stylesheetSwitchAll(buffer.focusedFrame, arg); window.stylesheetSwitchAll(buffer.focusedFrame, arg);
}, }, {
{
argCount: "?", argCount: "?",
completer: function (context) modules.completion.alternateStyleSheet(context), completer: function (context) {
modules.completion.alternateStyleSheet(context);
},
literal: 0 literal: 0
}); });
@@ -2016,8 +2017,7 @@ var Buffer = Module("Buffer", {
doc.contentType, false, null, chosenData, doc.contentType, false, null, chosenData,
doc.referrer ? window.makeURI(doc.referrer) : null, doc.referrer ? window.makeURI(doc.referrer) : null,
doc, true); doc, true);
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) { completer: function (context) {
@@ -2041,11 +2041,14 @@ var Buffer = Module("Buffer", {
commands.add(["vie[wsource]"], commands.add(["vie[wsource]"],
"View source code of current document", "View source code of current document",
function (args) { buffer.viewSource(args[0], args.bang); }, function (args) {
{ buffer.viewSource(args[0], args.bang);
}, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) modules.completion.url(context, "bhf") completer: function (context) {
modules.completion.url(context, "bhf");
}
}); });
commands.add(["zo[om]"], commands.add(["zo[om]"],
@@ -2475,7 +2478,9 @@ var Buffer = Module("Buffer", {
"string", "UTF-8", "string", "UTF-8",
{ {
scope: Option.SCOPE_LOCAL, scope: Option.SCOPE_LOCAL,
getter: function () buffer.docShell.QueryInterface(Ci.nsIDocCharset).charset, getter: function () {
return buffer.docShell.QueryInterface(Ci.nsIDocCharset).charset;
},
setter: function (val) { setter: function (val) {
if (options["encoding"] == val) if (options["encoding"] == val)
return val; return val;
@@ -2491,7 +2496,9 @@ var Buffer = Module("Buffer", {
}); });
return null; return null;
}, },
completer: function (context) completion.charset(context) completer: function (context) {
completion.charset(context);
}
}); });
options.add(["iskeyword", "isk"], options.add(["iskeyword", "isk"],
@@ -2502,7 +2509,7 @@ var Buffer = Module("Buffer", {
this.regexp = util.regexp(value); this.regexp = util.regexp(value);
return value; return value;
}, },
validator: function (value) RegExp(value) validator: function (value) { return RegExp(value); }
}); });
options.add(["jumptags", "jt"], options.add(["jumptags", "jt"],
@@ -2518,8 +2525,10 @@ var Buffer = Module("Buffer", {
vals[k] = update(new String(v), { matcher: DOM.compileMatcher(Option.splitList(v)) }); vals[k] = update(new String(v), { matcher: DOM.compileMatcher(Option.splitList(v)) });
return vals; return vals;
}, },
validator: function (value) DOM.validateMatcher.call(this, value) validator: function (value) {
&& Object.keys(value).every(v => v.length == 1) return DOM.validateMatcher.call(this, value) &&
Object.keys(value).every(v => v.length == 1);
}
}); });
options.add(["linenumbers", "ln"], options.add(["linenumbers", "ln"],
@@ -2591,7 +2600,7 @@ var Buffer = Module("Buffer", {
options.add(["scroll", "scr"], options.add(["scroll", "scr"],
"Number of lines to scroll with <C-u> and <C-d> commands", "Number of lines to scroll with <C-u> and <C-d> commands",
"number", 0, "number", 0,
{ validator: function (value) value >= 0 }); { validator: function (value) { return value >= 0; } });
options.add(["showstatuslinks", "ssli"], options.add(["showstatuslinks", "ssli"],
"Where to show the destination of the link under the cursor", "Where to show the destination of the link under the cursor",
@@ -2616,7 +2625,9 @@ var Buffer = Module("Buffer", {
initValue: function () {}, initValue: function () {},
getter: function getter(value) !prefs.get(this.PREF) ? 1 : value, getter: function getter(value) {
return !prefs.get(this.PREF) ? 1 : value;
},
setter: function setter(value) { setter: function setter(value) {
prefs.set(this.PREF, value > 1); prefs.set(this.PREF, value > 1);
@@ -2624,15 +2635,19 @@ var Buffer = Module("Buffer", {
return value; return value;
}, },
validator: function (value) value > 0 validator: function (value) { return value > 0; }
}); });
options.add(["usermode", "um"], options.add(["usermode", "um"],
"Show current website without styling defined by the author", "Show current website without styling defined by the author",
"boolean", false, "boolean", false,
{ {
setter: function (value) buffer.contentViewer.authorStyleDisabled = value, setter: function (value) {
getter: function () buffer.contentViewer.authorStyleDisabled return buffer.contentViewer.authorStyleDisabled = value;
},
getter: function () {
return buffer.contentViewer.authorStyleDisabled;
}
}); });
options.add(["yankshort", "ys"], options.add(["yankshort", "ys"],

View File

@@ -1676,9 +1676,13 @@ 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] of iter(config.completers))], completer: function (context) {
return [[k, ""] for ([k, v] of iter(config.completers))];
},
type: CommandOption.STRING, type: CommandOption.STRING,
validator: function (arg) arg in config.completers || /^custom,/.test(arg) validator: function (arg) {
return arg in config.completers || /^custom,/.test(arg);
}
}, },
{ {
names: ["-description", "-desc", "-d"], names: ["-description", "-desc", "-d"],
@@ -1715,7 +1719,8 @@ var Commands = Module("commands", {
], ],
literal: 1, literal: 1,
serialize: function () Ary(commands.userHives) serialize: function () {
return Ary(commands.userHives)
.filter(h => h.persist) .filter(h => h.persist)
.map(hive => [ .map(hive => [
{ {
@@ -1736,7 +1741,8 @@ var Commands = Module("commands", {
} }
for (cmd of hive) if (cmd.persist) for (cmd of hive) if (cmd.persist)
]) ])
.flatten().array .flatten().array;
}
}); });
commands.add(["delc[ommand]"], commands.add(["delc[ommand]"],
@@ -1754,16 +1760,21 @@ var Commands = Module("commands", {
}, { }, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context, args) modules.completion.userCommand(context, args["-group"]), completer: function (context, args) {
modules.completion.userCommand(context, args["-group"]);
},
options: [contexts.GroupFlag("commands")] options: [contexts.GroupFlag("commands")]
}); });
commands.add(["comp[letions]"], commands.add(["comp[letions]"],
"List the completion results for a given command substring", "List the completion results for a given command substring",
function (args) { modules.completion.listCompleter("ex", args[0]); }, function (args) {
{ modules.completion.listCompleter("ex", args[0]);
}, {
argCount: "1", argCount: "1",
completer: function (context, args) modules.completion.ex(context), completer: function (context) {
modules.completion.ex(context);
},
literal: 0 literal: 0
}); });
@@ -1801,10 +1812,11 @@ var Commands = Module("commands", {
let lines = res.split("\n").length; let lines = res.split("\n").length;
dactyl.echomsg(_("command.yank.yankedLine" + (lines == 1 ? "" : "s"), lines)); dactyl.echomsg(_("command.yank.yankedLine" + (lines == 1 ? "" : "s"), lines));
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) modules.completion[/^:/.test(context.filter) ? "ex" : "javascript"](context), completer: function (context) {
modules.completion[/^:/.test(context.filter) ? "ex" : "javascript"](context);
},
literal: 0 literal: 0
}); });
}, },

View File

@@ -1224,8 +1224,7 @@ var Completion = Module("completion", {
function m(item) { function m(item) {
return template.completionRow(item, "CompItem"); return template.completionRow(item, "CompItem");
})]); })]);
}, }, {
{
argCount: "*", argCount: "*",
completer: function (context) { completer: function (context) {
let PREFIX = "/ex/contexts"; let PREFIX = "/ex/contexts";
@@ -1303,7 +1302,9 @@ var Completion = Module("completion", {
return values; return values;
}, },
validator: function validator(values) validator.supercall(this, this.setter(values)) validator: function validator(values) {
return validator.supercall(this, this.setter(values));
}
}); });
options.add(["wildanchor", "wia"], options.add(["wildanchor", "wia"],

View File

@@ -152,7 +152,9 @@ var Contexts = Module("contexts", {
contexts.user)[this.name]; contexts.user)[this.name];
}, },
completer: function (context) modules.completion.group(context) completer: function (context) {
modules.completion.group(context);
}
}); });
memoize(modules, "userContext", () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, false])); memoize(modules, "userContext", () => contexts.Context(modules.io.getRCFile("~", true), contexts.user, [modules, false]));
@@ -685,8 +687,7 @@ var Contexts = Module("contexts", {
!["-description", "-locations", "-nopersist"] !["-description", "-locations", "-nopersist"]
.some(hasOwnProperty.bind(null, args.explicitOpts)), .some(hasOwnProperty.bind(null, args.explicitOpts)),
_("group.cantModifyBuiltin")); _("group.cantModifyBuiltin"));
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context, args) { completer: function (context, args) {
@@ -718,7 +719,8 @@ var Contexts = Module("contexts", {
} }
], ],
serialGroup: 20, serialGroup: 20,
serialize: function () [ serialize: function () {
return [
{ {
command: this.name, command: this.name,
bang: true, bang: true,
@@ -735,7 +737,8 @@ var Contexts = Module("contexts", {
} }
for (group of contexts.initializedGroups()) for (group of contexts.initializedGroups())
if (!group.builtin && group.persist) if (!group.builtin && group.persist)
].concat([{ command: this.name, arguments: ["user"] }]) ].concat([{ command: this.name, arguments: ["user"] }]);
}
}); });
commands.add(["delg[roup]"], commands.add(["delg[roup]"],
@@ -749,8 +752,7 @@ var Contexts = Module("contexts", {
util.assert(contexts.getGroup(args[0]), _("group.noSuch", args[0])); util.assert(contexts.getGroup(args[0]), _("group.noSuch", args[0]));
contexts.removeGroup(args[0]); contexts.removeGroup(args[0]);
} }
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context, args) { completer: function (context, args) {

View File

@@ -481,8 +481,7 @@ var Downloads_ = Module("downloads", XPCOM(Ci.nsIDownloadProgressListener), {
function (args) { function (args) {
let downloads = DownloadList(modules, args[0], args["-sort"]); let downloads = DownloadList(modules, args[0], args["-sort"]);
modules.commandline.echo(downloads); modules.commandline.echo(downloads);
}, }, {
{
argCount: "?", argCount: "?",
options: [ options: [
{ {
@@ -492,8 +491,12 @@ var Downloads_ = Module("downloads", XPCOM(Ci.nsIDownloadProgressListener), {
get default() { get default() {
return modules.options["downloadsort"]; return modules.options["downloadsort"];
}, },
completer: function (context, args) modules.options.get("downloadsort").completer(context, { values: args["-sort"] }), completer: function (context, args) {
validator: function (value) modules.options.get("downloadsort").validator(value) modules.options.get("downloadsort").completer(context, { values: args["-sort"] });
},
validator: function (value) {
return modules.options.get("downloadsort").validator(value);
}
} }
] ]
}); });
@@ -546,7 +549,9 @@ var Downloads_ = Module("downloads", XPCOM(Ci.nsIDownloadProgressListener), {
.flatten().array; .flatten().array;
}, },
has: function () Array.some(arguments, val => this.value.some(v => v.substr(1) == val)), has: function () {
return Array.some(arguments, val => this.value.some(v => v.substr(1) == val));
},
validator: function (value) { validator: function (value) {
let seen = new RealSet(); let seen = new RealSet();

View File

@@ -429,7 +429,9 @@ var Help = Module("Help", {
}, { }, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) completion.help(context, consolidated), completer: function (context) {
completion.help(context, consolidated);
},
literal: 0 literal: 0
}); });
}); });

View File

@@ -332,10 +332,11 @@ var Highlights = Module("Highlight", {
dactyl.assert(lastScheme, _("command.colorscheme.notFound", scheme)); dactyl.assert(lastScheme, _("command.colorscheme.notFound", scheme));
} }
autocommands.trigger("ColorScheme", { name: scheme }); autocommands.trigger("ColorScheme", { name: scheme });
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) completion.colorScheme(context) completer: function (context) {
completion.colorScheme(context);
}
}); });
commands.add(["hi[ghlight]"], commands.add(["hi[ghlight]"],
@@ -381,8 +382,7 @@ var Highlights = Module("Highlight", {
highlight.set(key, css, clear, "-append" in args, args["-link"]); highlight.set(key, css, clear, "-append" in args, args["-link"]);
else else
util.assert(false, _("error.invalidArgument")); util.assert(false, _("error.invalidArgument"));
}, }, {
{
// TODO: add this as a standard highlight completion function? // TODO: add this as a standard highlight completion function?
completer: function (context, args) { completer: function (context, args) {
// Complete a highlight group on :hi clear ... // Complete a highlight group on :hi clear ...
@@ -420,7 +420,8 @@ var Highlights = Module("Highlight", {
} }
} }
], ],
serialize: function () [ serialize: function () {
return [
{ {
command: this.name, command: this.name,
arguments: [v.class], arguments: [v.class],
@@ -431,7 +432,8 @@ var Highlights = Module("Highlight", {
} }
for (v of highlight) for (v of highlight)
if (v.value != v.defaultValue) if (v.value != v.defaultValue)
] ];
}
}); });
}, },
completion: function initCompletion(dactyl, modules) { completion: function initCompletion(dactyl, modules) {

View File

@@ -650,7 +650,9 @@ var IO = Module("io", {
} }
}, { }, {
argCount: "?", argCount: "?",
completer: function (context) completion.directory(context, true), completer: function (context) {
completion.directory(context, true);
},
literal: 0 literal: 0
}); });
@@ -689,7 +691,9 @@ var IO = Module("io", {
}, { }, {
argCount: "*", // FIXME: should be "?" but kludged for proper error message argCount: "*", // FIXME: should be "?" but kludged for proper error message
bang: true, bang: true,
completer: function (context) completion.file(context, true) completer: function (context) {
completion.file(context, true);
}
}); });
commands.add(["mkv[imruntime]"], commands.add(["mkv[imruntime]"],
@@ -889,17 +893,22 @@ unlet s:cpo_save
}, { }, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) completion.directory(context, true), completer: function (context) {
completion.directory(context, true);
},
literal: 1 literal: 1
}); });
commands.add(["runt[ime]"], commands.add(["runt[ime]"],
"Source the specified file from each directory in 'runtimepath'", "Source the specified file from each directory in 'runtimepath'",
function (args) { io.sourceFromRuntimePath(args, args.bang); }, function (args) {
{ io.sourceFromRuntimePath(args, args.bang);
}, {
argCount: "+", argCount: "+",
bang: true, bang: true,
completer: function (context) completion.runtime(context) completer: function (context) {
completion.runtime(context);
}
} }
); );
@@ -927,7 +936,9 @@ unlet s:cpo_save
}, { }, {
argCount: "+", // FIXME: should be "1" but kludged for proper error message argCount: "+", // FIXME: should be "1" but kludged for proper error message
bang: true, bang: true,
completer: function (context) completion.file(context, true) completer: function (context) {
completion.file(context, true);
}
}); });
commands.add(["!", "run"], commands.add(["!", "run"],
@@ -969,7 +980,9 @@ unlet s:cpo_save
argCount: "?", argCount: "?",
bang: true, bang: true,
// This is abominably slow. // This is abominably slow.
// completer: function (context) completion.shellCommand(context), //completer: function (context) {
// completion.shellCommand(context);
//},
literal: 0 literal: 0
}); });
}, },
@@ -1156,10 +1169,15 @@ unlet s:cpo_save
options.add(["fileencoding", "fenc"], options.add(["fileencoding", "fenc"],
"The character encoding used when reading and writing files", "The character encoding used when reading and writing files",
"string", "UTF-8", { "string", "UTF-8",
completer: function (context) completion.charset(context), {
getter: function () File.defaultEncoding, completer: function (context) {
setter: function (value) (File.defaultEncoding = value) completion.charset(context);
},
getter: function () { return File.defaultEncoding; },
setter: function (value) {
return File.defaultEncoding = value;
}
}); });
options.add(["cdpath", "cd"], options.add(["cdpath", "cd"],
"List of directories searched when executing :cd", "List of directories searched when executing :cd",
@@ -1169,7 +1187,9 @@ unlet s:cpo_save
return this.value.map(path => File(path, modules.io.cwd)) return this.value.map(path => File(path, modules.io.cwd))
.filter(dir => dir.exists()); .filter(dir => dir.exists());
}, },
setter: function (value) File.expandPathList(value) setter: function (value) {
return File.expandPathList(value);
}
}); });
options.add(["runtimepath", "rtp"], options.add(["runtimepath", "rtp"],
@@ -1185,7 +1205,7 @@ unlet s:cpo_save
options.add(["shell", "sh"], options.add(["shell", "sh"],
"Shell to use for executing external commands with :! and :run", "Shell to use for executing external commands with :! and :run",
"string", shell, "string", shell,
{ validator: function (val) io.pathSearch(val) }); { validator: function (val) { return io.pathSearch(val); } });
options.add(["shellcmdflag", "shcf"], options.add(["shellcmdflag", "shcf"],
"Flag passed to shell when executing external commands with :! and :run", "Flag passed to shell when executing external commands with :! and :run",

View File

@@ -860,7 +860,9 @@ var JavaScript = Module("javascript", {
}, { }, {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) modules.completion.javascript(context), completer: function (context) {
modules.completion.javascript(context);
},
hereDoc: true, hereDoc: true,
literal: 0 literal: 0
}); });

View File

@@ -1418,7 +1418,8 @@ var Options = Module("options", {
description: "Set an option", description: "Set an option",
modifiers: {}, modifiers: {},
extra: { extra: {
serialize: function () [ serialize: function () {
return [
{ {
command: this.name, command: this.name,
literalArg: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name literalArg: [opt.type == "boolean" ? (opt.value ? "" : "no") + opt.name
@@ -1426,7 +1427,8 @@ var Options = Module("options", {
} }
for (opt of modules.options) for (opt of modules.options)
if (!opt.getter && !opt.isDefault && (opt.scope & Option.SCOPE_GLOBAL)) if (!opt.getter && !opt.isDefault && (opt.scope & Option.SCOPE_GLOBAL))
] ];
}
} }
} }
].forEach(function (params) { ].forEach(function (params) {

View File

@@ -507,15 +507,14 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
else else
sanitize(items); sanitize(items);
}, }, {
{
argCount: "*", // FIXME: should be + and 0 argCount: "*", // FIXME: should be + and 0
bang: true, bang: true,
completer: function (context) { completer: function (context) {
context.title = ["Privacy Item", "Description"]; context.title = ["Privacy Item", "Description"];
context.completions = modules.options.get("sanitizeitems").values; context.completions = modules.options.get("sanitizeitems").values;
}, },
domains: function (args) args["-host"] || [], domains: function (args) { return args["-host"] || []; },
options: [ options: [
{ {
names: ["-host", "-h"], names: ["-host", "-h"],
@@ -533,9 +532,13 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
}, { }, {
names: ["-timespan", "-t"], names: ["-timespan", "-t"],
description: "Timespan for which to sanitize items", description: "Timespan for which to sanitize items",
completer: function (context) modules.options.get("sanitizetimespan").completer(context), completer: function (context) {
modules.options.get("sanitizetimespan").completer(context);
},
type: modules.CommandOption.STRING, type: modules.CommandOption.STRING,
validator: function (arg) modules.options.get("sanitizetimespan").validator(arg) validator: function (arg) {
return modules.options.get("sanitizetimespan").validator(arg);
}
} }
], ],
privateData: true privateData: true
@@ -645,8 +648,10 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
return res && !/^!/.test(res); return res && !/^!/.test(res);
}, },
validator: function (values) values.length && validator: function (values) {
values.every(val => (val === "all" || hasOwnProperty(sanitizer.itemMap, val.replace(/^!/, "")))) return values.length &&
values.every(val => (val === "all" || hasOwnProperty(sanitizer.itemMap, val.replace(/^!/, ""))));
}
}); });
options.add(["sanitizeshutdown", "ss"], options.add(["sanitizeshutdown", "ss"],
@@ -712,7 +717,9 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
["none", "Accept no cookies"], ["none", "Accept no cookies"],
["visited", "Accept cookies from visited sites"] ["visited", "Accept cookies from visited sites"]
], ],
getter: function () (this.values[prefs.get(this.PREF)] || ["all"])[0], getter: function () {
return (this.values[prefs.get(this.PREF)] || ["all"])[0];
},
setter: function (val) { setter: function (val) {
prefs.set(this.PREF, this.values.map(i => i[0]).indexOf(val)); prefs.set(this.PREF, this.values.map(i => i[0]).indexOf(val));
return val; return val;
@@ -731,7 +738,9 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
["prompt", "Always prompt for a lifetime"], ["prompt", "Always prompt for a lifetime"],
["session", "The current session"] ["session", "The current session"]
], ],
getter: function () (this.values[prefs.get(this.PREF)] || [prefs.get(this.PREF_DAYS)])[0], getter: function () {
return (this.values[prefs.get(this.PREF)] || [prefs.get(this.PREF_DAYS)])[0];
},
setter: function (value) { setter: function (value) {
let val = this.values.map(i => i[0]).indexOf(value); let val = this.values.map(i => i[0]).indexOf(value);
if (val > -1) if (val > -1)
@@ -743,7 +752,10 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef
}, },
initialValue: true, initialValue: true,
persist: false, persist: false,
validator: function validator(val) parseInt(val) == val || validator.superapply(this, arguments) validator: function validator(val) {
return parseInt(val) == val ||
validator.superapply(this, arguments);
}
}); });
} }
}); });

View File

@@ -628,8 +628,7 @@ var Styles = Module("Styles", {
if (args["-nopersist"] || !args["-append"] || style.persist === undefined) if (args["-nopersist"] || !args["-append"] || style.persist === undefined)
style.persist = !args["-nopersist"]; style.persist = !args["-nopersist"];
} }
}, }, {
{
completer: function (context, args) { completer: function (context, args) {
let sheet = args["-group"].get(args["-name"]); let sheet = args["-group"].get(args["-name"]);
if (args.completeArg == 0) { if (args.completeArg == 0) {
@@ -654,8 +653,8 @@ var Styles = Module("Styles", {
nameFlag(), nameFlag(),
{ names: ["-nopersist", "-N"], description: "Do not save this style to an auto-generated RC file" } { names: ["-nopersist", "-N"], description: "Do not save this style to an auto-generated RC file" }
], ],
serialize: function () serialize: function () {
Ary(styles.hives) return Ary(styles.hives)
.filter(hive => hive.persist) .filter(hive => hive.persist)
.map(hive => .map(hive =>
hive.sheets.filter(style => style.persist) hive.sheets.filter(style => style.persist)
@@ -670,7 +669,8 @@ var Styles = Module("Styles", {
"-name": style.name || undefined "-name": style.name || undefined
} }
}))) })))
.flatten().array .flatten().array;
}
}); });
[ [

View File

@@ -242,10 +242,11 @@ const Config = Module("config", ConfigBase, {
let arg = args.literalArg; let arg = args.literalArg;
dactyl.assert(arg in Config.displayPanes, _("error.invalidArgument", arg)); dactyl.assert(arg in Config.displayPanes, _("error.invalidArgument", arg));
config.closeDisplayPane(Config.displayPanes[arg]); config.closeDisplayPane(Config.displayPanes[arg]);
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) completion.displayPane(context), completer: function (context) {
completion.displayPane(context);
},
literal: 0 literal: 0
}); });
@@ -257,10 +258,11 @@ const Config = Module("config", ConfigBase, {
dactyl.assert(arg in Config.displayPanes, _("error.invalidArgument", arg)); dactyl.assert(arg in Config.displayPanes, _("error.invalidArgument", arg));
// TODO: focus when we have better key handling of these extended modes // TODO: focus when we have better key handling of these extended modes
config.openDisplayPane(Config.displayPanes[arg]); config.openDisplayPane(Config.displayPanes[arg]);
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) completion.displayPane(context), completer: function (context) {
completion.displayPane(context);
},
literal: 0 literal: 0
}); });
@@ -316,7 +318,7 @@ const Config = Module("config", ConfigBase, {
prefs.set("browser.offline", ioService.offline); prefs.set("browser.offline", ioService.offline);
return value; return value;
}, },
getter: function () !services.io.offline getter: function () { return !services.io.offline; }
}); });
}, },
services: function initServices(dactyl, modules, window) { services: function initServices(dactyl, modules, window) {

View File

@@ -486,11 +486,12 @@ const Player = Module("player", {
"chrome://songbird/content/mediapages/filtersPage.xul"); "chrome://songbird/content/mediapages/filtersPage.xul");
// TODO: make this player.focusTrack work ? // TODO: make this player.focusTrack work ?
player.focusTrack(view.getItemByIndex(0)); player.focusTrack(view.getItemByIndex(0));
}, }, {
{
argCount: "1", argCount: "1",
literal: 0 literal: 0
//completer: function (context, args) completion.tracks(context, args); //completer: function (context, args) {
// completion.tracks(context, args);
//}
}); });
commands.add(["load"], commands.add(["load"],
@@ -513,10 +514,11 @@ const Player = Module("player", {
// load main library if there are no args // load main library if there are no args
_SBShowMainLibrary(); _SBShowMainLibrary();
} }
}, }, {
{
argCount: "?", argCount: "?",
completer: function (context, args) completion.playlist(context), completer: function (context) {
completion.playlist(context);
},
literal: 0 literal: 0
}); });
@@ -595,10 +597,11 @@ const Player = Module("player", {
} }
dactyl.echoerr(_("error.invalidArgument", arg)); dactyl.echoerr(_("error.invalidArgument", arg));
} }
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) completion.mediaView(context), completer: function (context) {
completion.mediaView(context);
},
literal: 0 literal: 0
}); });
@@ -606,17 +609,22 @@ const Player = Module("player", {
"Sort the current media view", "Sort the current media view",
function (args) { function (args) {
player.sortBy(args[0], args["-order"] == "up"); player.sortBy(args[0], args["-order"] == "up");
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) completion.mediaListSort(context), completer: function (context) {
completion.mediaListSort(context);
},
options: [ options: [
{ {
names: ["-order", "-o"], type: CommandOption.STRING, names: ["-order", "-o"], type: CommandOption.STRING,
default: "up", default: "up",
description: "Specify the sorting order of the given field", description: "Specify the sorting order of the given field",
validator: function (arg) /^(up|down)$/.test(arg), validator: function (arg) {
completer: function () [["up", "Sort in ascending order"], ["down", "Sort in descending order"]] return /^(up|down)$/.test(arg);
},
completer: function () {
return [["up", "Sort in ascending order"], ["down", "Sort in descending order"]];
}
} }
] ]
}); });
@@ -645,8 +653,7 @@ const Player = Module("player", {
gMM.sequencer.playView(mainView, gMM.sequencer.playView(mainView,
mainView.getIndexForItem(library.getItemsByProperties(properties).queryElementAt(0, Ci.sbIMediaItem))); mainView.getIndexForItem(library.getItemsByProperties(properties).queryElementAt(0, Ci.sbIMediaItem)));
player.focusPlayingTrack(); player.focusPlayingTrack();
}, }, {
{
argCount: "+", argCount: "+",
completer: function (context, args) { completer: function (context, args) {
if (args.completeArg == 0) if (args.completeArg == 0)
@@ -815,21 +822,29 @@ const Player = Module("player", {
"Set the playback repeat mode", "Set the playback repeat mode",
"number", 0, "number", 0,
{ {
setter: function (value) gMM.sequencer.repeatMode = value, setter: function (value) {
getter: function () gMM.sequencer.repeatMode, return gMM.sequencer.repeatMode = value;
completer: function (context) [ },
getter: function () { return gMM.sequencer.repeatMode; },
completer: function () {
return [
["0", "Repeat none"], ["0", "Repeat none"],
["1", "Repeat one"], ["1", "Repeat one"],
["2", "Repeat all"] ["2", "Repeat all"]
] ];
}
}); });
options.add(["shuffle"], options.add(["shuffle"],
"Play tracks in shuffled order", "Play tracks in shuffled order",
"boolean", false, "boolean", false,
{ {
setter: function (value) gMM.sequencer.mode = value ? gMM.sequencer.MODE_SHUFFLE : gMM.sequencer.MODE_FORWARD, setter: function (value) {
getter: function () gMM.sequencer.mode == gMM.sequencer.MODE_SHUFFLE return gMM.sequencer.mode = value ? gMM.sequencer.MODE_SHUFFLE : gMM.sequencer.MODE_FORWARD;
},
getter: function () {
return gMM.sequencer.mode == gMM.sequencer.MODE_SHUFFLE;
}
}); });
} }
}); });

View File

@@ -153,13 +153,12 @@ var Config = Module("config", ConfigBase, {
} }
return dactyl.echoerr(_("error.invalidArgument", args[0])); return dactyl.echoerr(_("error.invalidArgument", args[0]));
}, }, {
{
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (context) { completer: function (context) {
context.ignoreCase = true; context.ignoreCase = true;
return completion.sidebar(context); completion.sidebar(context);
}, },
literal: 0 literal: 0
}); });
@@ -171,10 +170,9 @@ var Config = Module("config", ConfigBase, {
this.forceTarget = dactyl.NEW_WINDOW; this.forceTarget = dactyl.NEW_WINDOW;
this.execute(args[0], null, true); this.execute(args[0], null, true);
}); });
}, }, {
{
argCount: "1", argCount: "1",
completer: function (context) completion.ex(context), completer: function (context) { completion.ex(context); },
literal: 0, literal: 0,
subCommand: 0 subCommand: 0
}); });
@@ -191,10 +189,11 @@ var Config = Module("config", ConfigBase, {
dactyl.open(args[0], dactyl.NEW_WINDOW); dactyl.open(args[0], dactyl.NEW_WINDOW);
else else
dactyl.open("about:blank", dactyl.NEW_WINDOW); dactyl.open("about:blank", dactyl.NEW_WINDOW);
}, {
completer: function (context) { completion.url(context); },
domains: function (args) {
return commands.get("open").domains(args);
}, },
{
completer: function (context) completion.url(context),
domains: function (args) commands.get("open").domains(args),
literal: 0, literal: 0,
privateData: true privateData: true
}); });
@@ -242,7 +241,7 @@ var Config = Module("config", ConfigBase, {
window.BrowserOffline.toggleOfflineStatus(); window.BrowserOffline.toggleOfflineStatus();
return value; return value;
}, },
getter: function () !services.io.offline getter: function () { return !services.io.offline; }
}); });
} }
}); });

View File

@@ -164,7 +164,9 @@ var Config = Module("config", ConfigBase, {
window.MailOfflineMgr.toggleOfflineStatus(); window.MailOfflineMgr.toggleOfflineStatus();
return value; return value;
}, },
getter: function () window.MailOfflineMgr.isOnline() getter: function () {
return window.MailOfflineMgr.isOnline();
}
}); });
} }
}); });

View File

@@ -405,10 +405,11 @@ var Mail = Module("mail", {
MsgOpenNewTabForFolder(folder.URI); MsgOpenNewTabForFolder(folder.URI);
else else
SelectFolder(folder.URI); SelectFolder(folder.URI);
}, }, {
{
argCount: "?", argCount: "?",
completer: function (context) completion.mailFolder(context), completer: function (context) {
completion.mailFolder(context);
},
count: true, count: true,
literal: 0 literal: 0
}); });
@@ -449,19 +450,25 @@ var Mail = Module("mail", {
commands.add(["copy[to]"], commands.add(["copy[to]"],
"Copy selected messages", "Copy selected messages",
function (args) { mail._moveOrCopy(true, args.literalArg); }, function (args) {
{ mail._moveOrCopy(true, args.literalArg);
}, {
argCount: "1", argCount: "1",
completer: function (context) completion.mailFolder(context), completer: function (context) {
completion.mailFolder(context);
},
literal: 0 literal: 0
}); });
commands.add(["move[to]"], commands.add(["move[to]"],
"Move selected messages", "Move selected messages",
function (args) { mail._moveOrCopy(false, args.literalArg); }, function (args) {
{ mail._moveOrCopy(false, args.literalArg);
}, {
argCount: "1", argCount: "1",
completer: function (context) completion.mailFolder(context), completer: function (context) {
completion.mailFolder(context);
},
literal: 0 literal: 0
}); });
@@ -875,7 +882,9 @@ var Mail = Module("mail", {
"Set the archive folder", "Set the archive folder",
"string", "Archive", "string", "Archive",
{ {
completer: function (context) completion.mailFolder(context) completer: function (context) {
completion.mailFolder(context);
}
}); });
// TODO: generate the possible values dynamically from the menu // TODO: generate the possible values dynamically from the menu
@@ -893,25 +902,29 @@ var Mail = Module("mail", {
return value; return value;
}, },
completer: function (context) [ completer: function () {
return [
["inherit", "Default View"], // FIXME: correct description? ["inherit", "Default View"], // FIXME: correct description?
["classic", "Classic View"], ["classic", "Classic View"],
["wide", "Wide View"], ["wide", "Wide View"],
["vertical", "Vertical View"] ["vertical", "Vertical View"]
] ];
}
}); });
options.add(["smtpserver", "smtp"], options.add(["smtpserver", "smtp"],
"Set the default SMTP server", "Set the default SMTP server",
"string", services.smtp.defaultServer.key, // TODO: how should we handle these persistent external defaults - "inherit" or null? "string", services.smtp.defaultServer.key, // TODO: how should we handle these persistent external defaults - "inherit" or null?
{ {
getter: function () services.smtp.defaultServer.key, getter: function () { return services.smtp.defaultServer.key; },
setter: function (value) { setter: function (value) {
let server = mail.smtpServers.filter(s => s.key == value)[0]; let server = mail.smtpServers.filter(s => s.key == value)[0];
services.smtp.defaultServer = server; services.smtp.defaultServer = server;
return value; return value;
}, },
completer: function (context) [[s.key, s.serverURI] for ([, s] in Iterator(mail.smtpServers))] completer: function () {
return [[s.key, s.serverURI] for ([, s] in Iterator(mail.smtpServers))];
}
}); });
/*options.add(["threads"], /*options.add(["threads"],