diff --git a/modules/init-lib.el b/modules/init-lib.el index 67dd277c..6602c842 100644 --- a/modules/init-lib.el +++ b/modules/init-lib.el @@ -11,7 +11,6 @@ (load (file-name-concat (locate-user-emacs-file "modules") "init-require")))) (exordium-require 'init-prefs) -(require 'use-package) (require 'cl-lib) ;;; Files @@ -72,6 +71,11 @@ It makes buffer local variable with an extra back tick added." ;; Packages management +(require 'package) +(eval-when-compile + (use-package use-package + :autoload (use-package-only-one + use-package-process-keywords))) (defun use-package-normalize/:exordium-force-elpa (_name keyword args) ; checkdoc-params: (keyword args) @@ -92,18 +96,36 @@ Installation only hapens when the package is a built-in package." (let ((body (use-package-process-keywords name rest state)) (force-elpa-form (when archive-name - `(let ((package ',(use-package-as-symbol name))) - (use-package-pin-package package ,archive-name) + `(let ((package ',(use-package-as-symbol name)) + refreshed) + (package-read-all-archive-contents) ;; Once package is installed from ELPA it is no longer a built-in package - (when (package-built-in-p package) + (when-let* (((package-built-in-p package)) + (builtin-version (alist-get package package--builtin-versions)) + (archive-desc (or + (cl-find-if (lambda (desc) + (equal (package-desc-archive desc) + ,archive-name)) + (alist-get package + package-archive-contents)) + (progn + (package-refresh-contents) + (setq refreshed t) + (cl-find-if (lambda (desc) + (equal (package-desc-archive desc) + ,archive-name)) + (alist-get package + package-archive-contents))))) + (archive-version (package-desc-version archive-desc)) + ((version-list-< builtin-version archive-version))) + (use-package-pin-package package ,archive-name) (condition-case-unless-debug err (let ((package-install-upgrade-built-in t)) - (package-read-all-archive-contents) (if (assoc package package-archive-contents) (package-install package) - (package-refresh-contents) - (package-read-all-archive-contents) - (package-install package)) + (unless refreshed + (package-refresh-contents) + (package-install package))) t) (error (display-warning 'use-package