src.nth.io/

summaryrefslogtreecommitdiff
path: root/pastebin-region.el
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2011-05-14 14:47:51 -0500
committerLuke Hoersten <[email protected]>2011-05-14 14:47:51 -0500
commitfe3a6566c715cb00cfa050f5313be2613186bd75 (patch)
treed8c65872208bfed264e59b449da91652a81c6094 /pastebin-region.el
parentb0435ed206a17ee89e3aeecaddbcb48c08d2769d (diff)
Moved 3rd party libs to separate dir and added optional scion haskell support.
--HG-- rename : hoersten-align-with-spaces.el => align-with-spaces.el rename : hoersten-pastebin-region.el => pastebin-region.el rename : color-theme-twilight.el => thirdparty/color-theme-twilight.el rename : pretty-mode.el => thirdparty/pretty-mode.el rename : vala-mode.el => thirdparty/vala-mode.el rename : zencoding-mode.el => thirdparty/zencoding-mode.el
Diffstat (limited to 'pastebin-region.el')
-rw-r--r--pastebin-region.el43
1 files changed, 43 insertions, 0 deletions
diff --git a/pastebin-region.el b/pastebin-region.el
new file mode 100644
index 0000000..fbae423
--- /dev/null
+++ b/pastebin-region.el
@@ -0,0 +1,43 @@
+;; ~/.emacs.d/hoersten-pastebin-region.el
+;; Luke Hoersten <[email protected]>
+
+;; custom keys
+(global-set-key (kbd "C-c w") 'pastebin-region)
+
+;; Based on http://www.emacswiki.org/cgi-bin/wiki/download/pastebin.el
+(defvar pastebin-type-assoc
+ '((emacs-lisp-mode . "common-lisp")
+ (c-mode . "c")
+ (python-mode . "python")
+ (nxml-mode . "xml")
+ (c++-mode . "cpp")))
+
+(defun pastebin-region (start end)
+ "Send selected text to dpaste pastebin."
+ (interactive "r")
+ (let*
+ ((pastebin-url "http://inf/paste/")
+ (url-request-method "POST")
+ (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded")))
+ (url-request-data
+ (format
+ "title=%s&content=%s&lexer=%s&author=%s"
+ (url-hexify-string (buffer-file-name)) ; title
+ (url-hexify-string (buffer-substring-no-properties start end)) ; content
+ (url-hexify-string (or (assoc-default major-mode pastebin-type-assoc) "text")) ; lexer
+ (url-hexify-string (user-full-name))))) ; author
+ (url-retrieve
+ pastebin-url
+ (lambda (arg)
+ (cond
+ ((equal :error (car arg))
+ (signal (cdr arg)))
+ ((equal :redirect (car arg))
+ (let ((redirected (cadr arg)))
+ (message redirected)
+ (with-temp-buffer
+ (insert redirected)
+ (clipboard-kill-ring-save (point-min) (point-max))))))))))
+
+(message "Loading pastebin-region...done")
+(provide 'pastebin-region)