Skip to content

Instantly share code, notes, and snippets.

@pjstadig
Created November 5, 2010 12:57
Show Gist options
  • Save pjstadig/664097 to your computer and use it in GitHub Desktop.
Save pjstadig/664097 to your computer and use it in GitHub Desktop.
(defun gist-region (begin end &optional private &optional callback)
"Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring.
With a prefix argument, makes a private paste."
(interactive "r\nP")
(let* ((file (or (buffer-file-name) (buffer-name)))
(name (file-name-nondirectory file))
(ext (or (cdr (assoc major-mode gist-supported-modes-alist))
(file-name-extension file)
"txt")))
(gist-request
"https://gist.github.com/gists"
(or callback 'gist-created-callback)
`(,@(if private '(("action_button" . "private")))
("file_ext[gistfile1]" . ,(concat "." ext))
("file_name[gistfile1]" . ,name)
("file_contents[gistfile1]" . ,(buffer-substring begin end))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment