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