diff options
-rw-r--r-- | edit-vimperator-files.js | 8 | ||||
-rw-r--r-- | twittperator.js | 139 |
2 files changed, 87 insertions, 60 deletions
diff --git a/edit-vimperator-files.js b/edit-vimperator-files.js index 8584d84..b57fae6 100644 --- a/edit-vimperator-files.js +++ b/edit-vimperator-files.js @@ -38,7 +38,7 @@ let PLUGIN_INFO = <name>Edit Vimperator File</name> <description>Open vimperator files with text-editor.</description> <description lang="ja">Vimperator 関連のファイルをエディタで開く</description> - <version>1.2.0</version> + <version>1.2.1</version> <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> <license>new BSD License (Please read the source code comments of this plugin)</license> <license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license> @@ -58,7 +58,7 @@ let PLUGIN_INFO = // INFO {{{ let INFO = <> - <plugin name="EditVimperatorFile" version="1.2.0" + <plugin name="EditVimperatorFile" version="1.2.1" href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/edit-vimperator-files.js" summary="Open vimperator files with text-editor." lang="en-US" @@ -73,7 +73,7 @@ let INFO = <description><p></p></description> </item> </plugin> - <plugin name="EditVimperatorFile" version="1.2.0" + <plugin name="EditVimperatorFile" version="1.2.1" href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/edit-vimperator-files.js" summary="Vimperator 関連のファイルをエディタで開く" lang="ja" @@ -101,7 +101,7 @@ let INFO = let args = commands.parseArgs(options["editor"], [], "*", true); liberator.assert(args.length >= 1, "No editor specified"); args.push(path); - liberator.callFunctionInThread(null, io.run, io.expandPath(args.shift()), args, false); + io.run(io.expandPath(args.shift()), args); } let dirs = toArray(liberator.globalVariables.plugin_loader_roots || []).map(function (path) io.File(path).path); diff --git a/twittperator.js b/twittperator.js index c286a88..d2ba9d0 100644 --- a/twittperator.js +++ b/twittperator.js @@ -1897,6 +1897,12 @@ let PLUGIN_INFO = })(); // }}} const SubCommand = function(init) { // {{{ + if (!(init.completer instanceof Array)) + init.completer = [init.completer]; + + if (init.timelineCompleter) + init.completer = init.completer.map(makeTimelineCompleter); + return { __proto__: init, get expr() { @@ -1953,8 +1959,16 @@ let PLUGIN_INFO = command: ["?"], description: "Twitter search", action: function(arg) Twittperator.showTwitterSearchResult(arg), - timelineCompleter: true, - completer: Completers.text() + completer: [ + function (context, args) { + let lst = [[buffer.URL, 'Current Tab']]; + let w = buffer.getCurrentWord(); + if (w && w.length) + lst.push([w, 'Current word']); + context.completions = lst; + }, + makeTimelineCompleter(Completers.text()) + ] }), SubCommand({ command: ["/"], @@ -2094,59 +2108,81 @@ let PLUGIN_INFO = return result; } // }}} - function commandCompelter(context, args) { // {{{ + function setTimelineCompleter(context) { // {{{ function statusObjectFilter(item) let (desc = item.description) (this.match(desc.user.screen_name) || this.match(desc.text)); - function setTimelineCompleter() { - context.compare = void 0; - context.createRow = function(item, highlightGroup) { - let desc = item[1] || this.process[1].call(this, item, item.description); - - if (desc && desc.user) { - return <div highlight={highlightGroup || "CompItem"} style="white-space: nowrap"> - <li highlight="CompDesc"> - <img src={desc.user.profile_image_url} style="max-width: 24px; max-height: 24px"/> -  {desc.user.screen_name}: {desc.text} - </li> - </div>; - } + context.compare = void 0; + context.createRow = function(item, highlightGroup) { + let desc = item[1] || this.process[1].call(this, item, item.description); + if (desc && desc.user) { return <div highlight={highlightGroup || "CompItem"} style="white-space: nowrap"> - <li highlight="CompDesc">{desc} </li> + <li highlight="CompDesc"> + <img src={desc.user.profile_image_url} style="max-width: 24px; max-height: 24px"/> +  {desc.user.screen_name}: {desc.text} + </li> </div>; - }; + } + + return <div highlight={highlightGroup || "CompItem"} style="white-space: nowrap"> + <li highlight="CompDesc">{desc} </li> + </div>; + }; - context.filters = [statusObjectFilter]; + context.filters = [statusObjectFilter]; + context.title = ["Hidden", "Entry"]; + } // }}} + + function makeTimelineCompleter(completer) { // {{{ + return function (context, args) { + setTimelineCompleter(context); + return completer(context, args); } + } // }}} - let len = 0; + function subCommandCompleter(context, args) { // {{{ + if (!args.literalArg.match(/^(\W|\S+\s)/)) { + context.title = ["Sub command", "Description"]; + context.completions = SubCommands.map(function({ command, description }) [command[0], description]); + return; + } - if (args.bang) { - let [subCmd, m] = findSubCommand(args.literalArg) || []; - if (subCmd) { - if (subCmd.timelineCompleter) - setTimelineCompleter(); - context.title = ["Hidden", "Entry"]; - subCmd.completer(context, args); - len = m[0] === "@" ? 0 : m[0].length; - } - } else { - setTimelineCompleter(); - let arg = args.literalArg.slice(0, context.caret); - let m; - if (m = arg.match(/(RT\s+)@.*$/)) { - (m.index === 0 ? Completers.name_id - : Completers.name_id_text)(m.index === 0 && rejectMine)(context, args); - } else if (m = tailMatch(/(^|\b|\s)@[^@]*/, arg)) { - (m.index === 0 ? Completers.name_id(rejectMine) : Completers.name(rejectMine))(context, args); - } + let [subCmd, m] = findSubCommand(args.literalArg) || []; + if (!subCmd) + return; - if (m) - len = m.index + m[1].length; + context.offset += m[0] === "@" ? 0 : m[0].length; + let offset = context.offset; + + subCmd.completer.forEach(function (completer, index) { + context.fork( + "TwittperatorSubCommand" + index, 0, context, + function (context) { + context.offset = offset; + return completer(context, args); + } + ); + }); + } // }}} + + function commandCompelter(context, args) { // {{{ + let len = 0; + + setTimelineCompleter(context); + let arg = args.literalArg.slice(0, context.caret); + let m; + if (m = arg.match(/(RT\s+)@.*$/)) { + (m.index === 0 ? Completers.name_id + : Completers.name_id_text)(m.index === 0 && rejectMine)(context, args); + } else if (m = tailMatch(/(^|\b|\s)@[^@]*/, arg)) { + (m.index === 0 ? Completers.name_id(rejectMine) : Completers.name(rejectMine))(context, args); } + if (m) + len = m.index + m[1].length; + context.title = ["Name#ID", "Entry"]; context.offset += len; // XXX 本文でも検索できるように、@ はなかったことにする @@ -2155,13 +2191,6 @@ let PLUGIN_INFO = context.incomplete = false; } // }}} - function subCommandCompleter(context, args) { // {{{ - if (!args.bang || args.literalArg.match(/^(\W|\S+\s)/)) - return; - context.title = ["Sub command", "Description"]; - context.completions = SubCommands.map(function({ command, description }) [command[0], description]); - } // }}} - commands.addUserCommand(["tw[ittperator]"], "Twittperator command", // {{{ function(args) { let bang = args.bang; @@ -2185,14 +2214,11 @@ let PLUGIN_INFO = literal: 0, hereDoc: true, completer: let (getting) function(context, args) { - if (args.bang) - context.fork("File", 0, context, function(context) subCommandCompleter(context, args)); - + let completer = args.bang ? subCommandCompleter : commandCompelter; let doGet = (expiredStatus || !(history && history.length)) && setting.autoStatusUpdate; + let matches = args.bang || args.literalArg.match(/(RT\s+|)@/); - let matches = args.bang ? args.literalArg.match(/^(\s*[-+?])/) - : args.literalArg.match(/(RT\s+|)@/); - if (!args.bang && !matches) + if (!matches) return; context.incomplete = doGet; @@ -2203,11 +2229,12 @@ let PLUGIN_INFO = getting = true; Twitter.getFollowersStatus(null, true, function() { getting = false; - context.fork("Twittperator", 0, context, function(context) commandCompelter(context, args)); + completer(context, args); + context.incomplete = false; }); } } else { - context.fork("Twittperator", 0, context, function(context) commandCompelter(context, args)); + completer(context, args); } } }, true); // }}} |