Created
September 24, 2010 07:20
-
-
Save taichi/594981 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
API | |
http://develop.github.com/p/gist.html | |
emacs向け | |
http://github.com/defunkt/gist.el/blob/master/gist.el | |
リクエスト処理 | |
(defun* gist-request (url callback &optional params) | |
"Makes a request to `url' asynchronously, notifying `callback' when | |
complete. The github parameters are included in the request. Optionally | |
accepts additional POST `params' as a list of (key . value) conses." | |
(github-with-auth-info login token | |
(let ((url-request-data (gist-make-query-string | |
`(("login" . ,login) | |
("token" . ,token) ,@params))) | |
(url-max-redirecton -1) | |
(url-request-method "POST")) | |
(url-retrieve url callback)))) | |
バッファをブン投げる処理 | |
(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 | |
"http://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