Skip to content

Commit

Permalink
[fu] init-lib: exordium-force-elpa
Browse files Browse the repository at this point in the history
  • Loading branch information
pkryger committed Nov 14, 2024
1 parent 6acbc64 commit cb50403
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions modules/init-lib.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit cb50403

Please sign in to comment.