Skip to content

Commit

Permalink
make el-get an optional dependency. fix #53
Browse files Browse the repository at this point in the history
  • Loading branch information
edvorg committed May 7, 2018
1 parent 958bed5 commit f97d753
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cask
Expand Up @@ -8,7 +8,6 @@
(depends-on "ht")
(depends-on "use-package")
(depends-on "dash")
(depends-on "el-get")

(development
(depends-on "undercover")
Expand Down
45 changes: 22 additions & 23 deletions req-package.el
Expand Up @@ -5,7 +5,7 @@
;; Author: Edward Knyshov <edvorg@gmail.com>
;; Created: 25 Dec 2013
;; Version: 1.2
;; Package-Requires: ((use-package "1.0") (dash "2.7.0") (log4e "0.2.0") (ht "0") (el-get "5.1"))
;; Package-Requires: ((use-package "1.0") (dash "2.7.0") (log4e "0.2.0") (ht "0"))
;; Keywords: dotemacs startup speed config package
;; X-URL: https://github.com/edvorg/req-package

Expand Down Expand Up @@ -302,13 +302,11 @@
(package-install package))))))

(req-package-bootstrap 'use-package)
(req-package-bootstrap 'el-get)
(req-package-bootstrap 'dash)
(req-package-bootstrap 'log4e)
(req-package-bootstrap 'ht)

(require 'use-package)
(require 'el-get)
(require 'dash)
(require 'log4e)
(require 'ht)
Expand Down Expand Up @@ -336,26 +334,27 @@

(defvar req-package-branches (make-hash-table :size 200 :test 'equal))

(add-to-list 'use-package-keywords :el-get)

(defun use-package-normalize/:el-get (name-symbol keyword args)
(use-package-only-one (symbol-name keyword) args
(lambda (label arg)
(cond
((booleanp arg) name-symbol)
((symbolp arg) arg)
(t
(use-package-error
":el-get wants an package name or boolean value"))))))

(defun use-package-handler/:el-get (name-symbol keyword archive-name rest state)
(let ((body (use-package-process-keywords name-symbol rest state)))
;; This happens at macro expansion time, not when the expanded code is
;; compiled or evaluated.
(if (null archive-name)
body
(el-get-install archive-name)
body)))
(when (require 'el-get nil t)
(add-to-list 'use-package-keywords :el-get)

(defun use-package-normalize/:el-get (name-symbol keyword args)
(use-package-only-one (symbol-name keyword) args
(lambda (label arg)
(cond
((booleanp arg) name-symbol)
((symbolp arg) arg)
(t
(use-package-error
":el-get wants an package name or boolean value"))))))

(defun use-package-handler/:el-get (name-symbol keyword archive-name rest state)
(let ((body (use-package-process-keywords name-symbol rest state)))
;; This happens at macro expansion time, not when the expanded code is
;; compiled or evaluated.
(if (null archive-name)
body
(el-get-install archive-name)
body))))

(defun req-package-patch-config (pkg form)
"Wrap package PKG :config FORM into progn with callbacks."
Expand Down

2 comments on commit f97d753

@DarwinAwardWinner
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is optimal. If req-package and el-get are both installed, but req-package happens to be loaded before el-get is added to the load-path, the :el-get keyword will not be defined. I think it's better to call (require 'el-get t) within each function and throw an error at runtime if it fails, rather than do a single check at load time. That way, as long as el-get has been loaded by the time you call req-pacakge-finish, everything should be ok.

I can code up this proposal myself if you want. Just let me know.

@DarwinAwardWinner
Copy link

@DarwinAwardWinner DarwinAwardWinner commented on f97d753 May 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, or you could just use eval-after-load, I suppose. Edit: Although going with my idea above would give better error messages. Using eval-after-load will cause an error about :el-get being an unknown keyword (if el-get isn't loaded), while using the above idea would allow you to control the error message.

Please sign in to comment.