karthink / gptel

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

How to make `*ChatGPT*` buffer auto scroll when the buffer is growing? #92

Closed eval-exec closed 7 months ago

eval-exec commented 12 months ago

image

For above example: when I ask ChatGPT a question, and the question is near the mode-line, then the buffer is growing, I have to scroll up to see the answer.

How can I make this buffer auto scroll up when the buffer is growing? I tried auto-revert-tail-mode, but it give me "This buffer is not a file".

karthink commented 11 months ago

This feature will break asynchronous behavior -- gptel will not move point or mess with the window in any way.

I added gptel-pre-response-hook (latest commit) where you can manipulate the buffer/window as required. For instance you can now do

(add-hook 'gptel-pre-response-hook #'recenter)

to recenter the window before the response is inserted. If you want more fine-grained control, you can write a custom hook function. For example, you could move the query to the top of the window:

(defun gptel--recenter ()
  "Move point to top of window"
  (set-window-start nil (point)))

(add-hook 'gptel-pre-response-hook #'gptel--recenter)

You could also add to gptel-post-response-hook instead, which will update the window after the response has been inserted.

karthink commented 6 months ago

Update: I added auto-scrolling, see the README. Note that this moves the cursor too, not just the window view.