Function: revert-buffer-insert-file-contents-delicately
revert-buffer-insert-file-contents-delicately is a byte-compiled
function defined in files.el.gz.
Signature
(revert-buffer-insert-file-contents-delicately FILE-NAME AUTO-SAVE-P)
Documentation
Optional function for revert-buffer-insert-file-contents-function.
The function revert-buffer-with-fine-grain uses this function by binding
revert-buffer-insert-file-contents-function to it.
As with revert-buffer-insert-file-contents--default-function, FILE-NAME is
the name of the file and AUTO-SAVE-P is non-nil if this is an auto-save file.
Since calling replace-region-contents can take a long time, depending of
the number of changes made to the buffer, it uses the value of the variable
revert-buffer-with-fine-grain-max-seconds as a maximum time to try delicately
reverting the buffer. If it fails, it does a delete+insert. For more details,
see replace-region-contents.
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun revert-buffer-insert-file-contents-delicately (file-name _auto-save-p)
"Optional function for `revert-buffer-insert-file-contents-function'.
The function `revert-buffer-with-fine-grain' uses this function by binding
`revert-buffer-insert-file-contents-function' to it.
As with `revert-buffer-insert-file-contents--default-function', FILE-NAME is
the name of the file and AUTO-SAVE-P is non-nil if this is an auto-save file.
Since calling `replace-region-contents' can take a long time, depending of
the number of changes made to the buffer, it uses the value of the variable
`revert-buffer-with-fine-grain-max-seconds' as a maximum time to try delicately
reverting the buffer. If it fails, it does a delete+insert. For more details,
see `replace-region-contents'."
(cond
((not (file-exists-p file-name))
(error (if buffer-file-number
"File %s no longer exists"
"Cannot revert nonexistent file %s")
file-name))
((not (file-readable-p file-name))
(error (if buffer-file-number
"File %s no longer readable"
"Cannot revert unreadable file %s")
file-name))
(t
(let* ((buf (current-buffer)) ; current-buffer is the buffer to revert.
(success
(save-excursion
(save-restriction
(widen)
(with-temp-buffer
(insert-file-contents file-name)
(let ((temp-buf (current-buffer)))
(set-buffer buf)
(let ((buffer-file-name nil))
(replace-region-contents
(point-min) (point-max)
temp-buf
revert-buffer-with-fine-grain-max-seconds))))))))
;; See comments in revert-buffer-with-fine-grain for an explanation.
(defun revert-buffer-with-fine-grain-success-p ()
success))
(set-buffer-modified-p nil)
(set-visited-file-modtime))))