Skip to content

Commit

Permalink
refactor: group use-package related hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed Jul 18, 2023
1 parent 2d5a931 commit bc25440
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
24 changes: 3 additions & 21 deletions core/me-bootstrap.el
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,16 @@
(unless (require 'use-package nil t)
(straight-use-package 'use-package))

;; Add the `:pin-ref' extension to `use-package'
(require 'me-use-package-pin-ref)
;; Add the `:pin-ref' extension to integrate `straight' with `use-package'. And
;; add support for `minemacs-disabled-packages'.
(require 'me-use-package-extra)

(setq
;; Set `use-package' to verbose when MinEmacs is started in verbose mode
use-package-verbose (cond (minemacs-debug 'debug) (minemacs-verbose t))
;; Defer loading packages by default, use `:demand' to force loading a package
use-package-always-defer t)

;; HACK: This advice around `use-package' checks if a package is disabled in
;; `minemacs-disabled-packages' before calling `use-package'. This can come
;; handy if the user wants to enable some module while excluding some packages
;; from it.
(advice-add
'use-package :around
(defun +use-package--check-if-disabled-a (origfn package &rest args)
(unless (+package-disabled-p package)
(add-to-list 'minemacs-configured-packages package t)
(apply origfn package args))))

;; The previous advice will be removed after loading MinEmacs packages to avoid
;; messing with the user configuration (for example, if the user manually
;; install a disabled package).
(add-hook
'minemacs-after-loading-modules-hook
(defun +use-package--remove-check-if-disabled-advice-h ()
(advice-remove 'use-package '+use-package--check-if-disabled-a)))


(provide 'me-bootstrap)

Expand Down
33 changes: 26 additions & 7 deletions core/me-use-package-pin-ref.el → core/me-use-package-extra.el
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;; me-use-package-pin-ref.el --- Extend use-package to allow straight-x package pinning -*- lexical-binding: t; -*-
;; me-use-package-extra.el --- Extend use-package to allow straight-x package pinning -*- lexical-binding: t; -*-

;; Copyright (C) 2022-2023 Abdelhak Bougouffa

Expand Down Expand Up @@ -34,9 +34,28 @@
body
`((let ((straight-current-profile 'pinned))
(push '(,(symbol-name name-symbol) . ,ref) straight-x-pinned-packages)
,(macroexp-progn body)))))))


(provide 'me-use-package-pin-ref)

;;; me-use-package-pin-ref.el ends here
,(macroexp-progn body))))))

;; HACK: This advice around `use-package' checks if a package is disabled in
;; `minemacs-disabled-packages' before calling `use-package'. This can come
;; handy if the user wants to enable some module while excluding some packages
;; from it.
(advice-add
'use-package :around
(defun +use-package--check-if-disabled-a (origfn package &rest args)
(unless (+package-disabled-p package)
(add-to-list 'minemacs-configured-packages package t)
(apply origfn package args))))

;; The previous advice will be removed after loading MinEmacs packages to avoid
;; messing with the user configuration (for example, if the user manually
;; install a disabled package).
(add-hook
'minemacs-after-loading-modules-hook
(defun +use-package--remove-check-if-disabled-advice-h ()
(advice-remove 'use-package '+use-package--check-if-disabled-a))))


(provide 'me-use-package-extra)

;;; me-use-package-extra.el ends here

0 comments on commit bc25440

Please sign in to comment.