diff --git a/modules/init-lib.el b/modules/init-lib.el index 3a66adec..e7241a24 100644 --- a/modules/init-lib.el +++ b/modules/init-lib.el @@ -136,12 +136,30 @@ see Info node `(emacs) Package Installation'." (use-package-pin-package package ,archive-name) (condition-case-unless-debug err (let ((package-install-upgrade-built-in t) - (load-path (cons (expand-file-name - (package-desc-full-name archive-desc) - package-user-dir) - load-path))) - (package-install-from-archive archive-desc) - t) + ;; Ensure the newly installed package is in `load-path' + (with-load-path + (lambda (orig-fun &rest args) + (let ((pkg-dir (expand-file-name + (package-desc-full-name archive-desc) + package-user-dir))) + (if (or (member (file-name-as-directory pkg-dir) load-path) + (member (directory-file-name pkg-dir) load-path)) + (apply orig-fun args) + (let ((load-path (cons pkg-dir load-path))) + (apply orig-fun args))))))) + (unwind-protect + (progn + ;; `packgage-activate-1' calls + ;; `package--reload-previously-loaded' before + ;; adding the newly installed package directory to + ;; `load-path'. Ensure the new files are visible. + (advice-add 'package--reload-previously-loaded + :around + with-load-path) + (package-install-from-archive archive-desc) + t) + (advice-remove 'package--reload-previously-loaded + with-load-path))) (error (display-warning 'use-package (format "Failed to force ELPA installation %s: %s"