Skip to content

gptel-auto-scroll doesn't work at end of buffer #893

@JDNdeveloper

Description

@JDNdeveloper

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

  1. Enable auto scroll: (add-hook 'gptel-post-stream-hook 'gptel-auto-scroll)
  2. Move cursor to end of buffer.
  3. Invoke gptel-send and 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

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions