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 22, 2022
1 parent d985c03 commit effc597
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions quelpa-use-package.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,35 @@

;;; Code:

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

(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)

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

(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)
(defvar quelpa-persistent-cache-p)

(when quelpa-use-package-as-source-of-truth
(setq quelpa-persistent-cache-p nil))

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

0 comments on commit effc597

Please sign in to comment.