aboutsummaryrefslogtreecommitdiff
path: root/modules/ai-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-16 01:31:36 -0500
committerCraig Jennings <c@cjennings.net>2026-05-16 01:31:36 -0500
commit1ca46c2b477afd014ef993ed0ca5ca50e257adce (patch)
tree66ddfecc234c18f8d90e6e7908204de0afd3e3d2 /modules/ai-config.el
parent531f0f19f298e28b42dfb216f6008a1cbc6164d3 (diff)
downloaddotemacs-1ca46c2b477afd014ef993ed0ca5ca50e257adce.tar.gz
dotemacs-1ca46c2b477afd014ef993ed0ca5ca50e257adce.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/ai-config.el')
-rw-r--r--modules/ai-config.el19
1 files changed, 13 insertions, 6 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el
index bc896704..0ffee799 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))))