Function: eca-chat--with-point-preserved

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

Signature

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

Documentation

Run BODY, restoring point afterwards unless BODY moved it on purpose.

Rendering inserts text wherever the content goes, dragging point along, and streaming must not move the cursor. Helpers that move point deliberately set eca-chat--keep-point to keep the new position: a plain save-excursion would undo it whenever the chat window is the selected one.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defmacro eca-chat--with-point-preserved (&rest body)
  "Run BODY, restoring point afterwards unless BODY moved it on purpose.
Rendering inserts text wherever the content goes, dragging point
along, and streaming must not move the cursor.  Helpers that move
point deliberately set `eca-chat--keep-point' to keep the new
position: a plain `save-excursion' would undo it whenever the chat
window is the selected one."
  (declare (indent 0) (debug t))
  (let ((saved (gensym "saved-point-")))
    `(let ((eca-chat--keep-point nil)
           (,saved (point-marker)))
       (unwind-protect (progn ,@body)
         (when (and (not eca-chat--keep-point)
                    (eq (marker-buffer ,saved) (current-buffer)))
           (goto-char ,saved))
         (set-marker ,saved nil)))))