pypi.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 19 Feb 2015 19:29:16 +0200
changeset 1212 745c136f8398
parent 1211 c8cb83742738
child 1213 e0de9be5c1ee
permissions -rw-r--r--
Forget add provide.

;;; 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))

(provide 'pypi)

;;; pypi.el ends here