unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#66993: [PATCH] project.el: avoid asking user about project-list-file lock
@ 2023-11-07 21:28 Spencer Baugh
  2023-11-08  0:24 ` Dmitry Gutov
                   ` (3 more replies)
  0 siblings, 4 replies; 55+ messages in thread
From: Spencer Baugh @ 2023-11-07 21:28 UTC (permalink / raw)
  To: 66993

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

Tags: patch


This fixes a periodic issue that happens with multiple Emacs instances
and project.el.

Maybe this isn't the right way to change the behavior of
ask-user-about-lock though; possibly we should add some new defcustom to
customize it.  Happy to do that if that's preferred.


In GNU Emacs 29.1.50 (build 15, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2023-10-25 built on
 igm-qws-u22796a
Repository revision: 5cbca757f620c7b4ca31776711a247b8f266c36e
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.8 (Green Obsidian)

Configured using:
 'configure --config-cache --with-x-toolkit=lucid
 --with-gif=ifavailable'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-project.el-avoid-asking-user-about-project-list-file.patch --]
[-- Type: text/patch, Size: 2573 bytes --]

From ec6caaf9fcb913847278f7183e46d3026c6986fb Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
Date: Tue, 7 Nov 2023 16:24:26 -0500
Subject: [PATCH] project.el: avoid asking user about project-list-file lock

There are several features which will cause Emacs to frequently call
project-current, and therefore call project-remember-project, and
therefore sometimes call project--write-project-list whenever a new
project is seen.

- project-uniquify-dirname-transform will call this for each new
  buffer

- project-mode-line will call this on mode-line update

- My own private project-watch will call this based on file-notify
  events.

If a user has multiple Emacs instances open using one or more of these
features, it's fairly easy for both of the Emacs instances to see a
new project at the same time.  In that case, they'll both call
project--write-project-list at the same time, which will clash and run
ask-user-about-lock.  This will happen frequently if the user is often
looking at new projects.

There's no correct answer the user can give to ask-user-about-lock:
either way, one of the Emacs instances will have its project-list-file
update lost.  So let's not even bother prompting the user: just do
nothing if project-list-file is currently locked.

In the long run, the update doesn't actually get lost, because the
Emacs instance will probably make the same project-list-file update
again a few seconds later due to a later call to project-current.  So
this doesn't lose anything.

* lisp/progmodes/project.el (project--write-project-list): No-op if
the file is locked.
---
 lisp/progmodes/project.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 43c78f8b16b..78aaa75de5f 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1719,7 +1719,13 @@ project--write-project-list
                                 (expand-file-name name)))))
                     project--list)
             (current-buffer)))
-      (write-region nil nil filename nil 'silent))))
+      ;; If project-list-file is locked by some other Emacs, fail to
+      ;; write rather than prompting the user.
+      (ignore-error file-locked
+        (cl-letf (((symbol-function 'ask-user-about-lock)
+                   (lambda (file opponent)
+                     (signal 'file-locked (list file opponent)))))
+          (write-region nil nil filename nil 'silent))))))
 
 ;;;###autoload
 (defun project-remember-project (pr &optional no-write)
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2023-11-20 11:57 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-07 21:28 bug#66993: [PATCH] project.el: avoid asking user about project-list-file lock Spencer Baugh
2023-11-08  0:24 ` Dmitry Gutov
2023-11-08 12:29   ` Eli Zaretskii
2023-11-08 13:20     ` Dmitry Gutov
2023-11-08 15:06   ` Spencer Baugh
2023-11-08  7:46 ` Michael Albinus
2023-11-08 14:52   ` Spencer Baugh
2023-11-08 15:44     ` Michael Albinus
2023-11-08 16:35       ` Eli Zaretskii
2023-11-08 12:22 ` Eli Zaretskii
2023-11-08 13:26   ` Dmitry Gutov
2023-11-08 13:50     ` Eli Zaretskii
2023-11-08 13:56       ` Dmitry Gutov
2023-11-08 15:31         ` Eli Zaretskii
2023-11-08 15:41           ` Spencer Baugh
2023-11-08 16:35             ` Eli Zaretskii
2023-11-08 17:05               ` Spencer Baugh
2023-11-08 17:43                 ` Eli Zaretskii
2023-11-08 20:43                   ` Spencer Baugh
2023-11-09  6:32                     ` Eli Zaretskii
2023-11-09 16:38                       ` Spencer Baugh
2023-11-09 16:52                         ` Eli Zaretskii
2023-11-09 18:01                           ` Spencer Baugh
2023-11-09 19:46                             ` Eli Zaretskii
2023-11-10 12:48                               ` Spencer Baugh
2023-11-15 13:38                                 ` Eli Zaretskii
2023-11-08 15:36     ` Spencer Baugh
2023-11-08 16:32       ` Eli Zaretskii
2023-11-08 21:04         ` Dmitry Gutov
2023-11-09  6:37           ` Eli Zaretskii
2023-11-09 11:05             ` Dmitry Gutov
2023-11-09 11:27               ` Eli Zaretskii
2023-11-09 11:33                 ` Dmitry Gutov
2023-11-09 14:50                   ` Eli Zaretskii
2023-11-15 15:40                     ` Spencer Baugh
2023-11-15 20:49                       ` Spencer Baugh
2023-11-18  1:41                         ` Dmitry Gutov
2023-11-18 15:48                           ` sbaugh
2023-11-18 15:56                             ` sbaugh
2023-11-18 16:26                             ` Eli Zaretskii
2023-11-18 23:10                               ` Spencer Baugh
2023-11-19  6:05                                 ` Eli Zaretskii
2023-11-19 14:54                                   ` Spencer Baugh
2023-11-19 14:31                               ` Dmitry Gutov
2023-11-19 15:23                                 ` Eli Zaretskii
2023-11-20  2:05                                   ` Dmitry Gutov
2023-11-20 11:57                                     ` Eli Zaretskii
2023-11-19 14:33                             ` Dmitry Gutov
2023-11-19 17:52                             ` Juri Linkov
2023-11-19 19:38                               ` Spencer Baugh
2023-11-20  1:19                                 ` Dmitry Gutov
2023-11-08 21:03       ` Dmitry Gutov
2023-11-08 13:58 ` Dmitry Gutov
2023-11-08 15:25   ` Spencer Baugh
2023-11-08 21:14     ` Dmitry Gutov

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).