var PLUGIN_INFO = {NAME} CPAN search CPAN モジュールを検索し、補完します。 2.0pre 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 ); })();