Download
(defgroup disk nil
"Simplified find-file, revert-file, save-buffer interface."
:group 'convenience)
(defcustom disk-find-file-function 'find-file
"Function to use for visiting files."
:type 'function
:group 'disk)
(defvar disk-access nil)
(make-variable-buffer-local 'disk-access)
(add-hook 'find-file-hooks 'disk-notice)
(add-hook 'after-save-hook 'disk-notice)
(defun disk-file-modification-time ()
"Return modification time of the visited file."
(nth 5 (file-attributes (buffer-file-name))))
(defun disk-notice ()
"Store access time in `disk-acess'."
(setq disk-access (disk-file-modification-time)))
(defun disk-file-modified-p ()
"Return non-nil if the visited file has been modified."
(not (equal disk-access
(disk-file-modification-time))))
(defun disk ()
"Do the right thing with files.
If the buffer has no file, find a file. If the buffer needs saving, and
the file is unchanged, save the buffer. If the buffer needs saving, and
the file has changed, warn the user. If the buffer is unchanged, and
the file has changed, revert the buffer. Else do nothing."
(interactive)
(cond ((not (buffer-file-name))
(call-interactively disk-find-file-function))
((and (buffer-modified-p)
(not (disk-file-modified-p)))
(save-buffer))
((and (buffer-modified-p)
(disk-file-modified-p))
(error "Buffer must be saved, but the file has also changed."))
((and (not (buffer-modified-p))
(disk-file-modified-p))
(revert-buffer t t))
(t
(message "Nothing to do"))))
(save-excursion
(dolist (buf (buffer-list))
(set-buffer buf)
(when (buffer-file-name)
(disk-notice))))
(provide 'disk)