0
|
1 |
;; ~/.emacs.d/hoersten-pastebin-region.el - Luke Hoersten - v0.6 |
|
2 |
|
|
3 |
;; custom keys |
|
4 |
(global-set-key (kbd "C-c w") 'pastebin-region) |
|
5 |
|
|
6 |
;; Based on http://www.emacswiki.org/cgi-bin/wiki/download/pastebin.el |
|
7 |
(defvar pastebin-type-assoc |
|
8 |
'((emacs-lisp-mode . "common-lisp") |
1
|
9 |
(c-mode . "c") |
|
10 |
(python-mode . "python") |
|
11 |
(nxml-mode . "xml") |
|
12 |
(c++-mode . "cpp"))) |
0
|
13 |
|
|
14 |
(defun pastebin-region (start end) |
|
15 |
"Send selected text to dpaste pastebin." |
|
16 |
(interactive "r") |
|
17 |
(let* ((pastebin-url "http://build-ch-03/paste/") |
1
|
18 |
(url-request-method "POST") |
|
19 |
(url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))) |
|
20 |
(url-request-data |
|
21 |
(format "title=%s&content=%s&lexer=%s&author=%s" |
|
22 |
(url-hexify-string (buffer-file-name)) ; title |
|
23 |
(url-hexify-string (buffer-substring-no-properties start end)) ; content |
|
24 |
(url-hexify-string (or (assoc-default major-mode pastebin-type-assoc) "text")) ; lexer |
|
25 |
(url-hexify-string (user-full-name))))) ; author |
|
26 |
(url-retrieve pastebin-url (lambda (arg) |
|
27 |
(cond |
|
28 |
((equal :error (car arg)) |
|
29 |
(signal (cdr arg))) |
|
30 |
((equal :redirect (car arg)) |
|
31 |
(let ((redirected (cadr arg))) |
|
32 |
(message redirected) |
|
33 |
(with-temp-buffer |
|
34 |
(insert redirected) |
|
35 |
(clipboard-kill-ring-save (point-min) (point-max)))))))))) |