Function: sops--revert-buffer
sops--revert-buffer is a natively compiled function defined in
sops.el.
Signature
(sops--revert-buffer &rest ARGS)
Documentation
Revert function for sops-mode buffers: re-read encrypted file and decrypt.
Widens before erasing so a narrowed buffer doesn't corrupt itself with
mixed encrypted + plaintext content (parallels the narrowing defense
in sops--encrypt-and-write).
Refreshes visited-file-modtime BEFORE erase-buffer. Two reasons:
1. After the revert, verify-visited-file-modtime must return t
so the next keystroke doesn't re-fire the "FILE has changed on
disk" prompt.
2. erase-buffer triggers Emacs's lock-file path which calls
ask-user-about-supersession-threat if the modtime is stale.
In batch mode that errors out ("Cannot resolve conflict in
batch mode"); interactively it would re-fire the supersession
prompt mid-revert. Updating the recorded modtime first
suppresses the check because the buffer now "agrees" with disk.
Source Code
;; Defined in /nix/store/vihl6lkzddv9xrsrsznvqdjq27g2i30p-emacs-packages-deps/share/emacs/site-lisp/elpa/sops-20260920.2121/sops.el
(defun sops--revert-buffer (&rest _args)
"Revert function for sops-mode buffers: re-read encrypted file and decrypt.
Widens before erasing so a narrowed buffer doesn't corrupt itself with
mixed encrypted + plaintext content (parallels the narrowing defense
in `sops--encrypt-and-write').
Refreshes `visited-file-modtime' BEFORE `erase-buffer'. Two reasons:
1. After the revert, `verify-visited-file-modtime' must return t
so the next keystroke doesn't re-fire the \"FILE has changed on
disk\" prompt.
2. `erase-buffer' triggers Emacs's `lock-file' path which calls
`ask-user-about-supersession-threat' if the modtime is stale.
In batch mode that errors out (\"Cannot resolve conflict in
batch mode\"); interactively it would re-fire the supersession
prompt mid-revert. Updating the recorded modtime first
suppresses the check because the buffer now \"agrees\" with disk."
(save-restriction
(widen)
(set-visited-file-modtime)
(let ((inhibit-read-only t))
(erase-buffer)
(insert-file-contents buffer-file-name)))
(when (sops--decrypt-buffer)
(setq sops-mode t)
(setq sops--state (sops-state-create :status 'decrypted))
(sops--restore-after-major-mode-change))
(set-buffer-modified-p nil))