Skip to content

Conversation

@jwiegley
Copy link
Contributor

@jwiegley jwiegley commented Oct 4, 2025

Fixes #893

Summary

The gptel-auto-scroll function was called from within save-excursion during streaming responses. When point was at the end of the buffer, scroll-up-command would fail, preventing the window from following streaming output.

Changes

This fix defers the scroll operation using run-at-time, allowing it to execute after save-excursion completes. The implementation also:

  • Captures the insertion position before deferring (avoiding stale point references)
  • Uses recenter -1 instead of scroll-up-command for more reliable positioning at window bottom
  • Passes window and position as explicit lambda parameters

Testing

The fix addresses the reproduction steps in #893:

  1. Enable auto scroll: (add-hook 'gptel-post-stream-hook 'gptel-auto-scroll)
  2. Move cursor to end of buffer
  3. Invoke gptel-send with text longer than viewport

Expected: Window scrolls to follow streaming text
Result: Window now correctly scrolls

Comparison to PR #894

This implementation improves on PR #894 by:

  • Capturing position before deferring (more robust)
  • Using recenter -1 for consistent bottom-of-window positioning
  • Passing parameters explicitly to the lambda (cleaner closure)
  • Enhanced documentation

🤖 Generated with Claude Code

Fixes karthink#893

The gptel-auto-scroll function was called from within save-excursion
during streaming responses. When point was at the end of the buffer,
scroll-up-command would fail, preventing the window from following
streaming output.

This fix defers the scroll operation using run-at-time, allowing it
to execute after save-excursion completes. The implementation also:
- Captures the insertion position before deferring
- Uses recenter instead of scroll-up-command for more reliable positioning
- Passes window and position as explicit lambda parameters

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant