Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-indentation and alignment are not supported within #+begin_ai. #47

Open
iT-Boyer opened this issue May 11, 2023 · 4 comments
Open

Comments

@iT-Boyer
Copy link

iT-Boyer commented May 11, 2023

Indentation issue in org-ai: After executing a dialogue, newly added lines by [AI] are not aligned with the content above.
For example:

    #+begin_ai
    [SYS]: You are a helpful assistant.

    [ME]: hello world!
    #+end_ai

layout of newly added content after executing a request:

    #+begin_ai
    [SYS]: You are a helpful assistant.

    [ME]: hello world!

[AI]: Hello! How can I assist you today?

[ME]: 
     #+end_ai

@rksm
Copy link
Owner

rksm commented May 30, 2023

The same is true of org babel src blocks I believe. Not sure if this is something that org-ai can fix, it seems like an issue with org-mode / org-indent-mode

One workaround you can add to your config:

(add-hook #'org-ai-after-chat-insertion-hook
          (lambda (_ _)
            (when (eq major-mode 'org-mode)
              (org-indent-indent-buffer))))

@riclage
Copy link

riclage commented Aug 7, 2023

@rksm your workaround works for small files but slows Emacs to a crawl in larger ones.

Maybe it would help to have a specific hook for after the full chat response is inserted here?

@rksm
Copy link
Owner

rksm commented Aug 8, 2023

I think the simpler option is to use the first argument to customize the behavior:

(add-hook #'org-ai-after-chat-insertion-hook
          (lambda (what _)
            (when (and (eq what 'end)
                       (eq major-mode 'org-mode))
              (org-indent-indent-buffer))))

@tavisrudd
Copy link
Contributor

I've been using a similar hook, but with an additional check to see if org-indent-mode is active: #18 (comment). A more efficient approach would use (org-indent-refresh-maybe beg end _) which is intended to be called from things like after-change-functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants