On 2016-08-28 20:29, Stefan Monnier wrote: > The patch below is supposed to change Emacs such that if the file's > timestamp has changed, but the contents is still the same, it doesn't > prompt the user about a supersession-threat. > > Any objection? This sounds like a neat feature! Are you sure you want (point-min) and (point-max) rather than 1 and (buffer-size), though? Also, maybe this should be predicated on a test for small-enough files? For large-ish files, it could make things slow. Clément. > diff --git a/lisp/userlock.el b/lisp/userlock.el > index a0c55fd..9b45ef4 100644 > --- a/lisp/userlock.el > +++ b/lisp/userlock.el > @@ -97,6 +97,20 @@ ask-user-about-lock-help > > (define-error 'file-supersession nil 'file-error) > > +(defun userlock--check-content-unchanged (fn) > + (save-restriction > + (widen) > + (let ((buf (current-buffer)) > + (start (point-min)) > + (end (point-max))) > + (when (with-temp-buffer > + (insert-file-contents fn) > + (= 0 (compare-buffer-substrings > + buf start end > + (current-buffer) (point-min) (point-max)))) > + (set-visited-file-modtime) > + 'unchanged)))) > + > ;;;###autoload > (defun ask-user-about-supersession-threat (fn) > "Ask a user who is about to modify an obsolete buffer what to do. > @@ -106,30 +120,30 @@ ask-user-about-supersession-threat > > You can rewrite this to use any criterion you like to choose which one to do. > The buffer in question is current when this function is called." > - (discard-input) > - (save-window-excursion > - (let ((prompt > - (format "%s changed on disk; \ > + (unless (userlock--check-content-unchanged fn) > + (discard-input) > + (save-window-excursion > + (let ((prompt > + (format "%s changed on disk; \ > really edit the buffer? (y, n, r or C-h) " > - (file-name-nondirectory fn))) > - (choices '(?y ?n ?r ?? ?\C-h)) > - answer) > - (while (null answer) > - (setq answer (read-char-choice prompt choices)) > - (cond ((memq answer '(?? ?\C-h)) > - (ask-user-about-supersession-help) > - (setq answer nil)) > - ((eq answer ?r) > - ;; Ask for confirmation if buffer modified > - (revert-buffer nil (not (buffer-modified-p))) > - (signal 'file-supersession > - (list "File reverted" fn))) > - ((eq answer ?n) > - (signal 'file-supersession > - (list "File changed on disk" fn))))) > - (message > - "File on disk now will become a backup file if you save these changes.") > - (setq buffer-backed-up nil)))) > + (file-name-nondirectory fn)))) > + (while > + (let ((answer (read-char-choice prompt '(?y ?n ?r ?? ?\C-h)))) > + (cond ((memq answer '(?? ?\C-h)) > + (ask-user-about-supersession-help) > + 'repeat) > + ((eq answer ?r) > + ;; Ask for confirmation if buffer modified > + (revert-buffer nil (not (buffer-modified-p))) > + (signal 'file-supersession > + (list "File reverted" fn))) > + ((eq answer ?n) > + (signal 'file-supersession > + (list "File changed on disk" fn))) > + (t (null answer))))) > + (message > + "File on disk now will become a backup file if you save these changes.") > + (setq buffer-backed-up nil))))) > > (defun ask-user-about-supersession-help () > (with-output-to-temp-buffer "*Help*" > >