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