author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 26 Jan 2017 20:01:50 +0200 | |
changeset 1463 | 4c92e9fc2efd |
parent 1251 | a1f5b0d02e72 |
child 1516 | ad7b40d1f520 |
permissions | -rw-r--r-- |
1211
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
1 |
;;; pypi.el --- Handle work with Python pypi site. |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
3 |
;;; Commentary: |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
;; |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
5 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
(require 'url-handlers) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
(require 'thingatpt) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
|
1251
a1f5b0d02e72
Fix: Warning: reference to free variable `url-http-response-status'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1214
diff
changeset
|
9 |
(eval-when-compile |
a1f5b0d02e72
Fix: Warning: reference to free variable `url-http-response-status'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1214
diff
changeset
|
10 |
(defvar url-http-response-status)) |
a1f5b0d02e72
Fix: Warning: reference to free variable `url-http-response-status'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1214
diff
changeset
|
11 |
|
1211
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
;;; Code: |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
(defvar pypi.buffer-name "*Pip*") |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
(defvar pypi.pkg-history nil) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
(defvar pypi.url "https://pypi.python.org/pypi/%s/json") |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
(defun pypi.pkg-callback (status) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
21 |
(let ( (buffer (current-buffer)) content-type status ) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
(setq content-type (mail-fetch-field "Content-Type")) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
(setq status url-http-response-status) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
(switch-to-buffer pypi.buffer-name) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
25 |
(erase-buffer) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
26 |
(url-insert buffer) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
27 |
(fundamental-mode) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
28 |
(when (and (eq status 200) (string-match "application/json" content-type)) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
29 |
(js-mode)))) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
30 |
|
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
31 |
;;;###autoload |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
32 |
(defun pypi.pkg (pkg) |
1214
f9baff417868
If region active - use it content as default value.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1213
diff
changeset
|
33 |
(interactive (list |
f9baff417868
If region active - use it content as default value.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1213
diff
changeset
|
34 |
(read-string "Python package: " |
f9baff417868
If region active - use it content as default value.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1213
diff
changeset
|
35 |
(if (region-active-p) (buffer-substring (mark) (point)) (thing-at-point 'symbol)) |
f9baff417868
If region active - use it content as default value.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1213
diff
changeset
|
36 |
'pypi.pkg-history))) |
1211
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
37 |
(url-retrieve (format pypi.url pkg) #'pypi.pkg-callback)) |
c8cb83742738
Handle work with Python pypi site.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
38 |
|
1212
745c136f8398
Forget add provide.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1211
diff
changeset
|
39 |
(provide 'pypi) |
745c136f8398
Forget add provide.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1211
diff
changeset
|
40 |
|
745c136f8398
Forget add provide.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
1211
diff
changeset
|
41 |
;;; pypi.el ends here |