From 5cd28b75b35e900da741510e6559627731de1eba Mon Sep 17 00:00:00 2001 From: Kien Nguyen Date: Wed, 3 Aug 2022 17:25:37 +0900 Subject: [PATCH] Allow to use quelpa-use-package as source of truth for quelpa-cache --- quelpa-use-package.el | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/quelpa-use-package.el b/quelpa-use-package.el index a20cdf6..b07ddc0 100644 --- a/quelpa-use-package.el +++ b/quelpa-use-package.el @@ -37,10 +37,28 @@ ;;; 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 @@ -48,6 +66,7 @@ can prevent packages from being updated automatically.") (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 @@ -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)))