equal
deleted
inserted
replaced
|
1 ;;; pypi.el --- Handle work with Python pypi site. |
|
2 |
|
3 ;;; Commentary: |
|
4 ;; |
|
5 |
|
6 (require 'url-handlers) |
|
7 (require 'thingatpt) |
|
8 |
|
9 (eval-when-compile |
|
10 (defvar url-http-response-status)) |
|
11 |
|
12 ;;; Code: |
|
13 |
|
14 (defvar pypi/buffer-name "*Pip*") |
|
15 |
|
16 (defvar pypi/pkg-history nil) |
|
17 |
|
18 (defvar pypi/url "https://pypi.python.org/pypi/%s/json") |
|
19 |
|
20 (defun pypi/pkg-callback (status) |
|
21 (let ( (buffer (current-buffer)) content-type status ) |
|
22 (setq content-type (mail-fetch-field "Content-Type")) |
|
23 (setq status url-http-response-status) |
|
24 (switch-to-buffer pypi/buffer-name) |
|
25 (erase-buffer) |
|
26 (url-insert buffer) |
|
27 (fundamental-mode) |
|
28 (when (and (eq status 200) (string-match "application/json" content-type)) |
|
29 (js-mode)))) |
|
30 |
|
31 ;;;###autoload |
|
32 (defun pypi-pkg (pkg) |
|
33 (interactive (list |
|
34 (read-string "Python package: " |
|
35 (if (region-active-p) (buffer-substring (mark) (point)) (thing-at-point 'symbol)) |
|
36 'pypi/pkg-history))) |
|
37 (url-retrieve (format pypi/url pkg) #'pypi/pkg-callback)) |
|
38 |
|
39 (provide 'pypi) |
|
40 |
|
41 ;;; pypi.el ends here |