1 ;;; pastebin.el --- A simple interface to the www.pastebin.com webservice
3 ;;; Copyright (C) 2008 by Tapsell-Ferrier Limited
5 ;;; This program is free software; you can redistribute it and/or modify
6 ;;; it under the terms of the GNU General Public License as published by
7 ;;; the Free Software Foundation; either version 2, or (at your option)
10 ;;; This program is distributed in the hope that it will be useful,
11 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;; GNU General Public License for more details.
15 ;;; You should have received a copy of the GNU General Public License
16 ;;; along with this program; see the file COPYING. If not, write to the
17 ;;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;; Boston, MA 02110-1301 USA
22 ;;; Load this file and run:
24 ;;; M-x pastebin-buffer
26 ;;; to send the whole buffer or select a region and run
30 ;;; to send just the region.
32 ;;; In either case the url that pastebin generates is left on the kill
33 ;;; ring and the paste buffer.
38 (defvar dpastebin-type-assoc
39 '((emacs-lisp-mode . "887")
44 (defvar dpastebin-retrieved nil)
46 (defvar dpastebin-expire-history '())
48 (defun dpastebin-buffer (&optional expire)
49 "Send the whole buffer to paste.q0a.de."
50 (interactive (if current-prefix-arg
51 (list (read-string "pastebin expire:" nil 'dpastebin-expire-history))))
52 (dpastebin (point-min) (point-max) expire))
54 (defun dpastebin (start end &optional expire)
55 "An interface to the pastebin code snippet www service.
57 See pastebin.com for more information about pastebin.
59 Called interactively pastebin uses the current region for
60 preference for sending... if the mark is NOT set then the entire
63 Argument START is the start of region.
64 Argument END is the end of region.
66 If PREFIX is used pastebin prompts for a prefix to be used as the
67 virtual host to use. For example use 'emacs' for 'emacs.pastebin.com'."
69 (let ((pastebin-expire
70 (if current-prefix-arg
71 (read-string "pastebin expire:" nil 'dpastebin-expire-history))))
73 (list (region-beginning) (region-end) pastebin-expire)
74 (list (point-min) (point-max) pastebin-expire))))
76 (let* ((data (buffer-substring-no-properties start end))
77 (pastebin-url (format "http://paste.debian.net"))
78 (url-request-method "POST")
79 (url-request-extra-headers
80 '(("Content-Type" . "multipart/form-data")))
82 (concat (format "paste=Send&lang=%s&expiry=%s&poster=%s&code=%s"
83 (assoc-default major-mode dpastebin-type-assoc nil "878")
86 (url-hexify-string data))))
87 (content-buf (url-retrieve pastebin-url
90 ((equal :error (car arg))
92 ((equal :redirect (car arg))
93 (setq pastebin-retrieved (cadr arg))
95 (insert pastebin-retrieved)
96 (clipboard-kill-ring-save (point-min) (point-max)))))))))
99 (provide 'debian-pastebin)
100 ;;; pastebin.el ends here