aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/ai-config.el32
-rw-r--r--tests/test-ai-config-gptel-magit-lazy-loading.el16
-rw-r--r--todo.org6
3 files changed, 38 insertions, 16 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el
index 92992aa7..4a3d6a82 100644
--- a/modules/ai-config.el
+++ b/modules/ai-config.el
@@ -426,27 +426,27 @@ Works for any buffer, whether it's visiting a file or not."
;;; -------------------------------- GPTel-Magit --------------------------------
-;; Lazy gptel-magit integration (replaces use-package gptel-magit block).
+;; `: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.
;;
-;; The original `(magit-mode . gptel-magit-install)' hook ran on every magit
-;; buffer, repeatedly re-installing keybindings and loading gptel eagerly.
-;;
-;; Instead, we register autoloads and wire up keybindings once when magit
-;; loads. gptel-magit (and gptel) are only loaded when you actually press
-;; one of these keys:
+;; Keys:
;; M-g — generate commit message (in commit message buffer)
;; g — generate commit (in magit-commit transient)
;; x — explain diff (in magit-diff transient)
-(with-eval-after-load 'magit
- (autoload 'gptel-magit-generate-message "gptel-magit" nil t)
- (autoload 'gptel-magit-commit-generate "gptel-magit" nil t)
- (autoload 'gptel-magit-diff-explain "gptel-magit" nil t)
- (define-key git-commit-mode-map (kbd "M-g") #'gptel-magit-generate-message)
- (transient-append-suffix 'magit-commit #'magit-commit-create
- '("g" "Generate commit" gptel-magit-commit-generate))
- (transient-append-suffix 'magit-diff #'magit-stash-show
- '("x" "Explain" gptel-magit-diff-explain)))
+(use-package gptel-magit
+ :defer t
+ :commands (gptel-magit-generate-message
+ 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)
+ (transient-append-suffix 'magit-commit #'magit-commit-create
+ '("g" "Generate commit" gptel-magit-commit-generate))
+ (transient-append-suffix 'magit-diff #'magit-stash-show
+ '("x" "Explain" gptel-magit-diff-explain))))
;; ------------------------------ GPTel Directives -----------------------------
diff --git a/tests/test-ai-config-gptel-magit-lazy-loading.el b/tests/test-ai-config-gptel-magit-lazy-loading.el
index 05e3634d..bc345ef0 100644
--- a/tests/test-ai-config-gptel-magit-lazy-loading.el
+++ b/tests/test-ai-config-gptel-magit-lazy-loading.el
@@ -123,5 +123,21 @@ a gptel-magit function is called."
One for magit-commit (generate) and one for magit-diff (explain)."
(should (= 2 (length test-gptel-magit--transient-calls))))
+;;; Error Cases — Install behavior
+
+(ert-deftest test-ai-config-gptel-magit-declared-via-use-package ()
+ "ai-config should declare gptel-magit via `use-package' so it gets installed.
+Raw `(autoload ...)' calls register the function name but leave the
+package uninstalled on machines that never ran `package-install'. The
+\\=`use-package' form inherits `use-package-always-ensure' from
+early-init, which is how every other package in this config gets
+onto `load-path' before its autoloads fire."
+ (let ((source-file (expand-file-name "modules/ai-config.el"
+ user-emacs-directory)))
+ (with-temp-buffer
+ (insert-file-contents source-file)
+ (goto-char (point-min))
+ (should (re-search-forward "(use-package gptel-magit\\b" nil t)))))
+
(provide 'test-ai-config-gptel-magit-lazy-loading)
;;; test-ai-config-gptel-magit-lazy-loading.el ends here
diff --git a/todo.org b/todo.org
index 9411604c..787f190b 100644
--- a/todo.org
+++ b/todo.org
@@ -38,6 +38,12 @@ Tags are additive. For example, a small wrong-behavior fix can be
=:feature:refactor:=.
* Emacs Open Work
+
+** DOING [#A] transient-setup error when running gptel magit :bug:
+When running gptel magit during a commit message on this machine, I get the following error consistently:
+transient-setup: Cannot open load file: No such file or directory, gptel-magit
+
+
** PROJECT [#A] Architecture review follow-up from 2026-05-03 :refactor:no-sync:
High-level pass over =init.el=, =early-init.el=, and all 104 files in