Created
November 20, 2012 00:01
-
-
Save davazp/4115013 to your computer and use it in GitHub Desktop.
Gists url handlers for GNU/Emacs
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
;;; URL handlers for Gists | |
(defvar gist-directory | |
"~/.gists/") | |
(defvar gist-url-regex | |
"^https://gist.github.com/\\(.*\\)$") | |
(defun gist-retrieve (id) | |
(unless (file-exists-p gist-directory) | |
(make-directory gist-directory)) | |
(let ((url (format "git@gist.github.com:%s.git" id)) | |
(output (concat gist-directory id))) | |
(unless (file-exists-p output) | |
(call-process-shell-command "git" nil nil nil "clone" url output)) | |
(let ((files (directory-files output t "^[^\\.]"))) | |
(if (= (length files) 1) | |
(find-file (first files)) | |
(find-file output))))) | |
(defun gist-browse-url (url &rest args) | |
(let ((case-fold-search t)) | |
(string-match gist-url-regex url) | |
(gist-retrieve (match-string 1 url)))) | |
(setq browse-url-browser-function | |
(list (cons gist-url-regex #'gist-browse-url) | |
(cons "." #'browse-url-default-browser))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment