karthink / gptel

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

Allow to run fill-paragraph on the inserted answer #188

Closed aburlot closed 5 months ago

aburlot commented 5 months ago

I would like to automatically run fill-paragraph or fill-region on the inserted answer in my org buffer. I think it should be done after (pulse-momentary-highlight-region p (point)) in gptel--insert-response. The post response hook seems to be a bit far to do it. Any idea how I could do this properly? I'm not very fluent in elisp, so I'm not sure how to do it.

BTW, many thanks for this awesome package. I really love it!

karthink commented 5 months ago

On Thu, Jan 18, 2024, 10:06 AM Alan @.***> wrote:

I would like to automatically run fill-paragraph or fill-region on the inserted answer in my org buffer. I think it should be done after (pulse-momentary-highlight-region p (point)) in gptel--insert-response. The post response hook seems to be a bit far to do it.

Nothing happens between the pulsing and the post response hook execution. Why do you believe it's too late?

(Also, are you using streaming responses? The hook will work either way but the behavior might be subtly different)

Any idea how I could do this properly? I'm not very fluent in elisp, so I'm not sure how to do it.

I'd add a function to gptel-post-response-functions, which see. There's an example in the wiki (link in the header on this page).

BTW, many thanks for this awesome package. I really love it!

Cheers, glad it's useful!

karthink commented 5 months ago

Dunno if this is what you're looking for:

(add-hook 'gptel-post-response-functions #'fill-region)
aburlot commented 5 months ago

Perfect! I added (gptel-post-response . fill-region) to use-package. That was simpler than I thought... Should have tried it before bothering you. Anyway, thank you for your help!