Skip to content

Commit

Permalink
Tidy up fns for downloading libs
Browse files Browse the repository at this point in the history
  • Loading branch information
purcell committed Jun 7, 2011
1 parent ab53e66 commit 4a7dd49
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions init-site-lisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,33 @@
;;----------------------------------------------------------------------------
;; Utilities for grabbing upstream libs
;;----------------------------------------------------------------------------
(defun site-lisp-dir-for (name)
(expand-file-name (format "~/.emacs.d/site-lisp/%s" name)))

(defun grab-site-lisp-module (name url)
(let ((dir (expand-file-name (format "~/.emacs.d/site-lisp/%s" name))))
(defun site-lisp-library-el-path (name)
(expand-file-name (format "%s.el" name) (site-lisp-dir-for name)))

(defun download-site-lisp-module (name url)
(let ((dir (site-lisp-dir-for name)))
(message "Downloading %s from %s" name url)
(unless (file-directory-p dir)
(make-directory dir)
(add-to-list 'load-path dir))
(url-copy-file url (expand-file-name (format "%s.el" name) dir) t nil)))
(url-copy-file url (site-lisp-library-el-path name) t nil)))

(defun ensure-lib-from-url (name url)
(unless (require name nil t)
(grab-site-lisp-module name url)))

(defun ensure-lib-from-svn (name url &optional check-file)
(let ((dir (expand-file-name (format "~/.emacs.d/site-lisp/%s" name))))
(unless (if check-file
(file-exists-p (expand-file-name (format "%s.el" name) dir))
(require name nil t))
(unless (site-lisp-library-loadable-p name)
(download-site-lisp-module name url)))

(defun site-lisp-library-loadable-p (name)
"Return whether or not the library `name' can be loaded from a
source file under ~/.emacs.d/site-lisp/name/"
(let ((f (locate-library (symbol-name name))))
(and f (string-prefix-p (file-name-as-directory (site-lisp-dir-for name)) f))))

(defun ensure-lib-from-svn (name url)
(let ((dir (site-lisp-dir-for name)))
(unless (site-lisp-library-loadable-p name)
(message "Checking out %s from svn" name)
(shell-command (format "svn co %s %s" url dir))
(add-to-list 'load-path dir))))
Expand Down Expand Up @@ -67,6 +76,6 @@
(ensure-lib-from-url 'vc-darcs "http://www.pps.jussieu.fr/~jch/software/repos/vc-darcs/vc-darcs.el")

(ensure-lib-from-svn 'rdebug "http://ruby-debug.rubyforge.org/svn/trunk/emacs/")
(ensure-lib-from-svn 'ruby-mode "http://svn.ruby-lang.org/repos/ruby/trunk/misc/" t)
(ensure-lib-from-svn 'ruby-mode "http://svn.ruby-lang.org/repos/ruby/trunk/misc/")

(provide 'init-site-lisp)

0 comments on commit 4a7dd49

Please sign in to comment.