diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-16 01:31:36 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-16 01:31:36 -0500 |
| commit | b29223020b69b3467ea9c15fb76f4d157162ba75 (patch) | |
| tree | 4630f73eaca00e7bb4f7ca1400e6926eedc5301c /modules | |
| parent | 38e64bc76d4e1bb5a036fa5612dbf4c576a9bbc9 (diff) | |
| download | dotemacs-b29223020b69b3467ea9c15fb76f4d157162ba75.tar.gz dotemacs-b29223020b69b3467ea9c15fb76f4d157162ba75.zip | |
fix(ai-config): hook gptel-magit wiring per-feature, not on magit
The wiring keyed on `with-eval-after-load 'magit` fires while two
of its three references are still undefined. `magit.el` calls
`(provide 'magit)` BEFORE its `cl-eval-when (load eval)` block
requires `magit-commit` and `magit-stash`. At that moment the
`magit-commit` transient prefix doesn't exist, and
`transient-append-suffix` silently no-ops on missing prefixes
(default `transient-error-on-insert-failure` is nil). The "g
Generate commit" and "x Explain" suffixes never landed. Only the
M-g binding worked, because `git-commit` IS required before
provide.
Three per-feature hooks replace the single `'magit` hook: one each
on `git-commit`, `magit-commit`, and `magit-diff`. Each hooks the
exact dependency the wiring needs, side-stepping the load-order
race entirely.
The companion test was rewritten to check `after-load-alist`
registration rather than drive the hooks through `provide`. Emacs
30 batch mode doesn't fire registered `eval-after-load` callbacks
on `provide` alone -- only an actual `load` does. Inspecting the
registration is the stronger guard anyway: the regression is "a
single `'magit` hook," and the right shape of that check is "no
entry under `magit`, entries under `git-commit`, `magit-commit`,
`magit-diff`."
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/ai-config.el | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el index bc896704c..0ffee799c 100644 --- a/modules/ai-config.el +++ b/modules/ai-config.el @@ -449,9 +449,14 @@ Works for any buffer, whether it's visiting a file or not." ;;; -------------------------------- GPTel-Magit -------------------------------- -;; `:init' wires the bindings as soon as magit loads, so M-g and the transient -;; suffixes are ready before any keystroke. `:commands' + `:defer t' delays -;; loading gptel-magit itself until one of the entry points is invoked. +;; Each integration point waits on its actual dependency, not on `magit' +;; broadly. `magit.el' calls `(provide 'magit)' BEFORE its +;; `cl-eval-when (load eval) ...' block requires `magit-commit' and +;; `magit-stash', so a single `with-eval-after-load 'magit' fires while +;; the transient prefixes the wiring references are still undefined. +;; `transient-append-suffix' silently no-ops on missing prefixes (it +;; calls `message' unless `transient-error-on-insert-failure' is set), +;; which is how the failure stayed invisible. ;; ;; Keys: ;; M-g — generate commit message (in commit message buffer) @@ -464,10 +469,12 @@ Works for any buffer, whether it's visiting a file or not." gptel-magit-commit-generate gptel-magit-diff-explain) :init - (with-eval-after-load 'magit - (define-key git-commit-mode-map (kbd "M-g") #'gptel-magit-generate-message) + (with-eval-after-load 'git-commit + (define-key git-commit-mode-map (kbd "M-g") #'gptel-magit-generate-message)) + (with-eval-after-load 'magit-commit (transient-append-suffix 'magit-commit #'magit-commit-create - '("g" "Generate commit" gptel-magit-commit-generate)) + '("g" "Generate commit" gptel-magit-commit-generate))) + (with-eval-after-load 'magit-diff (transient-append-suffix 'magit-diff #'magit-stash-show '("x" "Explain" gptel-magit-diff-explain)))) |
