Created
October 27, 2008 08:15
-
-
Save nex3/20047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;###autoload | |
(defun gist-region (begin end &optional private) | |
"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")) | |
(login (github-auth-string)) | |
(do-private (if private "-F private=1" "")) | |
(url-request-method "POST") | |
(url-request-data | |
(gist-make-query-string | |
`(("file_ext[gistfile1]" . ,(concat "." ext)) | |
("file_name[gistfile1]" . ,name) | |
("file_contents[gistfile1]" . ,(buffer-substring begin end))))) | |
(output (url-retrieve-synchronously "http://gist.github.com/gists"))) | |
(with-current-buffer output | |
(re-search-forward "^Location: \(.*\)$") | |
(message "Paste created: %s" (match-string 1)) | |
(if gist-view-gist (browse-url (match-string 1))) | |
(kill-new (match-string 1))) | |
(kill-buffer output))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment