From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= Newsgroups: gmane.emacs.devel Subject: Re: Don't complain about changed file when it hasn't changed Date: Sun, 28 Aug 2016 23:36:23 -0400 Message-ID: <031d3e59-eaa3-df7a-492d-2a2d3c726094@gmail.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="htR0XSO9hM1wm9DQNiEkCAWTPkjDMfTLG" X-Trace: blaine.gmane.org 1472441845 9969 195.159.176.226 (29 Aug 2016 03:37:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Aug 2016 03:37:25 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 29 05:37:21 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1beDNw-0002CA-JE for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 05:37:20 +0200 Original-Received: from localhost ([::1]:41665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beDNu-0001IN-4V for ged-emacs-devel@m.gmane.org; Sun, 28 Aug 2016 23:37:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beDNI-0001I6-1Y for emacs-devel@gnu.org; Sun, 28 Aug 2016 23:36:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beDNC-0001ss-1N for emacs-devel@gnu.org; Sun, 28 Aug 2016 23:36:38 -0400 Original-Received: from mout.kundenserver.de ([217.72.192.73]:64832) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beDNB-0001so-N9 for emacs-devel@gnu.org; Sun, 28 Aug 2016 23:36:33 -0400 Original-Received: from [18.189.118.169] ([18.189.118.169]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0MFiib-1bsDSE00c1-00EdCi for ; Mon, 29 Aug 2016 05:36:31 +0200 In-Reply-To: X-Provags-ID: V03:K0:xEMuc32amzjjLCdk0ov5ixks2QjeQ9GpGYVCVshRyENVPTX6gcE srNnnwIpZdU+a2tPZg0Sov0nUnubqvUE6L64ez3fHPpTXZe3mP7eCYxmmbelGfWNTcXwCxM cX1KAx7Cjr4r9a+BmEdsTcp3KMXDvLivsiIq2Ghq0d0XarczZ0rVtDYYb+mTQJ2//Fg/HDE 3PcLv8G+1bFmUJMyoIvfA== X-UI-Out-Filterresults: notjunk:1;V01:K0:psfKC3JV0so=:fyEnz0u9r6aTGiAcPKnv3L kB3uhpFzGZ6rXmfmFJaTA8uS56SaVu37aGXXddsSowjvuXjuCh2PGYzQZyTzKr4uyRLKsxgZy XnjWNX1G0YDVFuPjnxuDJ6Ds7G1ljL6ohRW4cFhQAI5h1S0VSFQrSgZ/fATR7XidXyrKtXbN4 lGlLdELwCKBs3jU1At2T8ZYZYvmlExx1Hn1zTtzQ8yjJjBc4QmPbQyD+TvV6vM5nzO3M766DA ctWTpRC8izi9n0nzfiNmY3eyahYTg0bKEuHGsMny975Eus2wuiqYijvpl8O0XbFJVZ9hGiyrG GfanLuW9o+3uGFI9bMO2KAdhoFV5z3U2w1A8ITjARf1R35kyGpkWSRmQ8Do+T8wTYxOaywrtg e3jdCS2e402FuXqXZGtbFpQe/Jq3gOUSCW0UsosBqEcMxLUQG35j0Xewkz7MmNd4X+2Gt/kyS y6qmYY+EMDCfJCPqUT/NR6bqQVW6+Z9B+1oScTFgpPTtXpriijAzFydVWEUmUIxGuWJYQyhQ1 VUoWHnqY1WTBifL8hyVx4kH9zqOPoP0w2IXfFblEC8sxrUUp3BX52Rt7m3vua+brhZnuQjw+2 KSTl54Gbm2NumJb7NkUwto4SZbZATQrvJX9SAw5FHF4vQlQRUYeuRR7O5KIPnkuFB3oa2+pAY n9Kc1fYKt1+kJ3LZMyMfqlo3hu69IGnxP1KxyJ8TfomsyPhgX82f/F62i7ssyD5+dd6Q= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.72.192.73 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:206855 Archived-At: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --htR0XSO9hM1wm9DQNiEkCAWTPkjDMfTLG Content-Type: multipart/mixed; boundary="gpMfdec9GlRwHD0IbpOuItwgfdW4UK3uM"; protected-headers="v1" From: =?UTF-8?Q?Cl=c3=a9ment_Pit--Claudel?= To: emacs-devel@gnu.org Message-ID: <031d3e59-eaa3-df7a-492d-2a2d3c726094@gmail.com> Subject: Re: Don't complain about changed file when it hasn't changed References: In-Reply-To: --gpMfdec9GlRwHD0IbpOuItwgfdW4UK3uM Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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. >=20 > Any objection? This sounds like a neat feature! Are you sure you want (point-min) and (p= oint-max) rather than 1 and (buffer-size), though? Also, maybe this should be predicated on a test for small-enough files? F= or large-ish files, it could make things slow. Cl=E9ment. > 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 > =20 > (define-error 'file-supersession nil 'file-error) > =20 > +(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) > + (=3D 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 > =20 > 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 c= hanges.") > - (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))))) > =20 > (defun ask-user-about-supersession-help () > (with-output-to-temp-buffer "*Help*" >=20 >=20 --gpMfdec9GlRwHD0IbpOuItwgfdW4UK3uM-- --htR0XSO9hM1wm9DQNiEkCAWTPkjDMfTLG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXw629AAoJEPqg+cTm90wjrxkP/jyxqqWiiWKE1M0+MU8+JN9w jV+XDtBv3JXU11bTXULhogwGJwqPNUGLChNZnidm72AT35I+QyNdLOAR5kiEChcZ n7wCM0VSrzPFlT4LI7sVal0+8+KWahg0A94JCsSMLXb9nMXhGNgJwlrx7JXSwxsD qq9wptqmJFvDYM5NzfdFEyR8U33B2q1W4p5dyCzeXCxTU5OUdWNakSD/USNCWngI BncUhEizXvqmDOhHiLgecQo3xCd4RYX6QcIjPYsxMjNIj1Lp5YS367CZAfbgFwF3 xQJuI3JIqCL/Qnt462J2D+oc2ogvur3St5ny3ijIVMnUQ/kkEPyfU95mHxZqXW8G vbD8rcxGbwpm4l2DiJbje2zQ+xz/Z0+LR1GrPvmeE/xzARFJ//zaz08VwBMvAIHR gAdxVNhRRkf2eRJWlL3zCHhsDA7KGA5yOQEXR5InAzFfLPjXuPfDLgtGCEPsXHrv /ytA42mnULKEX6Det1YSpas37OL47yuxI+aVLydb9Cl3NCqFkiTEoH1h4BZYoS9Y gfJwl9qBcv7SMFsH6593n7SB6WotMJBSfn+t+NMxJi3qNLgNCqCtMXSUtVpp4Bp3 BWBXG8WRuL/QGdEQa+jWMd559V5NUupXOGny0CEeN32nnkTYAf5FM1cr9c6cTdUJ mu5Q85eNSSapE8s8Mdha =h5yR -----END PGP SIGNATURE----- --htR0XSO9hM1wm9DQNiEkCAWTPkjDMfTLG--