|
69 | 69 | ;; from it. This advice also evaluates `use-package's conditional sections
|
70 | 70 | ;; (`:if', `:when' and `:unless') to prevent installing packages with
|
71 | 71 | ;; `straight'.
|
72 |
| - (advice-add |
73 |
| - 'use-package :around |
74 |
| - (satch-defun +use-package--check-if-disabled:around-a (origfn package &rest args) |
75 |
| - (if (or (+package-disabled-p package) |
76 |
| - (and (memq :if args) |
77 |
| - (not (and (memq :if args) (eval (+varplist-get args :if t))))) |
78 |
| - (and (memq :when args) |
79 |
| - (not (and (memq :when args) (eval (+varplist-get args :when t))))) |
80 |
| - (and (memq :unless args) |
81 |
| - (not (and (memq :unless args) (not (eval (+varplist-get args :unless t))))))) |
82 |
| - ;; Register the package but don't enable it, useful when creating the lockfile, |
83 |
| - ;; this is the official straight.el way for conditionally installing packages |
84 |
| - (when-let* ((recipe (+varplist-get args :straight t))) |
85 |
| - (let* ((recipe (if (eq recipe t) (list package) recipe)) |
86 |
| - (car-recipe (and (listp recipe) (car recipe))) |
87 |
| - (car-recipe-is-pkg (and (symbolp car-recipe) (not (keywordp car-recipe)))) |
88 |
| - (recipe (if (and car-recipe car-recipe-is-pkg) recipe (append (list package) recipe)))) |
89 |
| - (straight-register-package recipe))) |
90 |
| - ;; Otherwise, add it to the list of configured packages and apply the `use-package' form |
91 |
| - (add-to-list 'minemacs-configured-packages package t) |
92 |
| - (apply origfn package args)))) |
| 72 | + (defun +use-package--check-if-disabled:around-a (origfn package &rest args) |
| 73 | + (if (or (+package-disabled-p package) |
| 74 | + (and (memq :if args) |
| 75 | + (not (and (memq :if args) (eval (+varplist-get args :if t))))) |
| 76 | + (and (memq :when args) |
| 77 | + (not (and (memq :when args) (eval (+varplist-get args :when t))))) |
| 78 | + (and (memq :unless args) |
| 79 | + (not (and (memq :unless args) (not (eval (+varplist-get args :unless t))))))) |
| 80 | + ;; Register the package but don't enable it, useful when creating the lockfile, |
| 81 | + ;; this is the official straight.el way for conditionally installing packages |
| 82 | + (when-let* ((recipe (+varplist-get args :straight t))) |
| 83 | + (let* ((recipe (if (eq recipe t) (list package) recipe)) |
| 84 | + (car-recipe (and (listp recipe) (car recipe))) |
| 85 | + (car-recipe-is-pkg (and (symbolp car-recipe) (not (keywordp car-recipe)))) |
| 86 | + (recipe (if (and car-recipe car-recipe-is-pkg) recipe (append (list package) recipe)))) |
| 87 | + (straight-register-package recipe))) |
| 88 | + ;; Otherwise, add it to the list of configured packages and apply the `use-package' form |
| 89 | + (add-to-list 'minemacs-configured-packages package t) |
| 90 | + (apply origfn package args))) |
| 91 | + |
| 92 | + (advice-add 'use-package :around #'+use-package--check-if-disabled:around-a) |
93 | 93 |
|
94 | 94 | ;; If you want to keep the `+use-package--check-if-disabled:around-a' advice after
|
95 | 95 | ;; loading MinEmacs' modules. You need to set in in your
|
|
99 | 99 | ;; The previous advice will be removed after loading MinEmacs packages to avoid
|
100 | 100 | ;; messing with the user configuration (for example, if the user manually
|
101 | 101 | ;; install a disabled package).
|
102 |
| - (add-hook |
103 |
| - 'minemacs-after-loading-modules-hook |
104 |
| - (satch-defun +use-package--remove-check-if-disabled-advice-h () |
105 |
| - (unless +use-package-keep-checking-for-disabled-p |
106 |
| - (advice-remove 'use-package '+use-package--check-if-disabled:around-a))))) |
| 102 | + (defun +use-package--remove-check-if-disabled-advice-h () |
| 103 | + (unless +use-package-keep-checking-for-disabled-p |
| 104 | + (advice-remove 'use-package '+use-package--check-if-disabled:around-a))) |
| 105 | + |
| 106 | + (add-hook 'minemacs-after-loading-modules-hook #'+use-package--remove-check-if-disabled-advice-h)) |
107 | 107 |
|
108 | 108 |
|
109 | 109 | (provide 'me-use-package-extra)
|
|
0 commit comments