Add :ignore & :freeze support to package!

This commit is contained in:
Henrik Lissner 2017-06-05 14:21:07 +02:00
parent e73def1c71
commit 435fda0f41
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 33 additions and 11 deletions

View file

@ -70,6 +70,18 @@ list of the package."
(version-list-< old-version new-version)) (version-list-< old-version new-version))
(list name old-version new-version))))) (list name old-version new-version)))))
;;;###autoload
(defun doom-package-ignored-p (name)
"Return t if NAME (a package symbol) has an :ignore property."
(doom-initialize-packages)
(plist-get (cdr (assq name doom-packages)) :ignore))
;;;###autoload
(defun doom-package-frozen-p (name)
"Return t if NAME (a package symbol) has an :frozen property."
(doom-initialize-packages)
(plist-get (cdr (assq name doom-packages)) :freeze))
;;;###autoload ;;;###autoload
(defun doom-get-packages (&optional backend) (defun doom-get-packages (&optional backend)
"Retrieves a list of explicitly installed packages (i.e. non-dependencies). "Retrieves a list of explicitly installed packages (i.e. non-dependencies).
@ -103,12 +115,18 @@ Be careful not to use it in a loop."
(package--get-deps name only)) (package--get-deps name only))
;;;###autoload ;;;###autoload
(defun doom-get-outdated-packages () (defun doom-get-outdated-packages (&optional include-frozen-p)
"Return a list of packages that are out of date. Each element is a list, "Return a list of packages that are out of date. Each element is a list,
containing (PACKAGE-SYMBOL OLD-VERSION-LIST NEW-VERSION-LIST). containing (PACKAGE-SYMBOL OLD-VERSION-LIST NEW-VERSION-LIST).
If INCLUDE-FROZEN-P is non-nil, check frozen packages as well.
Used by `doom/packages-update'." Used by `doom/packages-update'."
(delq nil (mapcar #'doom-package-outdated-p (mapcar #'car (doom-get-packages))))) (let ((pkgs (mapcar #'car (doom-get-packages))))
(delq nil
(mapcar #'doom-package-outdated-p
(if include-frozen-p pkgs
(cl-remove-if #'doom-package-frozen-p pkgs))))))
;;;###autoload ;;;###autoload
(defun doom-get-orphaned-packages () (defun doom-get-orphaned-packages ()
@ -119,21 +137,25 @@ Used by `doom/packages-autoremove'."
(doom-initialize-packages t) (doom-initialize-packages t)
(let ((package-selected-packages (let ((package-selected-packages
(append (mapcar #'car doom-packages) doom-core-packages))) (append (mapcar #'car doom-packages) doom-core-packages)))
(cl-set-difference (package--removable-packages) (package--removable-packages)))
doom-protected-packages)))
;;;###autoload ;;;###autoload
(defun doom-get-missing-packages () (defun doom-get-missing-packages (&optional include-ignored-p)
"Return a list of requested packages that aren't installed or built-in, but "Return a list of requested packages that aren't installed or built-in, but
are enabled (with a `package!' directive). Each element is a list whose CAR is are enabled (with a `package!' directive). Each element is a list whose CAR is
the package symbol, and whose CDR is a plist taken from that package's the package symbol, and whose CDR is a plist taken from that package's
`package!' declaration. `package!' declaration.
If INCLUDE-IGNORED-P is non-nil, includes missing packages that are ignored,
i.e. they have an :ignore property.
Used by `doom/packages-install'." Used by `doom/packages-install'."
(cl-remove-if (lambda (pkgsym) (cl-remove-if (lambda (pkgsym)
(or (assq (car pkgsym) package-alist) (let ((pkg (car pkgsym)))
(and (not (plist-get (assq (car pkgsym) doom-packages) :pin)) (or (assq pkg package-alist)
(assq (car pkgsym) package--builtins)))) (unless include-ignored-p (doom-package-ignored-p pkg))
(and (not (plist-get (assq pkg doom-packages) :pin))
(assq pkg package--builtins)))))
(doom-get-packages))) (doom-get-packages)))
;;;###autoload ;;;###autoload

View file

@ -56,9 +56,6 @@ package's name as a symbol, and whose CDR is the plist supplied to its
"A list of packages that must be installed (and will be auto-installed if "A list of packages that must be installed (and will be auto-installed if
missing) and shouldn't be deleted.") missing) and shouldn't be deleted.")
(defvar doom-protected-packages nil
"A list of packages that shouldn't be deleted by `doom/packages-autoremove'.")
(defvar doom-init-time nil (defvar doom-init-time nil
"The time it took, in seconds, for DOOM Emacs to initialize.") "The time it took, in seconds, for DOOM Emacs to initialize.")
@ -359,6 +356,8 @@ Accepts the following properties:
from external sources. from external sources.
:pin ARCHIVE-NAME Instructs ELPA to only look for this package in :pin ARCHIVE-NAME Instructs ELPA to only look for this package in
ARCHIVE-NAME. e.g. \"org\". Ignored if RECIPE is present. ARCHIVE-NAME. e.g. \"org\". Ignored if RECIPE is present.
:ignore t Do not install this package.
:freeze t Do not update this package.
This macro serves a purely declarative purpose, and are used to fill This macro serves a purely declarative purpose, and are used to fill
`doom-packages', so that functions like `doom/packages-install' can operate on `doom-packages', so that functions like `doom/packages-install' can operate on
@ -380,6 +379,7 @@ them."
:test #'eq :key #'car)) :test #'eq :key #'car))
(when ,(and old-plist t) (when ,(and old-plist t)
(assq-delete-all ',name doom-packages)) (assq-delete-all ',name doom-packages))
;; :ignore and :freeze are handled upstream
(push ',(cons name plist) doom-packages)))) (push ',(cons name plist) doom-packages))))
(defmacro depends-on! (module submodule) (defmacro depends-on! (module submodule)