From f6152ce9d044ac295c179f310ec2fc64642a54b3 Mon Sep 17 00:00:00 2001 From: secondlife Date: Sat, 7 Feb 2009 03:33:04 +0000 Subject: クパン検索 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@29669 d0d07461-0603-4401-acd4-de1884942a52 --- cpan-search.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 cpan-search.js (limited to 'cpan-search.js') 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 = + +{NAME} +CPAN search +CPAN モジュールを検索し、補完します。 +2.0 +2.0pre +http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/cpan-search.js +Yuichi Tateno +MPL 1.1/GPL 2.0/LGPL 2.1 +0.1 + +; + +(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 +); + +})(); + -- cgit v1.2.3