Skip to content

Commit

Permalink
whitespace, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Mar 4, 2010
1 parent 603282c commit 58a7ce1
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions gist.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
;; Will Farrington <wcfarrington@gmail.com> ;; Will Farrington <wcfarrington@gmail.com>
;; Michael Ivey ;; Michael Ivey
;; Phil Hagelberg ;; Phil Hagelberg
;; Version: 0.3 ;; Dan McKinley
;; Version: 0.4
;; Created: 21 Jul 2008 ;; Created: 21 Jul 2008
;; Keywords: gist git github paste pastie pastebin ;; Keywords: gist git github paste pastie pastebin


Expand Down Expand Up @@ -84,11 +85,11 @@ posted.")




(defun* gist-request (url callback &optional params) (defun* gist-request (url callback &optional params)
"Makes a request to `url' asynchronously, notifying `callback' when "Makes a request to `url' asynchronously, notifying `callback' when
complete. The github parameters are included in the request. Optionally complete. The github parameters are included in the request. Optionally
accepts additional POST `params' as a list of (key . value) conses." accepts additional POST `params' as a list of (key . value) conses."
(github-with-auth-info login token (github-with-auth-info login token
(let ((url-request-data (gist-make-query-string (let ((url-request-data (gist-make-query-string
`(("login" . ,login) `(("login" . ,login)
("token" . ,token) ,@params))) ("token" . ,token) ,@params)))
(url-max-redirecton 5) (url-max-redirecton 5)
Expand All @@ -107,7 +108,7 @@ With a prefix argument, makes a private paste."
(ext (or (cdr (assoc major-mode gist-supported-modes-alist)) (ext (or (cdr (assoc major-mode gist-supported-modes-alist))
(file-name-extension file) (file-name-extension file)
"txt"))) "txt")))
(gist-request (gist-request
"http://gist.github.com/gists" "http://gist.github.com/gists"
(or callback 'gist-created-callback) (or callback 'gist-created-callback)
`(,@(if private '(("action_button" . "private"))) `(,@(if private '(("action_button" . "private")))
Expand Down Expand Up @@ -152,7 +153,7 @@ Copies the URL into the kill ring."
(defun github-set-config (key value) (defun github-set-config (key value)
"Sets a GitHub specific value to the global Git config." "Sets a GitHub specific value to the global Git config."
(let ((git (executable-find "git"))) (let ((git (executable-find "git")))
(shell-command-to-string (shell-command-to-string
(format git " config --global github.%s %s" key value)))) (format git " config --global github.%s %s" key value))))


(defun github-auth-info () (defun github-auth-info ()
Expand All @@ -163,13 +164,13 @@ for the info then sets it to the git config."
(interactive) (interactive)


;; If we've been called within a scope that already has this ;; If we've been called within a scope that already has this
;; defined, don't take the time to get it again. ;; defined, don't take the time to get it again.
(if (boundp '*github-auth-info*) (if (boundp '*github-auth-info*)
*github-auth-info* *github-auth-info*


(let* ((user (or github-user (github-config "user"))) (let* ((user (or github-user (github-config "user")))
(token (or github-token (github-config "token")))) (token (or github-token (github-config "token"))))

(when (not user) (when (not user)
(setq user (read-string "GitHub username: ")) (setq user (read-string "GitHub username: "))
(github-set-config "user" user)) (github-set-config "user" user))
Expand All @@ -181,7 +182,7 @@ for the info then sets it to the git config."
(cons user token)))) (cons user token))))


(defmacro github-with-auth-info (login token &rest body) (defmacro github-with-auth-info (login token &rest body)
"Binds the github authentication credentials to `login' and `token'. "Binds the github authentication credentials to `login' and `token'.
The credentials are retrieved at most once within the body of this macro." The credentials are retrieved at most once within the body of this macro."
(declare (indent 2)) (declare (indent 2))
`(let ((*github-auth-info* (github-auth-info))) `(let ((*github-auth-info* (github-auth-info)))
Expand Down Expand Up @@ -232,11 +233,11 @@ Copies the URL into the kill ring."
"Displays a list of all of the current user's gists in a new buffer." "Displays a list of all of the current user's gists in a new buffer."
(interactive) (interactive)
(message "Retrieving list of your gists...") (message "Retrieving list of your gists...")
(github-with-auth-info login token (github-with-auth-info login token
(gist-request (gist-request
(format "http://gist.github.com/api/v1/xml/gists/%s" login) (format "http://gist.github.com/api/v1/xml/gists/%s" login)
'gist-lists-retrieved-callback))) 'gist-lists-retrieved-callback)))

(defun gist-lists-retrieved-callback (status) (defun gist-lists-retrieved-callback (status)
"Called when the list of gists has been retrieved. Parses the result "Called when the list of gists has been retrieved. Parses the result
and displays the list." and displays the list."
Expand All @@ -251,7 +252,7 @@ and displays the list."
(kill-region (point-min) (point-max)) (kill-region (point-min) (point-max))
(gist-insert-list-header) (gist-insert-list-header)
(mapc 'gist-insert-gist-link (xml-node-children (car gists))) (mapc 'gist-insert-gist-link (xml-node-children (car gists)))

;; remove the extra newline at the end ;; remove the extra newline at the end
(delete-backward-char 1)) (delete-backward-char 1))


Expand All @@ -268,14 +269,14 @@ and displays the list."
(let ((ov (make-overlay (line-beginning-position) (line-end-position)))) (let ((ov (make-overlay (line-beginning-position) (line-end-position))))
(overlay-put ov 'face 'header-line)) (overlay-put ov 'face 'header-line))
(forward-line)) (forward-line))

(defun gist-insert-gist-link (gist) (defun gist-insert-gist-link (gist)
"Inserts a button that will open the given gist when pressed." "Inserts a button that will open the given gist when pressed."
(let* ((data (gist-parse-gist gist)) (let* ((data (gist-parse-gist gist))
(repo (string-to-number (car data)))) (repo (string-to-number (car data))))
(mapc '(lambda (x) (insert (format " %s " x))) data) (mapc '(lambda (x) (insert (format " %s " x))) data)
(make-text-button (line-beginning-position) (line-end-position) (make-text-button (line-beginning-position) (line-end-position)
'repo repo 'repo repo
'action 'gist-fetch-button 'action 'gist-fetch-button
'face 'default)) 'face 'default))
(insert "\n")) (insert "\n"))
Expand All @@ -285,7 +286,7 @@ and displays the list."
(gist-fetch (button-get button 'repo))) (gist-fetch (button-get button 'repo)))


(defun gist-parse-gist (gist) (defun gist-parse-gist (gist)
"Returns a list of the gist's attributes for display, given the xml list "Returns a list of the gist's attributes for display, given the xml list
for the gist." for the gist."
(let ((repo (gist-child-text 'repo gist)) (let ((repo (gist-child-text 'repo gist))
(created-at (gist-child-text 'created-at gist)) (created-at (gist-child-text 'created-at gist))
Expand Down

0 comments on commit 58a7ce1

Please sign in to comment.