From d384b3bb7abf7be1d6d66d06809ffdc98583ec83 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 16 May 2026 00:31:58 -0500 Subject: 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. --- tests/testutil-ai-config.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/testutil-ai-config.el') 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) -- cgit v1.2.3