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

Add some standard JS function completers for the liberator API

This commit is contained in:
Kris Maglione
2008-11-12 23:55:34 +00:00
parent 5221fb41be
commit d7076c5aa5
6 changed files with 66 additions and 35 deletions

View File

@@ -227,6 +227,11 @@ function Commands() //{{{
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.registerObserver("load_completion", function ()
{
completion.setFunctionCompleter(commands.get, [function () ([c.name, c.description] for (c in commands))]);
});
var commandManager = {
// FIXME: remove later, when our option handler is better

View File

@@ -27,9 +27,7 @@ the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/
// An eval with a cleaner lexical scope.
// TODO: that shows up in ":echo modules", can we move it "inside" the Completion class? --mst
const EVAL_TMP = "__liberator_eval_tmp";
function __eval(__liberator_eval_arg, __liberator_eval_tmp)
modules._cleanEval = function (__liberator_eval_arg, __liberator_eval_tmp)
{
return window.eval(__liberator_eval_arg);
}
@@ -47,6 +45,10 @@ function Completion() //{{{
}
catch (e) {}
const EVAL_TMP = "__liberator_eval_tmp";
const cleanEval = _cleanEval;
delete modules._cleanEval;
// the completion substrings, used for showing the longest common match
var cacheFilter = {}
var cacheResults = {}
@@ -205,7 +207,7 @@ function Completion() //{{{
try
{
return cache[key] = __eval(arg, tmp);
return cache[key] = cleanEval(arg, tmp);
}
catch (e)
{
@@ -361,7 +363,7 @@ function Completion() //{{{
}
catch (e)
{
liberator.dump(util.escapeString(string) + ": " + e + "\n" + e.stack);
// liberator.dump(util.escapeString(string) + ": " + e + "\n" + e.stack);
lastIdx = 0;
return [0, []];
}
@@ -480,14 +482,13 @@ function Completion() //{{{
let [offset, obj, func] = getObjKey(-3);
let key = str.substring(get(-2, 0, STATEMENTS), top[OFFSET]) + "''";
let completer = this.completers[func];
try
{
if (!completer)
completer = obj[func].liberatorCompleter;
var completer = obj[func].liberatorCompleter;
}
catch (e) {}
liberator.dump({ call: completer, func: func, obj: obj, string: string, args: "args" });
if (!completer)
completer = this.completers[func];
if (!completer)
return [0, []];
@@ -502,6 +503,8 @@ function Completion() //{{{
args.push(key);
let compl = completer.call(this, func, obj, string, args);
if (!(compl instanceof Array))
compl = [v for (v in compl)];
key = this.eval(key);
return [top[OFFSET], this.filter(compl, key + string, last, key.length)];
}
@@ -636,6 +639,16 @@ function Completion() //{{{
return {
setFunctionCompleter: function (func, completers)
{
func.liberatorCompleter = function (func, obj, string, args) {
let completer = completers[args.length - 1];
if (!completer)
return [];
return completer.call(this, this.eval(obj), this.eval(args.pop()) + string, args);
};
},
// returns the longest common substring
// used for the 'longest' setting for wildmode
getLongestSubstring: function getLongestSubstring()
@@ -982,17 +995,10 @@ function Completion() //{{{
return mapped;
};
try
{
if (tail)
return [dir.length, this.cached("file-" + dir, compl, generate, "filter", [true])];
else
return [0, this.cached("file-" + dir, filter, generate, "filter", [true])];
}
catch (e)
{
liberator.dump(e);
}
if (tail)
return [dir.length, this.cached("file-" + dir, compl, generate, "filter", [true])];
else
return [0, this.cached("file-" + dir, filter, generate, "filter", [true])];
},
help: function help(filter)
@@ -1028,15 +1034,7 @@ function Completion() //{{{
javascript: function _javascript(str)
{
try
{
return javascript.complete(str);
}
catch (e)
{
liberator.dump(e);
return [0, []];
}
return javascript.complete(str);
},
macro: function macro(filter)

View File

@@ -171,6 +171,12 @@ function AutoCommands() //{{{
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.registerObserver("load_completion", function ()
{
completion.setFunctionCompleter(autocommands.get, [function () config.autocommands]);
});
return {
__iterator__: function () util.Array.iterator(store),

View File

@@ -258,6 +258,23 @@ function Mappings() //{{{
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
liberator.registerObserver("load_completion", function ()
{
completion.setFunctionCompleter(mappings.get,
[
null,
function (obj, filter, args)
{
let mode = this.eval(args[0]);
return util.Array.flatten(
[
[[name, map.description] for ([i, name] in Iterator(map.names))]
for ([i, map] in Iterator(user[mode].concat(main[mode])))
])
}
]);
});
// FIXME:
Mappings.flags = {
ALLOW_EVENT_ROUTING: 1 << 0, // if set, return true inside the map command to pass the event further to firefox

View File

@@ -49,10 +49,6 @@ const modes = (function () //{{{
else if (passAllKeys && !passNextKey)
return "-- PASS THROUGH --";
var ext = "";
if (extended & modes.MENU) // TODO: desirable?
ext += " (menu)";
// when recording a macro
var macromode = "";
if (modes.isRecording)
@@ -60,6 +56,9 @@ const modes = (function () //{{{
else if (modes.isReplaying)
macromode = "replaying";
var ext = "";
if (extended & modes.MENU) // TODO: desirable?
ext += " (menu)";
ext += " --" + macromode;
switch (main)
@@ -67,9 +66,9 @@ const modes = (function () //{{{
case modes.INSERT:
return "-- INSERT" + ext;
case modes.VISUAL:
return (extended & modes.LINE) ? "-- VISUAL LINE" + ext : "-- VISUAL" + ext;
return "-- VISUAL" + (extended & modes.LINE ? " LINE" : "") + ext;
case modes.COMMAND_LINE:
// under modes.COMMAND_LINE, this block will never be reached
// under modes.COMMAND_LINE, this function will never be called
return macromode;
case modes.CARET:
return "-- CARET" + ext;

View File

@@ -847,6 +847,12 @@ function Options() //{{{
////////////////////// PUBLIC SECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
// TODO: Does this belong elsewhere?
liberator.registerObserver("load_completion", function ()
{
completion.setFunctionCompleter(options.get, [function () ([o.name, o.description] for (o in options))]);
});
return {
OPTION_SCOPE_GLOBAL: 1,