unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Clément Pit--Claudel" <clement.pit@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Don't complain about changed file when it hasn't changed
Date: Sun, 28 Aug 2016 23:36:23 -0400	[thread overview]
Message-ID: <031d3e59-eaa3-df7a-492d-2a2d3c726094@gmail.com> (raw)
In-Reply-To: <jwvy43g2ze5.fsf-monnier+emacs@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 3788 bytes --]

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*"
> 
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-08-29  3:36 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29  0:29 Don't complain about changed file when it hasn't changed Stefan Monnier
2016-08-29  3:36 ` Clément Pit--Claudel [this message]
2016-08-29  3:39   ` Daniel Colascione
2016-08-29  3:43     ` Clément Pit--Claudel
2016-08-29  6:44       ` Michael Albinus
2016-08-29 14:42         ` Eli Zaretskii
2016-08-29 16:18           ` Michael Albinus
2016-08-29 17:42         ` Davis Herring
2016-08-29 17:57           ` Clément Pit--Claudel
2016-08-29 19:10             ` Davis Herring
2016-08-29 13:17   ` Stefan Monnier
2016-08-30  9:20     ` Michael Albinus
2016-08-30 15:00       ` Stefan Monnier
2016-08-30 13:40     ` Clément Pit--Claudel
2016-08-30 15:01       ` Stefan Monnier
2016-08-30 15:23         ` Clément Pit--Claudel
2016-08-30 15:48           ` Stefan Monnier
2016-08-30 16:55             ` Eli Zaretskii
2016-08-30 16:11           ` Eli Zaretskii
2016-08-30 16:38             ` Clément Pit--Claudel
2016-08-29 14:34 ` Eli Zaretskii
2016-08-29 14:50   ` Stefan Monnier
2016-08-30 15:26     ` Eli Zaretskii
2016-08-30 15:44       ` Stefan Monnier
2016-08-30 16:15         ` Eli Zaretskii
2016-08-30 17:13           ` Stefan Monnier
2016-08-30 17:26             ` Eli Zaretskii
2016-08-30 18:02               ` Stefan Monnier
2016-08-30 15:46       ` Stefan Monnier
2016-08-30 16:19         ` Eli Zaretskii
2016-08-30 17:16           ` Stefan Monnier
2016-08-30 17:32             ` Eli Zaretskii
2016-08-30 18:06               ` Stefan Monnier
2016-09-01 13:49                 ` Eli Zaretskii
2016-09-02 15:22                   ` Stefan Monnier
2016-09-02 15:26                     ` Eli Zaretskii
2016-09-02 15:44                       ` Stefan Monnier
2016-09-02 15:39                     ` Joost Kremers
2016-08-29 16:01   ` Stefan Monnier
2016-08-29 16:26     ` Eli Zaretskii
2016-08-30  0:35       ` Stefan Monnier
2016-08-29 17:50   ` Davis Herring
2016-08-29 18:09     ` Eli Zaretskii
2016-08-29 19:22       ` Davis Herring
2016-08-30  0:39       ` Stefan Monnier
2016-08-30  7:55         ` Andreas Schwab
2016-08-30  0:37     ` Stefan Monnier
2016-08-30  1:23   ` Rolf Ade
2016-08-30 15:12     ` Eli Zaretskii
2016-08-30 15:34       ` Clément Pit--Claudel
2016-08-30 16:14         ` Eli Zaretskii
2016-09-06 16:29 ` John Wiegley
2016-09-06 17:50   ` Stefan Monnier
2016-09-06 17:52     ` John Wiegley
2016-09-06 19:00       ` Andreas Röhler
2016-09-06 21:00         ` Stefan Monnier
2016-09-06 21:29           ` Drew Adams
2016-09-06 21:41     ` Karl Fogel
2016-09-06 21:59       ` Paul Eggert
2016-09-06 22:01         ` Karl Fogel
2016-09-06 22:07           ` Davis Herring
2016-09-06 22:21             ` Karl Fogel
2016-09-06 22:46               ` Clément Pit--Claudel
2016-09-07  0:24               ` Stefan Monnier
2016-09-07 16:49                 ` Karl Fogel
2016-09-07 18:41                   ` Andreas Röhler
2016-09-07 20:02                     ` Karl Fogel
2016-09-06 22:03         ` Karl Fogel
2016-12-24  1:03 ` Rolf Ade
2016-12-25 15:44   ` Stefan Monnier
2016-12-26  0:29     ` Rolf Ade

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=031d3e59-eaa3-df7a-492d-2a2d3c726094@gmail.com \
    --to=clement.pit@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).