Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge commit 'a1fa5f67c54dc94ff7aeb250f0958f8fa0b74d24' into maint

Conflicts:
	gist.el
  • Loading branch information...
commit ae0935707f096f7853c9803f777054607fe4a912 2 parents f0d2e11 + a1fa5f6
@sigma sigma authored
Showing with 44 additions and 7 deletions.
  1. +3 −0  README.md
  2. +41 −7 gist.el
View
3  README.md
@@ -15,6 +15,9 @@ In your emacs config:
(add-to-list 'load-path "~/.emacs.d/vendor/gist.el")
(require 'gist)
+ ;; to use curl
+ (setq gist-use-curl t)
+
Functions
=========
View
48 gist.el
@@ -29,6 +29,9 @@
;; MA 02111-1307, USA.
;;; Commentary:
+;; to function with https you may need to use curl
+;; by setting the option below
+;; (setq gist-use-curl t)
;; Uses your local GitHub config if it can find it.
;; See http://github.com/blog/180-local-github-config
@@ -49,6 +52,14 @@ git-config(1).")
"If non-nil, automatically use `browse-url' to view gists after they're
posted.")
+(defvar gist-use-curl nil
+ "Set gist.el to use curl by default.")
+
+(defvar gist-temp-bufname "*gist temp*")
+
+(defun gist-temp-buffer ()
+ (get-buffer-create gist-temp-bufname))
+
(defvar gist-supported-modes-alist '((action-script-mode . "as")
(c-mode . "c")
(c++-mode . "cpp")
@@ -102,7 +113,24 @@ accepts additional POST `params' as a list of (key . value) conses."
("token" . ,token) ,@params)))
(url-max-redirecton -1)
(url-request-method "POST"))
- (url-retrieve url callback))))
+ (if gist-use-curl
+ (gist-curl-retrieve url callback url-request-method url-request-data)
+ (url-retrieve url callback)))))
+
+(defun gist-curl-retrieve (url &optional callback url-request-method url-request-data)
+ (progn (call-process "curl"
+ nil
+ (gist-temp-buffer)
+ nil
+ url
+ "--silent"
+ (if (string= url-request-method "POST")
+ "--data"
+ "--header")
+ (if url-request-data url-request-data ""))
+ (set-buffer gist-temp-bufname)
+ (if callback
+ (funcall callback))))
;;;###autoload
(defun gist-region (begin end &optional private callback)
@@ -127,8 +155,10 @@ With a prefix argument, makes a private paste."
("file_name[gistfile1]" . ,name)
("file_contents[gistfile1]" . ,(buffer-substring begin end))))))
-(defun gist-created-callback (status)
- (let ((location (cadr status)))
+(defun gist-created-callback (&optional status)
+ (goto-char (point-min))
+ (re-search-forward"<a href=\"\\([^\"]*\\)\">redirected" nil t nil)
+ (let ((location (if status (cadr status) (match-string 1))))
(message "Paste created: %s" location)
(when gist-view-gist
(browse-url location))
@@ -241,7 +271,7 @@ Copies the URL into the kill ring."
(format "https://%s@gist.github.com/api/v1/xml/gists/%s" login login)
'gist-lists-retrieved-callback)))
-(defun gist-lists-retrieved-callback (status)
+(defun gist-lists-retrieved-callback (&optional status)
"Called when the list of gists has been retrieved. Parses the result
and displays the list."
(goto-char (point-min))
@@ -330,17 +360,21 @@ If the Gist already exists in a buffer, switches to it"
(interactive "nGist ID: ")
(let* ((gist-buffer-name (format "*gist %d*" id))
+ (gist-url (format gist-fetch-url id))
(gist-buffer (get-buffer gist-buffer-name)))
(if (bufferp gist-buffer)
(switch-to-buffer-other-window gist-buffer)
(progn
(message "Fetching Gist %d..." id)
- (setq gist-buffer
- (url-retrieve-synchronously (format gist-fetch-url id)))
+ (if gist-use-curl
+ (progn
+ (gist-curl-retrieve gist-url)
+ (setq gist-buffer (gist-temp-buffer)))
+ (setq gist-buffer (url-retrieve-synchronously gist-url)))
(with-current-buffer gist-buffer
(rename-buffer gist-buffer-name t)
(goto-char (point-min))
- (search-forward-regexp "\n\n")
+ (search-forward-regexp "\n\n" nil t)
(delete-region (point-min) (point))
(set-buffer-modified-p nil))
(switch-to-buffer-other-window gist-buffer)))))
Please sign in to comment.
Something went wrong with that request. Please try again.