Open mjhoy opened 1 year ago
Yeah seeing this as well. When I disable/enable org-indent-mode it seems to get fixed. It might be related to the org-element-cache issue? https://github.com/rksm/org-ai/issues/16. Hmm. If an org-mode maintainer is seeing this, any idea would be appreciated!
I am definitely not the org-mode expert/maintainer you're looking for, but running this inside the block after the output has been inserted fixes it for me. I was looking for a way to have it run after the text insertion is complete, but I didn't manage yet (there is no hook for that?)
(EDIT: "revert-buffer" is probably easier.)
(defun org-ai-dirty-indent-fix ()
(interactive)
(save-excursion
(evil-org->
(re-search-backward "^\\#\\+begin_ai" nil t)
(re-search-forward "^\\#\\+end_ai" nil t) 2)
(evil-undo 1)))
I personally just save and use C-x x g
, revert-buffer-quick
if I notice the indentation is off.
Is there a way run revert-buffer-quick after org-ai is done? Some hook that runs functions after the response has been inserted?
You can do something like
(add-hook 'org-ai-after-chat-insertion-hook
(lambda (type text) ; type will be 'text, 'role or 'end
(when (eq type 'end)
(save-buffer)
(revert-buffer-quick))))
I've been using the following hook to solve this issue:
(defun dss/-org-ai-after-chat-insertion-hook (type _text)
(when (and (eq type 'end) (eq major-mode 'org-mode) (memq 'org-indent-mode minor-mode-list))
(org-indent-indent-buffer)))
(add-hook 'org-ai-after-chat-insertion-hook #'dss/-org-ai-after-chat-insertion-hook)
AI chat within
begin_ai
blocks doesn't seem to maintainorg-indent-mode
in a way that makes my OCD go crazy 😂. Looking at the code, I don't totally understand why this is... it seems to just useinsert
and when I evaluate(insert "\n\n")
locally, for instance, I can't reproduce the behavior.