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

More completion stuff

This commit is contained in:
Kris Maglione
2008-11-22 09:56:57 +00:00
parent ef0b517d3f
commit 49a559866c
14 changed files with 58 additions and 56 deletions

View File

@@ -322,7 +322,7 @@ function Bookmarks() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter) completion.bookmark(filter), completer: function (context) completion.bookmark(context.filter),
options: [[["-tags", "-T"], commands.OPTION_LIST]] options: [[["-tags", "-T"], commands.OPTION_LIST]]
}); });
@@ -335,7 +335,7 @@ function Bookmarks() //{{{
liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE); liberator.echo(deletedCount + " bookmark(s) with url `" + url + "' deleted", commandline.FORCE_SINGLELINE);
}, },
{ completer: function (filter) completion.bookmark(filter) }); { completer: function (context) completion.bookmark(context.filter) });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// PUBLIC SECTION ////////////////////////////////////////// ////////////////////// PUBLIC SECTION //////////////////////////////////////////
@@ -623,8 +623,9 @@ function History() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter) completer: function (context)
{ {
let filter = context.filter;
var sh = getWebNavigation().sessionHistory; var sh = getWebNavigation().sessionHistory;
var completions = []; var completions = [];
for (let i = sh.index - 1; i >= 0; i--) for (let i = sh.index - 1; i >= 0; i--)
@@ -673,8 +674,9 @@ function History() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter) completer: function (context)
{ {
let filter = context.filter;
var sh = getWebNavigation().sessionHistory; var sh = getWebNavigation().sessionHistory;
var completions = []; var completions = [];
for (let i = sh.index + 1; i < sh.count; i++) for (let i = sh.index + 1; i < sh.count; i++)

View File

@@ -512,7 +512,7 @@ function Buffer() //{{{
stylesheetSwitchAll(window.content, args); stylesheetSwitchAll(window.content, args);
}, },
{ completer: function (filter) completion.alternateStylesheet(filter) }); { completer: function (context) completion.alternateStylesheet(context.filter) });
commands.add(["re[load]"], commands.add(["re[load]"],
"Reload current page", "Reload current page",
@@ -564,7 +564,7 @@ function Buffer() //{{{
{ {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (filter, bang, args, context) completion.file(context) completer: function (context) completion.file(context)
}); });
commands.add(["st[op]"], commands.add(["st[op]"],
@@ -578,7 +578,7 @@ function Buffer() //{{{
{ {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (filter, bang, args, context) completion.url(context, "bhf") completer: function (context) completion.url(context, "bhf")
}); });
commands.add(["zo[om]"], commands.add(["zo[om]"],

View File

@@ -825,7 +825,7 @@ function Commands() //{{{
{ {
argCount: "2", argCount: "2",
bang: true, bang: true,
completer: function (filter) completion.userCommand(filter), completer: function (context) completion.userCommand(context.filter),
options: [ options: [
[["-nargs"], commandManager.OPTION_STRING, [["-nargs"], commandManager.OPTION_STRING,
function (arg) /^[01*?+]$/.test(arg), ["0", "1", "*", "?", "+"]], function (arg) /^[01*?+]$/.test(arg), ["0", "1", "*", "?", "+"]],
@@ -873,7 +873,7 @@ function Commands() //{{{
}, },
{ {
argCount: "1", argCount: "1",
completer: function (filter) completion.userCommand(filter) completer: function (context) completion.userCommand(context.filter)
}); });
//}}} //}}}

View File

@@ -1080,7 +1080,7 @@ function Completion() //{{{
if (args) if (args)
{ {
// XXX, XXX, XXX // XXX, XXX, XXX
compObject = command.completer.call(command, args.string, special, args, context); compObject = command.completer.call(command, context, args, special, count);
if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects if (compObject instanceof Array) // for now at least, let completion functions return arrays instead of objects
compObject = { start: compObject[0], items: compObject[1] }; compObject = { start: compObject[0], items: compObject[1] };
if (args.completions) if (args.completions)

View File

@@ -114,7 +114,7 @@ function AutoCommands() //{{{
{ {
argCount: "3", argCount: "3",
bang: true, bang: true,
completer: function (filter) completion.autocmdEvent(filter), completer: function (context) completion.autocmdEvent(context.filter),
literal: true literal: true
}); });
@@ -127,7 +127,7 @@ function AutoCommands() //{{{
}, },
{ {
argCount: "+", argCount: "+",
completer: function (filter) completion.autocmdEvent(filter) completer: function (context) completion.autocmdEvent(context.filter)
} }
); );
@@ -164,7 +164,7 @@ function AutoCommands() //{{{
{ {
// TODO: Vim actually just displays "No matching autocommands" when no arg is specified // TODO: Vim actually just displays "No matching autocommands" when no arg is specified
argCount: "+", argCount: "+",
completer: function (filter) completion.autocmdEvent(filter) completer: function (context) completion.autocmdEvent(context.filter)
} }
); );
@@ -719,7 +719,7 @@ function Events() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter) completion.macro(filter) completer: function (context) completion.macro(context.filter)
}); });
commands.add(["macros"], commands.add(["macros"],
@@ -730,14 +730,14 @@ function Events() //{{{
var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args.string)); var str = template.tabular(["Macro", "Keys"], [], events.getMacros(args.string));
liberator.echo(str, commandline.FORCE_MULTILINE); liberator.echo(str, commandline.FORCE_MULTILINE);
}, },
{ completer: function (filter) completion.macro(filter) }); { completer: function (context) completion.macro(context.filter) });
commands.add(["pl[ay]"], commands.add(["pl[ay]"],
"Replay a recorded macro", "Replay a recorded macro",
function (args) { events.playMacro(args.arguments[0]); }, function (args) { events.playMacro(args.arguments[0]); },
{ {
argCount: "1", argCount: "1",
completer: function (filter) completion.macro(filter) completer: function (context) completion.macro(context.filter)
}); });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}

View File

@@ -208,7 +208,7 @@ function IO() //{{{
}, },
{ {
argCount: "?", argCount: "?",
completer: function (filter, bang, args, context) completion.file(context, true), completer: function (context) completion.file(context, true),
literal: true literal: true
}); });
@@ -268,7 +268,7 @@ function IO() //{{{
{ {
argCount: "?", argCount: "?",
bang: true, bang: true,
completer: function (filter, bang, args, context) completion.file(context, true) completer: function (context) completion.file(context, true)
}); });
commands.add(["runt[ime]"], commands.add(["runt[ime]"],
@@ -301,7 +301,7 @@ function IO() //{{{
{ {
argCount: "1", argCount: "1",
bang: true, bang: true,
completer: function (filter, bang, args, context) completion.file(context, true) completer: function (context) completion.file(context, true)
}); });
commands.add(["!", "run"], commands.add(["!", "run"],
@@ -339,7 +339,7 @@ function IO() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter) completion.shellCommand(filter) completer: function (context) completion.shellCommand(filter)
}); });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}

View File

@@ -202,7 +202,7 @@ const liberator = (function () //{{{
{ {
argCount: "1", argCount: "1",
bang: true, bang: true,
completer: function (filter) completion.dialog(filter) completer: function (context) completion.dialog(context.filter)
}); });
// TODO: move this // TODO: move this
@@ -257,10 +257,10 @@ const liberator = (function () //{{{
{ {
argCount: "+", // NOTE: single arg may contain unescaped whitespace argCount: "+", // NOTE: single arg may contain unescaped whitespace
// TODO: add this as a standard menu completion function // TODO: add this as a standard menu completion function
completer: function (filter) completer: function (context)
{ {
let completions = getMenuItems().map(function (item) [item.fullMenuPath, item.label]); let completions = getMenuItems().map(function (item) [item.fullMenuPath, item.label]);
return [0, completion.filter(completions, filter)]; return [0, completion.filter(completions, context.filter)];
} }
}); });
@@ -307,7 +307,7 @@ const liberator = (function () //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter) completion.help(filter) completer: function (context) completion.help(context.filter)
}); });
commands.add(["javas[cript]", "js"], commands.add(["javas[cript]", "js"],
@@ -334,7 +334,7 @@ const liberator = (function () //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter, bang, args, context) completion.javascript(context), completer: function (context) completion.javascript(context),
hereDoc: true hereDoc: true
}); });
@@ -461,12 +461,12 @@ const liberator = (function () //{{{
{ {
argCount: "+", argCount: "+",
bang: true, bang: true,
completer: function (filter) completer: function (context)
{ {
if (/^:/.test(filter)) if (/^:/.test(context.filter))
return completion.ex(filter); return completion.ex(context);
else else
return completion.javascript(filter); return completion.javascript(context);
}, },
count: true count: true
}); });

View File

@@ -684,7 +684,7 @@ function Mail() //{{{
SelectFolder(folder.URI); SelectFolder(folder.URI);
}, },
{ {
completer: function (filter) getFolderCompletions(filter), completer: function (context) getFolderCompletions(context.filter),
count: true count: true
}); });
@@ -726,12 +726,12 @@ function Mail() //{{{
commands.add(["copy[to]"], commands.add(["copy[to]"],
"Copy selected messages", "Copy selected messages",
function (args) { moveOrCopy(true, args.string); }, function (args) { moveOrCopy(true, args.string); },
{ completer: function (filter) getFolderCompletions(filter) }); { completer: function (context) getFolderCompletions(context.filter) });
commands.add(["move[to]"], commands.add(["move[to]"],
"Move selected messages", "Move selected messages",
function (args) { moveOrCopy(false, args.string); }, function (args) { moveOrCopy(false, args.string); },
{ completer: function (filter) getFolderCompletions(filter) }); { completer: function (context) getFolderCompletions(context.filter) });
commands.add(["empty[trash]"], commands.add(["empty[trash]"],
"Empty trash of the current account", "Empty trash of the current account",

View File

@@ -186,7 +186,7 @@ function Mappings() //{{{
const opts = { const opts = {
argCount: "2", argCount: "2",
completer: function (filter) completion.userMapping(filter, modes), completer: function (context) completion.userMapping(context.filter, modes),
options: [ options: [
[["<silent>", "<Silent>"], commands.OPTION_NOARG] [["<silent>", "<Silent>"], commands.OPTION_NOARG]
], ],
@@ -245,7 +245,7 @@ function Mappings() //{{{
if (!found) if (!found)
liberator.echoerr("E31: No such mapping"); liberator.echoerr("E31: No such mapping");
}, },
{ completer: function (filter) completion.userMapping(filter, modes) }); { completer: function (context) completion.userMapping(context.filter, modes) });
} }
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}

View File

@@ -394,9 +394,9 @@ function Options() //{{{
{ {
bang: true, bang: true,
count: true, count: true,
completer: function (filter, special, count) completer: function (context, args, special, count)
{ {
return commands.get("set").completer(filter, special, count, { scope: options.OPTION_SCOPE_LOCAL }); return commands.get("set").completer(context.filter, special, count, { scope: options.OPTION_SCOPE_LOCAL });
} }
} }
); );
@@ -410,9 +410,9 @@ function Options() //{{{
{ {
bang: true, bang: true,
count: true, count: true,
completer: function (filter, special, count) completer: function (context, args, special, count)
{ {
return commands.get("set").completer(filter, special, count, { scope: options.OPTION_SCOPE_GLOBAL }); return commands.get("set").completer(context.filter, special, count, { scope: options.OPTION_SCOPE_GLOBAL });
} }
} }
); );
@@ -686,7 +686,7 @@ function Options() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter, special, count, modifiers) completer: function (context, args, special, count, modifiers)
{ {
var optionCompletions = []; var optionCompletions = [];

View File

@@ -389,7 +389,7 @@ liberator.registerObserver("load_commands", function ()
}, },
{ {
argCount: 1, argCount: 1,
completer: function (filter) completion.colorScheme(filter) completer: function (context) completion.colorScheme(context.filter)
}); });
commands.add(["sty[le]"], commands.add(["sty[le]"],
@@ -430,7 +430,7 @@ liberator.registerObserver("load_commands", function ()
{ {
argCount: "2", argCount: "2",
bang: true, bang: true,
completer: function (filter, bang, args) { completer: function (context, args, bang) {
let compl = []; let compl = [];
if (args.completeArg == 0) if (args.completeArg == 0)
{ {
@@ -467,12 +467,13 @@ liberator.registerObserver("load_commands", function ()
}, },
{ {
argCount: "2", argCount: "2",
completer: function (filter) [0, completion.filter( // FIXME: Ugly.
completer: function (context) [0, completion.filter(
[[i, <>{s.sites.join(",")}: {s.css.replace("\n", "\\n")}</>] [[i, <>{s.sites.join(",")}: {s.css.replace("\n", "\\n")}</>]
for ([i, s] in styles.userSheets) for ([i, s] in styles.userSheets)
] ]
.concat([[s, ""] for each (s in styles.sites)]) .concat([[s, ""] for each (s in styles.sites)])
, filter)], , context.filter)],
literal: true, literal: true,
options: [[["-index", "-i"], commands.OPTION_INT, null, function () [[k, v.name || v.sites.join(",") + " " + v.css] for ([k, v] in Iterator(styles.userNames))]], options: [[["-index", "-i"], commands.OPTION_INT, null, function () [[k, v.name || v.sites.join(",") + " " + v.css] for ([k, v] in Iterator(styles.userNames))]],
[["-name", "-n"], commands.OPTION_STRING, null, function () [[k, v.css] for ([k, v] in Iterator(styles.userNames))]]] [["-name", "-n"], commands.OPTION_STRING, null, function () [[k, v.css] for ([k, v] in Iterator(styles.userNames))]]]
@@ -513,9 +514,8 @@ liberator.registerObserver("load_commands", function ()
argCount: "2", argCount: "2",
bang: true, bang: true,
// TODO: add this as a standard highlight completion function? // TODO: add this as a standard highlight completion function?
// I agree. It could (should) be much more sophisticated. --Kris completer: function (context) [0,
completer: function (filter) [0, completion.filter([[v.class, ""] for (v in highlight)], context.filter)
completion.filter([[v.class, ""] for (v in highlight)], filter)
], ],
hereDoc: true, hereDoc: true,
literal: true, literal: true,

View File

@@ -354,7 +354,7 @@ function Tabs() //{{{
{ {
bang: true, bang: true,
count: true, count: true,
completer: function (filter) completion.buffer(filter) completer: function (context) completion.buffer(context.filter)
}); });
// TODO: this should open in a new tab positioned directly after the current one, not at the end // TODO: this should open in a new tab positioned directly after the current one, not at the end
@@ -368,7 +368,7 @@ function Tabs() //{{{
}, },
{ {
argCount: "+", argCount: "+",
completer: function (filter) completion.ex(filter) completer: function (context) completion.ex(context.filter)
}); });
commands.add(["tabl[ast]", "bl[ast]"], commands.add(["tabl[ast]", "bl[ast]"],
@@ -478,7 +478,7 @@ function Tabs() //{{{
{ {
bang: true, bang: true,
count: true, count: true,
completer: function (filter) completion.buffer(filter) completer: function (context) completion.buffer(context.filter)
}); });
commands.add(["buffers", "files", "ls", "tabs"], commands.add(["buffers", "files", "ls", "tabs"],
@@ -548,7 +548,7 @@ function Tabs() //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter, bang, args, context) completion.url(context) completer: function (context) completion.url(context)
}); });
commands.add(["tabde[tach]"], commands.add(["tabde[tach]"],
@@ -618,7 +618,7 @@ function Tabs() //{{{
undoCloseTab(count - 1); undoCloseTab(count - 1);
}, },
{ {
completer: function (filter) completer: function (context)
{ {
// get closed-tabs from nsSessionStore // get closed-tabs from nsSessionStore
var ss = Components.classes["@mozilla.org/browser/sessionstore;1"] var ss = Components.classes["@mozilla.org/browser/sessionstore;1"]
@@ -629,7 +629,7 @@ function Tabs() //{{{
{ {
var url = undoItems[i].state.entries[0].url; var url = undoItems[i].state.entries[0].url;
var title = undoItems[i].title; var title = undoItems[i].title;
if (completion.match([url, title], filter, false)) if (completion.match([url, title], context.filter, false))
completions.push([url, title]); completions.push([url, title]);
} }
return [0, completions]; return [0, completions];

View File

@@ -500,7 +500,7 @@ function CommandLine() //{{{
if (str != null) if (str != null)
command.action(str); command.action(str);
}, },
{ completer: function (filter, bang, args, context) completion.javascript(context) }); { completer: function (context) completion.javascript(context) });
}); });
commands.add(["mes[sages]"], commands.add(["mes[sages]"],

View File

@@ -293,7 +293,7 @@ const config = { //{{{
}, },
{ {
bang: true, bang: true,
completer: function (filter, args, bang, context) completion.url(context) completer: function (context) completion.url(context)
}); });
commands.add(["redr[aw]"], commands.add(["redr[aw]"],
@@ -345,7 +345,7 @@ const config = { //{{{
}, },
{ {
argCount: "+", argCount: "+",
completer: function (filter) completion.sidebar(filter) completer: function (context) completion.sidebar(context.filter)
}); });
commands.add(["winc[lose]", "wc[lose]"], commands.add(["winc[lose]", "wc[lose]"],
@@ -364,7 +364,7 @@ const config = { //{{{
else else
liberator.open("about:blank", liberator.NEW_WINDOW); liberator.open("about:blank", liberator.NEW_WINDOW);
}, },
{ completer: function (filter, bang, args, context) completion.url(context) }); { completer: function (context) completion.url(context) });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// OPTIONS ///////////////////////////////////////////////// ////////////////////// OPTIONS /////////////////////////////////////////////////