diff options
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 () |
