aboutsummaryrefslogtreecommitdiff
path: root/tests/testutil-ai-config.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-16 00:31:58 -0500
committerCraig Jennings <c@cjennings.net>2026-05-16 00:31:58 -0500
commitd384b3bb7abf7be1d6d66d06809ffdc98583ec83 (patch)
tree35aaa1926878b3c9f9f2b6de6600a4fb728d0297 /tests/testutil-ai-config.el
parent3236b5da26e1d92f17694601b31e9efae058a6ff (diff)
downloaddotemacs-d384b3bb7abf7be1d6d66d06809ffdc98583ec83.tar.gz
dotemacs-d384b3bb7abf7be1d6d66d06809ffdc98583ec83.zip
fix(ai-config): force tab-width=8 in gptel org-mode prompt buffers
gptel's `gptel--with-buffer-copy-internal` copies the source buffer's `major-mode` symbol but doesn't run mode hooks. An inherited-org-mode prompt buffer keeps `tab-width` at this config's global default of 4 instead of the 8 that `org-mode-hook` would set. When gptel later parses the prompt buffer with `org-element`, Org's `tab-width=8` guard raises "Tab width in Org files must be 8, not 4." I was hitting this on every second `gptel-magit-generate-message` from COMMIT_EDITMSG. `vc-config.el` sets `git-commit-major-mode 'org-mode'`, and the diffs contained list-shaped content that `org-element--list-struct` parsed. The advice forces `tab-width=8` in the prompt buffer when its inherited mode is org-mode. It's a local workaround for an upstream gap. An upstream patch to run `(delay-mode-hooks (funcall major-mode))` in the buffer-copy is the real fix. I'll send it next.
Diffstat (limited to 'tests/testutil-ai-config.el')
-rw-r--r--tests/testutil-ai-config.el15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/testutil-ai-config.el b/tests/testutil-ai-config.el
index c7486222..f56a38e1 100644
--- a/tests/testutil-ai-config.el
+++ b/tests/testutil-ai-config.el
@@ -74,6 +74,21 @@
;; so the magit integration only activates when magit is provided.
;; See test-ai-config-gptel-magit-lazy-loading.el for magit stub tests.
+;; Stub `gptel--with-buffer-copy-internal' so the advice attached to it
+;; in ai-config.el can be exercised without loading real gptel-request.
+;; Mirrors the salient bits of the real function (gptel-request.el:945):
+;; create a temp buffer, copy major-mode as a symbol (no hooks), call
+;; body-thunk inside. See test-ai-config-gptel-prompt-tab-width.el.
+(unless (fboundp 'gptel--with-buffer-copy-internal)
+ (defun gptel--with-buffer-copy-internal (buf _start _end body-thunk)
+ "Stub: create temp buffer, copy major-mode from BUF, run BODY-THUNK."
+ (let ((temp (generate-new-buffer " *gptel-prompt-stub*" t)))
+ (unwind-protect
+ (with-current-buffer temp
+ (setq major-mode (buffer-local-value 'major-mode buf))
+ (funcall body-thunk))
+ (kill-buffer temp)))))
+
;; Stub ai-conversations
(provide 'ai-conversations)