Function: eca-chat--with-preserved-scroll

eca-chat--with-preserved-scroll is a macro defined in eca-chat-expandable.el.

Signature

(eca-chat--with-preserved-scroll &rest BODY)

Documentation

Execute BODY preserving scroll position of all windows showing this buffer.

Saves window-start for every window displaying the current buffer before BODY runs, then restores it afterwards. This prevents the visible content from jumping when buffer text is inserted or deleted
(e.g. when an expandable block is toggled).

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat-expandable.el
(defmacro eca-chat--with-preserved-scroll (&rest body)
  "Execute BODY preserving scroll position of all windows showing this buffer.
Saves `window-start' for every window displaying the current buffer
before BODY runs, then restores it afterwards.  This prevents the
visible content from jumping when buffer text is inserted or deleted
\(e.g. when an expandable block is toggled)."
  (declare (indent 0) (debug t))
  (let ((saved (gensym "saved-wins-")))
    `(let ((,saved (mapcar (lambda (w) (cons w (window-start w)))
                           (get-buffer-window-list (current-buffer) nil t))))
       (prog1 (progn ,@body)
         (dolist (entry ,saved)
           (let ((win (car entry))
                 (start (cdr entry)))
             (when (window-live-p win)
               (set-window-start win (min start (point-max)) t))))))))