Refactor package! macro

And have :ignore and :freeze be evaluated during package management,
rather than during macro expansion/compile time.

Also gives doom-package-prop a third, boolean argument. If non-nil,
`eval' the return value.
This commit is contained in:
Henrik Lissner 2018-06-24 19:58:25 +02:00
parent 2ad1280e4e
commit e99ae5382c
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 29 additions and 31 deletions

View file

@ -88,11 +88,12 @@ list of the package."
(list name old-version new-version))))) (list name old-version new-version)))))
;;;###autoload ;;;###autoload
(defun doom-package-prop (name prop) (defun doom-package-prop (name prop &optional eval)
"Return PROPerty in NAME's plist." "Return PROPerty in NAME's plist."
(cl-check-type name symbol) (cl-check-type name symbol)
(cl-check-type prop keyword) (cl-check-type prop keyword)
(plist-get (cdr (assq name doom-packages)) prop)) (let ((value (plist-get (cdr (assq name doom-packages)) prop)))
(if eval (eval value) value)))
;;;###autoload ;;;###autoload
(defun doom-package-different-backend-p (name) (defun doom-package-different-backend-p (name)
@ -164,9 +165,9 @@ files."
if (and (or (not backend) if (and (or (not backend)
(eq (doom-package-backend sym t) backend)) (eq (doom-package-backend sym t) backend))
(or (eq ignored 'any) (or (eq ignored 'any)
(if ignored (let* ((form (plist-get plist :ignore))
(plist-get plist :ignore) (value (eval form)))
(not (plist-get plist :ignore)))) (if ignored value (not value))))
(or (eq disabled 'any) (or (eq disabled 'any)
(if disabled (if disabled
(plist-get plist :disable) (plist-get plist :disable)
@ -236,9 +237,9 @@ Used by `doom-packages-update'."
(let (quelpa-pkgs elpa-pkgs) (let (quelpa-pkgs elpa-pkgs)
;; Separate quelpa from elpa packages ;; Separate quelpa from elpa packages
(dolist (pkg (mapcar #'car package-alist)) (dolist (pkg (mapcar #'car package-alist))
(when (and (or (not (doom-package-prop pkg :freeze)) (when (and (or (not (doom-package-prop pkg :freeze 'eval))
include-frozen-p) include-frozen-p)
(not (doom-package-prop pkg :ignore)) (not (doom-package-prop pkg :ignore 'eval))
(not (doom-package-different-backend-p pkg))) (not (doom-package-different-backend-p pkg)))
(push pkg (push pkg
(if (eq (doom-package-backend pkg) 'quelpa) (if (eq (doom-package-backend pkg) 'quelpa)

View file

@ -171,7 +171,7 @@ them."
;; Module package macros ;; Module package macros
;; ;;
(defmacro package! (name &rest plist) (cl-defmacro package! (name &rest plist &key recipe pin disable _ignore _freeze)
"Declares a package and how to install it (if applicable). "Declares a package and how to install it (if applicable).
This macro is declarative and does not load nor install packages. It is used to This macro is declarative and does not load nor install packages. It is used to
@ -200,30 +200,27 @@ Returns t if package is successfully registered, and nil if it was disabled
elsewhere." elsewhere."
(declare (indent defun)) (declare (indent defun))
(doom--assert-stage-p 'packages #'package!) (doom--assert-stage-p 'packages #'package!)
(let* ((old-plist (cdr (assq name doom-packages))) (let ((plist (append plist (cdr (assq name doom-packages)))))
(pkg-recipe (or (plist-get plist :recipe) (when recipe
(and old-plist (plist-get old-plist :recipe)))) (when (cl-evenp (length recipe))
(pkg-pin (or (plist-get plist :pin) (setq plist (plist-put plist :recipe (cons name recipe))))
(and old-plist (plist-get old-plist :pin)))) (setq pin nil
(pkg-disable (or (plist-get plist :disable) plist (plist-put plist :pin nil)))
(and old-plist (plist-get old-plist :disable))))) (when (file-in-directory-p (FILE!) doom-private-dir)
(when pkg-recipe
(when (= 0 (% (length pkg-recipe) 2))
(setq plist (plist-put plist :recipe (cons name pkg-recipe))))
(when pkg-pin
(setq plist (plist-put plist :pin nil))))
(dolist (prop '(:ignore :freeze))
(when-let* ((val (plist-get plist prop)))
(setq plist (plist-put plist prop (eval val)))))
(when (file-in-directory-p (or (bound-and-true-p byte-compile-current-file)
load-file-name)
doom-private-dir)
(setq plist (plist-put plist :private t))) (setq plist (plist-put plist :private t)))
`(progn (let (newplist)
,(if pkg-disable `(add-to-list 'doom-disabled-packages ',name nil #'eq)) (while plist
,(if pkg-pin `(setf (alist-get ',name package-pinned-packages) ,pkg-pin)) (unless (null (cadr plist))
(setf (alist-get ',name doom-packages) ',plist) (push (cadr plist) newplist)
(not (memq ',name doom-disabled-packages))))) (push (car plist) newplist))
(pop plist)
(pop plist))
(setq plist newplist))
(macroexp-progn
(append (if disable `((add-to-list 'doom-disabled-packages ',name nil #'eq)))
(if pin `((setf (alist-get ',name package-pinned-packages) ,pin)))
`((setf (alist-get ',name doom-packages) ',plist)
(not (memq ',name doom-disabled-packages)))))))
(defmacro packages! (&rest packages) (defmacro packages! (&rest packages)
"A convenience macro like `package!', but allows you to declare multiple "A convenience macro like `package!', but allows you to declare multiple