Skip to content

Instantly share code, notes, and snippets.

@wfarr
Created September 25, 2008 14:57
Show Gist options
  • Save wfarr/12833 to your computer and use it in GitHub Desktop.
Save wfarr/12833 to your computer and use it in GitHub Desktop.
;; Some work to make gist.el use some of the new api goodness
;; Non-working, atm
(defun gist-region (begin end)
"Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring."
(interactive "r")
(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"))
(output (generate-new-buffer " *gist*"))
(login (get-github-user-info)))
(shell-command-on-region
begin end
(format (concat "curl -sS "
"%s"
"-F 'file_ext[gistfile1]=.%s' "
"-F 'file_name[gistfile1]=%s' "
"-F 'file_contents[gistfile1]=<-' "
"http://gist.github.com/gists") login ext name)
output)
(with-current-buffer output
(re-search-backward "href=\"\\(.*\\)\"")
(message "Paste created: %s" (match-string 1))
(kill-new (match-string 1)))
(kill-buffer output)))
(defun get-github-user-info (&optional github-user github-key)
"Asks the user for their github username and api key. If they
don't have them, or wish to paste anonymously, they can do so.
Totally not required."
(interactive)
(cond ((and (not (string= github-username ""))
(not (string= github-api-key "")))
(format "-F 'login=%s' -F 'token=%s'" github-username github-api-key))
((and (> (length github-user) 1)
(> (length github-key) 1))
(format "-F 'login=%s' -F 'token=%s'" github-user github-key))
(t
(progn
(if (or (not github-user)
(not github-key))
(progn
(setq github-user (read-string "GitHub username?: "))
(setq github-key (read-string "GitHub API key?: "))))
(if (or (string= github-user "")
(string= github-key ""))
""
(format "-F 'login=%s' -F 'token=%s'" github-user github-key))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment