13 (c++-mode . "cpp"))) |
13 (c++-mode . "cpp"))) |
14 |
14 |
15 (defun pastebin-region (start end) |
15 (defun pastebin-region (start end) |
16 "Send selected text to dpaste pastebin." |
16 "Send selected text to dpaste pastebin." |
17 (interactive "r") |
17 (interactive "r") |
18 (let* ((pastebin-url "http://inf/paste/") |
18 (let* |
19 (url-request-method "POST") |
19 ((pastebin-url "http://inf/paste/") |
20 (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))) |
20 (url-request-method "POST") |
21 (url-request-data |
21 (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))) |
22 (format "title=%s&content=%s&lexer=%s&author=%s" |
22 (url-request-data |
23 (url-hexify-string (buffer-file-name)) ; title |
23 (format |
24 (url-hexify-string (buffer-substring-no-properties start end)) ; content |
24 "title=%s&content=%s&lexer=%s&author=%s" |
25 (url-hexify-string (or (assoc-default major-mode pastebin-type-assoc) "text")) ; lexer |
25 (url-hexify-string (buffer-file-name)) ; title |
26 (url-hexify-string (user-full-name))))) ; author |
26 (url-hexify-string (buffer-substring-no-properties start end)) ; content |
27 (url-retrieve pastebin-url (lambda (arg) |
27 (url-hexify-string (or (assoc-default major-mode pastebin-type-assoc) "text")) ; lexer |
28 (cond |
28 (url-hexify-string (user-full-name))))) ; author |
29 ((equal :error (car arg)) |
29 (url-retrieve |
30 (signal (cdr arg))) |
30 pastebin-url |
31 ((equal :redirect (car arg)) |
31 (lambda (arg) |
32 (let ((redirected (cadr arg))) |
32 (cond |
33 (message redirected) |
33 ((equal :error (car arg)) |
34 (with-temp-buffer |
34 (signal (cdr arg))) |
35 (insert redirected) |
35 ((equal :redirect (car arg)) |
36 (clipboard-kill-ring-save (point-min) (point-max)))))))))) |
36 (let ((redirected (cadr arg))) |
|
37 (message redirected) |
|
38 (with-temp-buffer |
|
39 (insert redirected) |
|
40 (clipboard-kill-ring-save (point-min) (point-max)))))))))) |
37 |
41 |
38 (provide 'hoersten-pastebin-region) |
42 (provide 'hoersten-pastebin-region) |