Refactor package! macro

This commit is contained in:
Henrik Lissner 2019-07-22 22:30:35 +02:00
parent 93f7520c79
commit 0eb200c49f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -197,7 +197,8 @@ necessary package metadata is initialized and available for them."
;; ;;
;;; Module package macros ;;; Module package macros
(cl-defmacro package! (name &rest plist &key built-in _recipe disable ignore _freeze) (cl-defmacro package!
(name &rest plist &key built-in _recipe 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
@ -226,28 +227,39 @@ Returns t if package is successfully registered, and nil if it was disabled
elsewhere." elsewhere."
(declare (indent defun)) (declare (indent defun))
(let ((old-plist (cdr (assq name doom-packages)))) (let ((old-plist (cdr (assq name doom-packages))))
;; Add current module to :modules
(let ((module-list (plist-get old-plist :modules)) (let ((module-list (plist-get old-plist :modules))
(module (or doom--current-module (module (doom-module-from-path)))
(let ((file (file!)))
(cond ((file-in-directory-p file doom-private-dir)
(list :private))
((file-in-directory-p file doom-core-dir)
(list :core))
((doom-module-from-path file)))))))
(unless (member module module-list) (unless (member module module-list)
(setq module-list (append module-list (list module) nil) (plist-put! plist :modules
plist (plist-put plist :modules module-list)))) (append module-list
(list module)
nil))))
;; Handle :built-in
(unless ignore
(when built-in (when built-in
(doom-log "Ignoring built-in package %S" name) (doom-log "Ignoring built-in package %S" name)
(when (equal built-in '(quote prefer)) (when (equal built-in '(quote prefer))
(setq built-in `(locate-library ,(symbol-name name) nil doom--initial-load-path)))) (setq built-in `(locate-library ,(symbol-name name) nil doom--initial-load-path))))
(setq plist (plist-put plist :ignore (or built-in ignore))) (plist-put! plist :ignore built-in))
(while plist
(unless (null (cadr plist)) ;; DEPRECATED Translate :fetcher to :host
(setq old-plist (plist-put old-plist (car plist) (cadr plist)))) (with-plist! plist (recipe)
(pop plist) (with-plist! recipe (fetcher)
(pop plist)) (when fetcher
(message "%s\n%s"
"WARNING: The :fetcher property was used for the %S package."
"This property is deprecated. Replace it with :host.")
(plist-put! recipe :host fetcher)
(plist-delete! recipe :fetcher))
(plist-put! plist :recipe recipe)))
(doplist! ((prop val) plist)
(unless (null val)
(plist-put! old-plist prop val)))
(setq plist old-plist) (setq plist old-plist)
;; TODO Add `straight-use-package-pre-build-function' support ;; TODO Add `straight-use-package-pre-build-function' support
(macroexp-progn (macroexp-progn
(append `((setf (alist-get ',name doom-packages) ',plist)) (append `((setf (alist-get ',name doom-packages) ',plist))