Created
January 26, 2011 12:58
-
-
Save caisui/796646 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/common/content/commands.js b/common/content/commands.js | |
--- a/common/content/commands.js | |
+++ b/common/content/commands.js | |
@@ -915,14 +915,22 @@ | |
} | |
// highlight non-existent commands | |
- let command = commands.get(cmd); | |
+ let command = Commands.prototype.get.call(subCmds ? {_exCommands: subCmds} : commands, cmd); | |
if (!command) { | |
- context.highlight(0, cmd.length, "SPELLCHECK"); | |
+ if (!subCmds) | |
+ context.highlight(0, cmd.length, "SPELLCHECK"); | |
return; | |
} | |
// dynamically get completions as specified with the command's completer function | |
[prefix] = context.filter.match(/^(?:\w*[\s!]|!)\s*/); | |
+ if (command.subCommands.length) { | |
+ context.fork("sub_" + command.name, prefix.length, this, "ex", command.subCommands); | |
+ let list = context.contextList; | |
+ if (/\/args$/.test(list[list.length -1].name)) | |
+ return; | |
+ } | |
+ | |
let cmdContext = context.fork(cmd, prefix.length); | |
let argContext = context.fork("args", prefix.length); | |
args = command.parseArgs(cmdContext.filter, argContext, { count: count, bang: bang }); | |
@@ -949,9 +957,6 @@ | |
} | |
} | |
} | |
- | |
- if (command.subCommands.length > 0) | |
- context.fork("sub_" + cmd, prefix.length, this, "ex", command.subCommands); | |
}; | |
completion.userCommand = function userCommand(context) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//test | |
function num2chars(num) { | |
var hintchars = "ZABCDEFGHIJKLMNOPQRSTUVWXY"; | |
var chars = ""; | |
var base = hintchars.length; | |
do { | |
chars = hintchars[num % base] + chars; | |
num = Math.floor(num / base); | |
} while (num > 0); | |
return chars; | |
} | |
let res_str = [ | |
["optest1", "sub sub test1"], | |
["optest2", "sub sub test2"], | |
["optest3", "sub sub test3"], | |
["optest4", "sub sub test4"], | |
["optest5", "sub sub test5"], | |
] | |
function showme (args) { | |
liberator.echo("my name is " + this.name); | |
for ([,a] in Iterator(Object.getOwnPropertyNames(args))) | |
liberator.echo(a + " : " + args[a]); | |
} | |
commands.addUserCommand("cmdtop", "test", showme, { | |
completer: completion.file, | |
options: [ | |
[["-test", "-t"], commands.OPTION_LIST, null, [[num2chars(i), i] for (i in util.range(1, 10))], true], | |
], | |
literal: 0, | |
subCommands: [ | |
let (i = num2chars(i)) | |
Command("scmd" + i, "sub command test" + i, showme, { | |
options: [ | |
[["-noarg"]], | |
[["-int"], commands.OPTION_INT] | |
], | |
completer: function (context) { | |
context.title = [this.name + "'s completer", this.description]; | |
context.completions = [["comp" + this.name + ":" + j, this.name] for(j in util.range(1, 10))]; | |
}, | |
subCommands: [ | |
Command("sscmd" + i + num2chars(k), "sub sub commands " + k, showme, { | |
options:[ | |
[["-tab" + k, "-t"], commands.OPTION_STRING, null, res_str ] | |
], | |
completer: function (context) { | |
context.title = [this.name + "'s completer", this.description]; | |
context.completions = [[i, i * i * i] for (i in util.range(1, 10))]; | |
} | |
}, true) | |
for (k in util.range(1, 10))], | |
}) for (i in util.range(1, 10)) | |
] | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment