hoersten-pastebin-region.el
author Luke Hoersten <Luke@Hoersten.org>
Sat, 04 Dec 2010 13:21:20 -0600
changeset 30 5aa1ceff049d
parent 29 b52bb6669eed
permissions -rw-r--r--
Started using eshell with TERM=emacs for bash colors.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
0fda818a8b6a Added doxymacs and provides for requires.
Luke Hoersten <Luke@Hoersten.org>
parents: 1
diff changeset
     1
;; ~/.emacs.d/hoersten-pastebin-region.el
0fda818a8b6a Added doxymacs and provides for requires.
Luke Hoersten <Luke@Hoersten.org>
parents: 1
diff changeset
     2
;; Luke Hoersten <[email protected]>
0
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     3
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     4
;; custom keys
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     5
(global-set-key (kbd "C-c w") 'pastebin-region)
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     6
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     7
;; Based on http://www.emacswiki.org/cgi-bin/wiki/download/pastebin.el
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     8
(defvar pastebin-type-assoc
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
     9
  '((emacs-lisp-mode . "common-lisp")
1
ede059431d20 Minor updates.
Luke Hoersten <Luke@Hoersten.org>
parents: 0
diff changeset
    10
    (c-mode          . "c")
ede059431d20 Minor updates.
Luke Hoersten <Luke@Hoersten.org>
parents: 0
diff changeset
    11
    (python-mode     . "python")
ede059431d20 Minor updates.
Luke Hoersten <Luke@Hoersten.org>
parents: 0
diff changeset
    12
    (nxml-mode       . "xml")
ede059431d20 Minor updates.
Luke Hoersten <Luke@Hoersten.org>
parents: 0
diff changeset
    13
    (c++-mode        . "cpp")))
0
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
    14
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
    15
(defun pastebin-region (start end)
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
    16
  "Send selected text to dpaste pastebin."
c25fee3c92e9 Initial commit.
Luke Hoersten <Luke@Hoersten.org>
parents:
diff changeset
    17
  (interactive "r")
17
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    18
  (let*
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    19
      ((pastebin-url "http://inf/paste/")
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    20
       (url-request-method "POST")
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    21
       (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded")))
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    22
       (url-request-data
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    23
        (format
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    24
         "title=%s&content=%s&lexer=%s&author=%s"
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    25
         (url-hexify-string (buffer-file-name))                                         ; title
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    26
         (url-hexify-string (buffer-substring-no-properties start end))                 ; content
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    27
         (url-hexify-string (or (assoc-default major-mode pastebin-type-assoc) "text")) ; lexer
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    28
         (url-hexify-string (user-full-name)))))                                        ; author
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    29
    (url-retrieve
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    30
     pastebin-url
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    31
     (lambda (arg)
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    32
       (cond
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    33
        ((equal :error (car arg))
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    34
         (signal (cdr arg)))
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    35
        ((equal :redirect (car arg))
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    36
         (let ((redirected (cadr arg)))
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    37
           (message redirected)
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    38
           (with-temp-buffer
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    39
             (insert redirected)
2067d6164e07 Updated nav and yasnipped modes as well as cleaned up the pastebin script.
Luke Hoersten <Luke@Hoersten.org>
parents: 8
diff changeset
    40
             (clipboard-kill-ring-save (point-min) (point-max))))))))))
4
0fda818a8b6a Added doxymacs and provides for requires.
Luke Hoersten <Luke@Hoersten.org>
parents: 1
diff changeset
    41
29
b52bb6669eed Added align-with-spaces require.
Luke Hoersten <Luke@Hoersten.org>
parents: 17
diff changeset
    42
(message "Loaded Hoersten pastebin")
4
0fda818a8b6a Added doxymacs and provides for requires.
Luke Hoersten <Luke@Hoersten.org>
parents: 1
diff changeset
    43
(provide 'hoersten-pastebin-region)