GNU bug report logs - #18336
24.4.50; When editing externally changed file, Emacs asks too many questions

Previous Next

Package: emacs;

Reported by: David Kastrup <dak <at> gnu.org>

Date: Wed, 27 Aug 2014 08:19:01 UTC

Severity: minor

Tags: fixed, patch

Found in version 24.4.50

Fixed in version 28.1

Done: Noam Postavsky <npostavs <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Noam Postavsky <npostavs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: dak <at> gnu.org, stefan <at> marxist.se, 18336 <at> debbugs.gnu.org
Subject: bug#18336: 24.4.50; When editing externally changed file, Emacs asks too many questions
Date: Sun, 22 Mar 2020 15:46:33 -0400
[Message part 1 (text/plain, inline)]
Eli Zaretskii <eliz <at> gnu.org> writes:

>> > Isn't it better to check whether the file is already locked?  That
>> > way, we don't need any (error-prone) heuristics for when it's okay to
>> > ask the question and when it isn't.
>> 
>> If I understand the code correctly, lock_file() already checks this (the
>> '&& !NILP (Ffile_exists_p (fn))' part), but takes the wrong action in
>> that case.  So I'm not sure what we should do differently.
>
> AFAIU, 'fn' in lock_file is the file we want to lock, not the file we
> create to indicate the lock.  Am I missing something?

Oh, you're right, I was confused.  The patch below seems to work.

[0001-Avoid-extra-changed-on-disk-prompt-in-save-buffer-Bu.patch (text/x-diff, inline)]
From 036eb17510ab63ce62aa858c9ff825b2ec5b5c7a Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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/filelock.c (lock_file): Don't query the user if the current
session already owns the lock.
---
 src/filelock.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/filelock.c b/src/filelock.c
index b28f16e9b5..5e14731ee8 100644
--- a/src/filelock.c
+++ b/src/filelock.c
@@ -679,6 +679,9 @@ lock_file (Lisp_Object fn)
   dostounix_filename (SSDATA (fn));
 #endif
   encoded_fn = ENCODE_FILE (fn);
+  if (create_lockfiles)
+    /* Create the name of the lock-file for file fn */
+    MAKE_LOCK_NAME (lfname, encoded_fn);
 
   /* See if this file is visited and has changed on disk since it was
      visited.  */
@@ -689,7 +692,8 @@ lock_file (Lisp_Object fn)
 
     if (!NILP (subject_buf)
 	&& NILP (Fverify_visited_file_modtime (subject_buf))
-	&& !NILP (Ffile_exists_p (fn)))
+        && !NILP (Ffile_exists_p (fn))
+        && (!create_lockfiles || current_lock_owner (NULL, lfname) != -2))
       call1 (intern ("userlock--ask-user-about-supersession-threat"), fn);
 
   }
@@ -697,10 +701,6 @@ lock_file (Lisp_Object fn)
   /* Don't do locking if the user has opted out.  */
   if (create_lockfiles)
     {
-
-      /* Create the name of the lock-file for file fn */
-      MAKE_LOCK_NAME (lfname, encoded_fn);
-
       /* Try to lock the lock.  FIXME: This ignores errors when
 	 lock_if_free returns a positive errno value.  */
       if (lock_if_free (&lock_info, lfname) < 0)
-- 
2.11.0


This bug report was last modified 5 years and 120 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.