Skip to content

Commit

Permalink
feat(use-package): add :trigger-commands option
Browse files Browse the repository at this point in the history
  • Loading branch information
abougouffa committed May 19, 2024
1 parent f3df815 commit b50fe3c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/me-use-package-extra.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

;;; Code:

(eval-when-compile
(require 'straight)
(require 'use-package))

(with-eval-after-load 'straight
;; Add a profile (and lockfile) for stable package revisions.
(add-to-list 'straight-profiles '(pinned . "pinned.el"))
Expand All @@ -19,7 +23,25 @@
;; Allow pinning versions from `use-package' using the `:pin-ref' keyword
(with-eval-after-load 'use-package-core
(add-to-list 'use-package-keywords :pin-ref)
(add-to-list 'use-package-keywords :trigger-commands)

;; :trigger-commands
(defun use-package-normalize/:trigger-commands (name keyword args)
(setq args (use-package-normalize-recursive-symlist name keyword args))
(if (consp args) args (list args)))

(defun use-package-handler/:trigger-commands (name _keyword arg rest state)
(use-package-concat
(cl-mapcan
#'(lambda (command)
(when (symbolp command)
(append
(unless (plist-get state :demand)
`((+advice-once! ,command :before (require ,name)))))))
(delete-dups arg))
(use-package-process-keywords name rest state)))

;; :pin-ref
(defun use-package-normalize/:pin-ref (_name-symbol keyword args)
(use-package-only-one (symbol-name keyword) args
(lambda (_label arg)
Expand Down

0 comments on commit b50fe3c

Please sign in to comment.