diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-16 00:31:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-16 00:31:58 -0500 |
| commit | d384b3bb7abf7be1d6d66d06809ffdc98583ec83 (patch) | |
| tree | 35aaa1926878b3c9f9f2b6de6600a4fb728d0297 /modules | |
| parent | 3236b5da26e1d92f17694601b31e9efae058a6ff (diff) | |
| download | dotemacs-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 'modules')
| -rw-r--r-- | modules/ai-config.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/ai-config.el b/modules/ai-config.el index 4a3d6a82..2783bc18 100644 --- a/modules/ai-config.el +++ b/modules/ai-config.el @@ -379,6 +379,28 @@ Works for any buffer, whether it's visiting a file or not." (advice-add 'gptel-send :before #'cj/gptel--refresh-org-prefix) (add-hook 'gptel-post-response-functions #'cj/gptel-insert-model-heading)) +;; Workaround: gptel's `gptel--with-buffer-copy-internal' copies the +;; source buffer's `major-mode' symbol into the prompt buffer but does +;; not run mode hooks, so `org-mode-hook' never fires there. In this +;; config the global `tab-width' default is 4, while `org-mode-hook' +;; sets it to 8 — so an inherited-org-mode prompt buffer keeps +;; `tab-width=4', and Org's `org-element--list-struct' guard raises +;; "Tab width in Org files must be 8" when gptel later parses it. +;; +;; Triggered in practice by `gptel-magit-generate-message' run from +;; COMMIT_EDITMSG with `git-commit-major-mode' set to `org-mode' (see +;; modules/vc-config.el). Force `tab-width=8' before `body-thunk' +;; runs so the prompt buffer satisfies Org's invariant. +(define-advice gptel--with-buffer-copy-internal + (:around (orig buf start end body-thunk) cj/fix-org-tab-width) + "Force `tab-width=8' in the gptel prompt buffer when its inherited +`major-mode' is `org-mode'." + (funcall orig buf start end + (lambda () + (when (eq major-mode 'org-mode) + (setq-local tab-width 8)) + (funcall body-thunk)))) + ;;; ---------------------------- Toggle GPTel Window ---------------------------- (defun cj/toggle-gptel () |
