Skip to content

Commit

Permalink
Allow to use quelpa-use-package as source of truth for quelpa-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
kiennq committed Aug 23, 2024
1 parent d985c03 commit 5cd28b7
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions quelpa-use-package.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,36 @@

;;; Code:

(defvar quelpa-use-package-inhibit-loading-quelpa nil
(defgroup quelpa-use-package nil
"Quelpa handler for `use-package'."
:group 'quelpa)

(defcustom quelpa-use-package-inhibit-loading-quelpa nil
"If non-nil, `quelpa-use-package' will do its best to avoid
loading `quelpa' unless necessary. This improves performance, but
can prevent packages from being updated automatically.")
can prevent packages from being updated automatically."
:type 'boolean
:group 'quelpa-use-package)

(defvar quelpa-persistent-cache-p)

(defcustom quelpa-use-package-as-source-of-truth nil
"If non-nil, only packages installed by this package will be managed by `quelpa'.
This option will disable `quelpa-persistent-cache-p'."
:type 'boolean
:group 'quelpa-use-package
:set (lambda (symbol value)
(set-default-toplevel-value symbol value)
(when value
(setq quelpa-persistent-cache-p nil))))

(require 'cl-lib)
(unless quelpa-use-package-inhibit-loading-quelpa
(require 'quelpa))
(require 'use-package-core)

(defvar quelpa-use-package-keyword :quelpa)
(defvar quelpa-cache)

;; insert `:quelpa' keyword after `:unless' so that quelpa only runs
;; if either `:if', `:when', `:unless' or `:requires' are satisfied
Expand Down Expand Up @@ -76,11 +95,15 @@ can prevent packages from being updated automatically.")
;; compiled or evaluated.
(if args
(use-package-concat
`((unless (and quelpa-use-package-inhibit-loading-quelpa
(package-installed-p ',(pcase (car args)
((pred symbolp) (car args))
((pred listp) (car (car args))))))
(apply 'quelpa ',args)))
(let ((info (pcase (car args)
((pred listp) (car args))
(`,pkg `(,pkg)))))
`((if (and quelpa-use-package-inhibit-loading-quelpa
(package-installed-p ',(car info)))
(when quelpa-use-package-as-source-of-truth
(setq quelpa-cache (when (boundp 'quelpa-cache) quelpa-cache))
(setf (alist-get ',(car info) quelpa-cache) ',(cdr info)))
(quelpa ',@args))))
body)
body)))

Expand Down

0 comments on commit 5cd28b7

Please sign in to comment.