unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: dak@gnu.org, stefan@marxist.se, 18336@debbugs.gnu.org
Subject: bug#18336: 24.4.50; When editing externally changed file, Emacs asks too many questions
Date: Sat, 21 Mar 2020 21:13:59 -0400	[thread overview]
Message-ID: <87y2rtjinc.fsf@gmail.com> (raw)
In-Reply-To: <838skevbsn.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 05 Mar 2020 21:31:20 +0200")

[-- Attachment #1: Type: text/plain, Size: 408 bytes --]

tags 18336 + patch
quit

Eli Zaretskii <eliz@gnu.org> writes:
>> 
>> I'm not sure.  Why exactly are we calling lock_file from write_region?
>
> Because write-region can be called from an unmodified buffer, I
> suppose, and from a buffer whose buffer-file-name is not the same as
> the file being written to.

So maybe we could just check those conditions?  Here's a patch,
tentatively suggested for master.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1371 bytes --]

From ae6a82e1b10ce850731fbc7135611108cd2bd147 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sat, 21 Mar 2020 21:00:08 -0400
Subject: [PATCH] Avoid extra "changed on disk" prompt in save-buffer
 (Bug#18336)

* src/fileio.c (write_region): Only call lock_file is the buffer is
unmodified or writing to some file other than the buffer's file.  As
mentioned in lock_file's commentary, calling it for modified buffers
is redundant (this reasoning only applies when writing to the buffer's
file).
---
 src/fileio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/fileio.c b/src/fileio.c
index 482f88627a..323faa2e77 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -5123,7 +5123,12 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
     = choose_write_coding_system (start, end, filename,
                                  append, visit, lockname, &coding);
 
-  if (open_and_close_file && !auto_saving)
+  if (open_and_close_file && !auto_saving &&
+      /* Only call lock_file on unmodifed buffer (see lock_file
+         commentary).  */
+      (NILP (Fbuffer_modified_p (Qnil)) ||
+       /* Or if we're not writing to the buffer's file.  */
+       NILP (Fstring_equal (visit_file, BVAR (current_buffer, filename)))))
     {
       lock_file (lockname);
       file_locked = 1;
-- 
2.11.0


[-- Attachment #3: Type: text/plain, Size: 443 bytes --]


> Evidently, when we disabled backups in /tmp, we missed the fact that
> lock_file called from write-region will be affected.  When backups are
> not disabled, this works correctly.

To me, the fact that it works with backups enabled seems like an
accident.  The connection between locking and backups isn't very
obvious, and I don't see any commentary about it (which I would expect
for such a subtle interaction if it was done on purpose).

  reply	other threads:[~2020-03-22  1:13 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27  7:44 bug#18336: 24.4.50; When editing externally changed file, Emacs asks too many questions David Kastrup
2020-03-01  0:27 ` Stefan Kangas
2020-03-01 16:26   ` Noam Postavsky
2020-03-01 16:38     ` David Kastrup
2020-03-01 17:09       ` Eli Zaretskii
2020-03-01 17:45         ` David Kastrup
2020-03-01 17:58           ` Eli Zaretskii
2020-03-01 18:22             ` David Kastrup
2020-03-01 18:27               ` Eli Zaretskii
2020-03-02  4:14                 ` Noam Postavsky
2020-03-02  8:27                   ` Eli Zaretskii
2020-03-02  9:42                     ` David Kastrup
2020-03-02 11:04                       ` Eli Zaretskii
2020-03-02 11:41                         ` David Kastrup
2020-03-02 11:51                           ` Eli Zaretskii
2020-03-02  8:39                   ` Stefan Kangas
2020-03-02  8:55                     ` Eli Zaretskii
2020-03-02  9:04                       ` Stefan Kangas
2020-03-02 11:01                         ` Eli Zaretskii
2020-03-02  9:53                     ` David Kastrup
2020-03-02 12:20                       ` Noam Postavsky
2020-03-02 16:33                         ` Eli Zaretskii
2020-03-05 14:13                           ` Noam Postavsky
2020-03-05 15:07                             ` David Kastrup
2020-03-05 17:54                               ` Noam Postavsky
2020-03-05 19:31                                 ` Eli Zaretskii
2020-03-22  1:13                                   ` Noam Postavsky [this message]
2020-03-22 14:35                                     ` Eli Zaretskii
2020-03-22 15:45                                       ` Noam Postavsky
2020-03-22 17:09                                         ` Eli Zaretskii
2020-03-22 19:46                                           ` Noam Postavsky
2020-03-22 20:16                                             ` Eli Zaretskii
2020-03-23  3:26                                               ` Noam Postavsky
2020-03-05 16:02                             ` Eli Zaretskii

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=87y2rtjinc.fsf@gmail.com \
    --to=npostavs@gmail.com \
    --cc=18336@debbugs.gnu.org \
    --cc=dak@gnu.org \
    --cc=eliz@gnu.org \
    --cc=stefan@marxist.se \
    /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).