diff options
author | secondlife | 2009-02-07 03:33:04 +0000 |
---|---|---|
committer | secondlife | 2009-02-07 03:33:04 +0000 |
commit | f6152ce9d044ac295c179f310ec2fc64642a54b3 (patch) | |
tree | 268c4b7d69d7fa6d5351cebaa726702f3428b6e7 /cpan-search.js | |
parent | 28d5572adfe5e75c7d42a457f4fd6cd48a77607c (diff) | |
download | vimperator-plugins-f6152ce9d044ac295c179f310ec2fc64642a54b3.tar.bz2 |
クパン検索
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@29669 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'cpan-search.js')
-rw-r--r-- | cpan-search.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/cpan-search.js b/cpan-search.js new file mode 100644 index 0000000..49c1238 --- /dev/null +++ b/cpan-search.js @@ -0,0 +1,74 @@ +var PLUGIN_INFO = +<VimperatorPlugin> +<name>{NAME}</name> +<description>CPAN search</description> +<description lang="ja">CPAN モジュールを検索し、補完します。</description> +<minVersion>2.0</minVersion> +<maxVersion>2.0pre</maxVersion> +<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/cpan-search.js</updateURL> +<author mail="hotchpotch@gmail.com" homepage="http://tako3.net/http://d.hatena.ne.jp/secondlife/">Yuichi Tateno</author> +<license>MPL 1.1/GPL 2.0/LGPL 2.1</license> +<version>0.1</version> +<detail><![CDATA[ +:cpan[!] Moo::Me[tab] + +CPAN モジュールリストは http://cpan.ma.la/list から vimp 起動時に初回ロードされます。(thx: mala!) +検索は1単語なら indexOf 探索ですが、: を含む言葉(Foo::Bar など)なら RegExp 検索になるので、重いかもしれません。 +WebService::Hatena をマッチさせたいなら Web::Ha[tab] などで補完できると思います。 +:cpan! で bang をつけると別のタブで開きます。 +]]></detail> +</VimperatorPlugin>; + +(function() { +var p = function(arg) { + Application.console.log(arg); + // liberator.log(arg); +} + +// preload cpan list +var cpanListURL = liberator.globalVariables.cpanSearchListURL || 'http://cpan.ma.la/list'; +if (!liberator.globalVariables.cpanListCache) { + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + liberator.globalVariables.cpanListCache = + xhr.responseText.split(/\r?\n/).map(function(i) [i, '', i.toUpperCase()]); + } else { + liberator.echoerr('CPAN Search: XHR Error: ' + xhr.statusText); + // throw new Error(xhr.statusText); + } + } + } + xhr.open('GET', cpanListURL, true); + xhr.send(null); +} + +commands.addUserCommand( + ['cpan'], + 'CPAN Search', + function(args) { + var name = (args.string || '').replace(/\s/g, '').replace(/^\^/,''); + var url = 'http://search.cpan.org/perldoc?' + name; + liberator.open(url, args.bang ? liberator.NEW_TAB : null); + }, { + completer: function(context) { + context.title = ['MODULE NAME', '']; + var word = context.filter.toUpperCase(); + if (word.indexOf(':') >= 0) { + var regex = word.split(/:+/).map(function(i) i + '[^:]*').join('::'); + regex = new RegExp('^' + regex.replace(/\[\^:\]\*$/, '')); + context.filters = [function (item) regex.test(item.item[2])]; + } else { + context.filters = [function (item) item.item[2].indexOf(word) != -1]; + } + context.completions = liberator.globalVariables.cpanListCache || []; + }, + argCount: '1', + bang: true, + }, + true +); + +})(); + |