Function: eca-chat--maybe-revert-changed-file

eca-chat--maybe-revert-changed-file is a natively compiled function defined in eca-chat.el.

Signature

(eca-chat--maybe-revert-changed-file CONTENT)

Documentation

Revert the buffer visiting the file changed by tool call CONTENT.

Only acts when eca-chat-auto-revert-changed-files is non-nil and CONTENT is a finished tool call (toolCalled) whose details are a fileChange. The buffer is reverted the way auto-revert-mode does it, and only when it has no unsaved changes and the file on disk changed since it was visited, so a preview or a failed edit leaves it alone. Errors are demoted so they never break chat rendering.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat.el
(defun eca-chat--maybe-revert-changed-file (content)
  "Revert the buffer visiting the file changed by tool call CONTENT.
Only acts when `eca-chat-auto-revert-changed-files' is non-nil and
CONTENT is a finished tool call (`toolCalled') whose details are a
fileChange.  The buffer is reverted the way `auto-revert-mode' does it,
and only when it has no unsaved changes and the file on disk changed
since it was visited, so a preview or a failed edit leaves it alone.
Errors are demoted so they never break chat rendering."
  (when (and eca-chat-auto-revert-changed-files
             (equal (plist-get content :type) "toolCalled"))
    (let ((details (plist-get content :details)))
      (when (equal (plist-get details :type) "fileChange")
        (with-demoted-errors "eca-chat auto revert: %S"
          (when-let* ((path (plist-get details :path))
                      (buffer (find-buffer-visiting
                               (eca--path-remote-to-local path)))
                      ((not (buffer-modified-p buffer)))
                      ((not (verify-visited-file-modtime buffer)))
                      ((file-exists-p (buffer-file-name buffer))))
            (with-current-buffer buffer
              (revert-buffer 'ignore-auto 'dont-ask 'preserve-modes))))))))