is it possible to disallow modification if there is an autosave version? I sometimes save a file only to find out that it has an autosave version but I am unable to recover because I saved.
One can derive how to detect existing autosave data from the part of
after-find-file that emits the message
"%s has auto save data; consider M-x recover-this-file".
find-file-hook if a buffer has autosave data.
(defun my-make-auto-saved-file-read-only () "Set the buffer read-only if it has a recent auto-save file." ;; Stolen from `after-find-file': (when (and ;; No need to warn if buffer is auto-saved ;; under the name of the visited file. (not (and buffer-file-name auto-save-visited-file-name)) (file-newer-than-file-p (or buffer-auto-save-file-name (make-auto-save-file-name)) buffer-file-name)) (read-only-mode))) (add-hook 'find-file-hook #'my-make-auto-saved-file-read-only)
Note, with this approach you must reset
read-only-mode yourself after reverting the file. But that is very simple in Emacs with GUI. Just click on the remaining
% in the mode line.