# HG changeset patch # User Oleksandr Gavenko # Date 1424366767 -7200 # Node ID c8cb83742738a369faa8504d3e07e8b67c6d0c69 # Parent b149f50121ac4f88462b69375769ed5ccbee16a8 Handle work with Python pypi site. diff -r b149f50121ac -r c8cb83742738 pypi.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pypi.el Thu Feb 19 19:26:07 2015 +0200 @@ -0,0 +1,32 @@ +;;; pypi.el --- Handle work with Python pypi site. + +;;; Commentary: +;; + +(require 'url-handlers) +(require 'thingatpt) + +;;; Code: + +(defvar pypi.buffer-name "*Pip*") + +(defvar pypi.pkg-history nil) + +(defvar pypi.url "https://pypi.python.org/pypi/%s/json") + +(defun pypi.pkg-callback (status) + (let ( (buffer (current-buffer)) content-type status ) + (setq content-type (mail-fetch-field "Content-Type")) + (setq status url-http-response-status) + (switch-to-buffer pypi.buffer-name) + (erase-buffer) + (url-insert buffer) + (fundamental-mode) + (when (and (eq status 200) (string-match "application/json" content-type)) + (js-mode)))) + +;;;###autoload +(defun pypi.pkg (pkg) + (interactive (list (read-string "Python package: " "" 'pypi.pkg-history (thing-at-point symbol)))) + (url-retrieve (format pypi.url pkg) #'pypi.pkg-callback)) +