aboutsummaryrefslogtreecommitdiffstats
path: root/pypi.js
diff options
context:
space:
mode:
authorGael Pasgrimaud2011-05-23 22:25:54 +0200
committerGael Pasgrimaud2011-05-23 22:25:54 +0200
commit8730c03848616652664f9aa88b95309632004e45 (patch)
treed76697cd0a63032085a6d733b3599c949e2f251d /pypi.js
parent444182183de203f9f28c8e520ba1c1269db6fd71 (diff)
downloadvimperator-plugins-8730c03848616652664f9aa88b95309632004e45.tar.bz2
add a pypi command with autocompletion
Diffstat (limited to 'pypi.js')
-rw-r--r--pypi.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/pypi.js b/pypi.js
new file mode 100644
index 0000000..ff19eb8
--- /dev/null
+++ b/pypi.js
@@ -0,0 +1,80 @@
+var PLUGIN_INFO =
+<VimperatorPlugin>
+<name>pypi</name>
+<description>Add a pypi command</description>
+<author mail="gael@gawel.org" homepage="http://www.gawel.org">gawel</author>
+<version>1.1</version>
+<license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
+<minVersion>2.0pre</minVersion>
+<maxVersion>2.0</maxVersion>
+<updateURL>https://github.com/gawel/vimperator-plugins/raw/master/pypi.js</updateURL>
+<detail lang="en"><![CDATA[
+
+== Command ==
+
+:pypi {package or term}
+
+]]></detail>
+</VimperatorPlugin>;
+
+liberator.plugins.pypi = (function(){
+
+var Pypi = {
+ packages: [],
+ init_packages: function() {
+ var req = new XMLHttpRequest();
+ req.onreadystatechange = function() {
+ if (req.readyState == 4) {
+ var lines = req.responseText.split('\n');
+ for (var i=0; i<lines.length; i++) {
+ var line = lines[i];
+ if (/^<a/.exec(line))
+ Pypi.packages.push(line.split('>')[1].split('<')[0]);
+ }
+ liberator.echo('Pypi packages list is up to date');
+ }
+ }
+ req.open("GET", "http://pypi.python.org/simple/", false);
+ req.send(null);
+ setTimeout(Pypi.init_packages, 600000);
+ }
+}
+
+setTimeout(Pypi.init_packages, 1000);
+
+commands.addUserCommand(["pypi"], "pypi search",
+ function(args){
+ var doc = window.content.document;
+ if (!args.length) {
+ doc.location.href = 'http://pypi.python.org/pypi';
+ }
+ var filter = args[0];
+ var packages = plugins.pypi.packages;
+ for (var i=0; i<packages.length; i++) {
+ if (filter.toLowerCase() == packages[i].toLowerCase()) {
+ doc.location.href = 'http://pypi.python.org/pypi/'+packages[i];
+ return;
+ }
+ }
+ doc.location.href = 'http://pypi.python.org/pypi?%3Aaction=search&submit=search&term='+filter;
+ }, {
+ completer: function(context, args){
+ if (context.filter.length < 1) return;
+ if (!plugins.pypi.packages.length) {
+ plugins.pypi.init_packages();
+ }
+ var packages = plugins.pypi.packages;
+ var results = [];
+ for (var i=0; i<packages.length; i++) {
+ if (new RegExp('^'+context.filter.replace('.', '\\.').toLowerCase()).exec(packages[i].toLowerCase())) {
+ results.push([packages[i], '']);
+ }
+ }
+ return {items:results, start:0};
+ }
+ }, true);
+
+return Pypi;
+})();
+
+// vim: sw=4 ts=4 et fdm=marker: