Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dleslie
Created March 1, 2010 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleslie/317988 to your computer and use it in GitHub Desktop.
Save dleslie/317988 to your computer and use it in GitHub Desktop.
(require 'gist)
(require 'tumblr)
(require 'http-post-simple)
(defun tumblr-gist-region (begin end &optional private)
"Post the current region as a new paste in a blog post"
(interactive "r\nP")
(gist-region begin end private 'tumblr-gist-callback))
(defun tumblr-gist-callback (status)
(let* ((url-max-redirections 5)
(url-request-method "GET")
(location (concat (cadr status) ".pibb"))
(gist-buffer (url-retrieve-synchronously location)))
(message "Fetched %s" location)
(with-current-buffer gist-buffer
(search-forward-regexp "\n\n")
(delete-region (point-min) (point))
(set-buffer-modified-p nil)
(let* ((content (buffer-substring (point-min) (point-max)))
(fixed-content (replace-regexp-in-string
"\\(<pre>\\|</pre>\\)" ""
content))
(title (read-string "Post title: "))
(tags (read-string "Post tags: ")))
(tumblr-gist-send-post title tags fixed-content)))))
(defun tumblr-gist-send-post (title tags body)
"Slightly more detailed variant on the 'tumblr send-post function"
(http-post-simple tumblr-post-url (list (cons 'email tumblr-email)
(cons 'password tumblr-password)
(cons 'type tumblr-default-type)
(cons 'title title)
(cons 'tags tags)
(cons 'slug title)
(cons 'private "0")
(cons 'body body))
'utf-8))
(provide 'tumblr-gist)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment