diff --git a/lisp/files.el b/lisp/files.el index ed18bc5841e..e8ecb351759 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6804,6 +6805,13 @@ revert-buffer-internal-hook ;; `preserve-modes' argument of `revert-buffer'. (defvar revert-buffer-preserve-modes) +(defvar-local revert-buffer-state-functions nil + "Functions to save and restore any state during `revert-buffer'. +This variable is a list of functions that are called before +reverting the buffer. These functions should return a lambda +that will be called after reverting the buffer +to restore a previous state saved in that lambda.") + (defun revert-buffer (&optional ignore-auto noconfirm preserve-modes) "Replace current buffer text with the text of the visited file on disk. This undoes all changes since the file was visited or saved. @@ -6854,13 +6862,16 @@ revert-buffer (let ((revert-buffer-in-progress-p t) (revert-buffer-preserve-modes preserve-modes) (state (and (boundp 'read-only-mode--state) - (list read-only-mode--state)))) + (list read-only-mode--state))) + (state-functions + (delq nil (mapcar #'funcall revert-buffer-state-functions)))) ;; Return whatever 'revert-buffer-function' returns. (prog1 (funcall (or revert-buffer-function #'revert-buffer--default) ignore-auto noconfirm) (when state (setq buffer-read-only (car state)) - (setq-local read-only-mode--state (car state)))))) + (setq-local read-only-mode--state (car state))) + (mapc #'funcall state-functions)))) (defun revert-buffer--default (ignore-auto noconfirm) "Default function for `revert-buffer'.