karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.03k stars 111 forks source link

Auto Fill mode should be respected #302

Closed sacredirritant closed 1 month ago

sacredirritant commented 1 month ago

It would be nice if the response insertion behaved the same as ordinary interactive insertion so that inserting a space at a column beyond current-fill-column automatically breaks the line at a previous space when Auto Fill mode is enabled. Long lines in the response are currently inserted as-is.

karthink commented 1 month ago

I don't think this is possible, auto-fill only works when running self-insert with space. So it doesn't work in gptel for the same reason that it doesn't work when you yank text.

You can fill text in gptel's post-response hook:

(add-hook 'gptel-post-response-functions 'fill-region)

Or, conditioned on auto-fill-mode,

(add-hook 'gptel-post-response-functions
          (lambda (beg end)
            (when auto-fill-function
              (fill-region beg end))))
sacredirritant commented 1 month ago

I see, thank you for the work around.

karthink commented 1 month ago

Due to the way text properties are handled by gptel, you may get errors with some LLMs when continuing a conversation after filling text. If you get errors as a result of filling text please reopen this issue.

willbush commented 1 month ago

Thought this was working pretty well at first, but then noticed it messes up source block formatting.

(add-hook 'gptel-post-response-functions
          (lambda (beg end)
            (when auto-fill-function
              (fill-region beg end))))

I ended up just going with soft-wrapping (add-hook 'gptel-mode-hook #'visual-line-mode)