- 
                Notifications
    
You must be signed in to change notification settings  - Fork 329
 
Labels
bugSomething isn't workingSomething isn't working
Description
Please update gptel first -- errors are often fixed by the time they're reported.
- I have updated gptel to the latest commit and tested that the issue still exists
 
Bug Description
(add-hook 'gptel-post-stream-hook 'gptel-auto-scroll) doesn't work correctly for me when I'm inserting text at the end of a buffer. I think the issue is that scroll-up-command is called from within save-excursion, where point is potentially already at the end of the buffer, causing it to error out rather than scroll up.
The fix I found is to run scroll-up-command outside of the excursion using a delay:
(defun gptel-auto-scroll-fixed ()
  "Scroll window if LLM response continues below viewport."
  (when-let* ((win (get-buffer-window (current-buffer) 'visible))
              ((not (pos-visible-in-window-p (point) win)))
              (scroll-error-top-bottom t))
    (condition-case nil
        (with-selected-window win
          (run-at-time 0 nil #'scroll-up-command))
      (error nil))))
I'll put up a PR, but wanted to open this bug for discoverability.
Backend
None
Steps to Reproduce
- Enable auto scroll: 
(add-hook 'gptel-post-stream-hook 'gptel-auto-scroll) - Move cursor to end of buffer.
 - Invoke 
gptel-sendand have it generate text longer than the current buffer. 
Expected behavior: as inserted text goes past end of buffer, it scrolls up to follow along with the inserted text.
Actual behavior: it doesn't scroll, and text goes off the end of the page.
Additional Context
Emacs 27.2
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working