liberator.modules.commands.addUserCommand commands.addUserCommandまたは
liberator.modules.commands.add commands.addaddメソッドはVimperator自身が使用するメソッドである。また、addメソッドの場合第5引数がなく、既に存在するコマンドの置き換えは不可能である。
commands.addUseCommand( ["he[llo]","h"], // コマンド名 "description", // コマンドの説明 function(args, bang, count) {... }, // コマンド本体の処理(functionオブジェクト) { /* extras */ completer : function (context, args) { // 補完関数 context.anchor = false; // (省略可) context.ignoreCase = true; // (省略可) context.title = ["url", "title"]; context.completions = [ ["候補1URL", "候補タイトル1"], ["候補2URL", "候補タイトル2"], ]; }, options : [ [["-optionA", "-a"], OPTION_ANY, function(arg) {... }, // オプション値の正当性をチェックする関数? function(context) {... }, // ]], argCount: "*", // "0"|"1"|"+"|"?"|"*" hereDoc: false, // ヒアドキュメントとして受け取るか bang: false, // !を許可するか count: false, // 回数指定で実行可能か literal: false // リテラルとして扱うか }, replace // 既存のコマンドを置き換えるかどうか );
commands.addUserCommand( ["hello[world]","hw"], "print hello world", function(){ liberator.echo("Hello World"); } );コマンド名となる文字列の後部を[]で囲むと省略可能とされてhelloworld,helloの2つに展開される。
contenxt.title = ["名前"];もしくは
context.title = ["名前","概要"];の様に代入する。
context.completions = [ ["候補値_1(String)","候補値_1の説明(String)"], ["候補値_2(String)","候補値_2の説明(String)"], ];の様に代入する。
completer: function(context, arg){ context.title = ["exampleplugin"]; let allSuggestions = [ ["foo","foo description"], ["bar","bar description"], ["hoge","hoge description"] ]; context.completions = allSuggestions; },Vimperator内部で自動的にフィルタリングしてくれるので、特にこちらでフィルタする必要はない。
completer: function(context, args){ context.ignoreCase = true; //大文字/小文字の区別をなくす context.completions = [ ["bar","bar desc"], //... ]; },
:bmark http://example.com/ -title Example -T example,Tag -k keywordとすると解析された結果は
args = ["http://example.com"]; args["-title"] = "Example"; args["-tags"] = ["example","Tag"]; args["-keyword"] = "keyword";となる。bmarkコマンドのoptionsの定義は以下の様になっている。
options: [ [["-title", "-t"], commands.OPTION_STRING], [["-tags", "-T"], commands.OPTION_LIST], [["-keyword", "-k"], commands.OPTION_STRING, function(arg) { return /\w/.test(arg); }] ],
@param str: something like "-x=foo -opt=bar arg1 arg2" "options" is an array [name, type, validator, completions] and could look like: options = [[["-force"], OPTION_NOARG], [["-fullscreen", "-f"], OPTION_BOOL], [["-language"], OPTION_STRING, validateFunc, ["perl", "ruby"]], [["-speed"], OPTION_INT], [["-acceleration"], OPTION_FLOAT], [["-accessories"], OPTION_LIST, null, ["foo", "bar"]], [["-other"], OPTION_ANY]];