GNU bug report logs - #66993
[PATCH] project.el: avoid asking user about project-list-file lock

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Tue, 7 Nov 2023 21:29:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #38 received at 66993 <at> debbugs.gnu.org (full text, mbox):

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: Dmitry Gutov <dmitry <at> gutov.dev>
Cc: 66993 <at> debbugs.gnu.org
Subject: Re: bug#66993: [PATCH] project.el: avoid asking user about
 project-list-file lock
Date: Wed, 08 Nov 2023 10:06:27 -0500
Dmitry Gutov <dmitry <at> gutov.dev> writes:
> On 07/11/2023 23:28, Spencer Baugh wrote:
>> - project-mode-line will call this on mode-line update
>
> Hopefully this will never result in writes to disk made more often
> than once per user command, or buffer switch, etc.
>
>> -      (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))))))
>
> I wonder if all cl-letf uses like this will survive native
> compilation, for example. Or will break over time due to internal
> changes in the function.
>
> Anyway, maybe an implementation like this (totally untested)?
>
> Or the warning could be skipped entirely.
>
> diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
> index a6426c08840..e544dfefa73 100644
> --- a/lisp/progmodes/project.el
> +++ b/lisp/progmodes/project.el
> @@ -1719,7 +1719,9 @@ project--write-project-list
>                                  (expand-file-name name)))))
>                      project--list)
>              (current-buffer)))
> -      (write-region nil nil filename nil 'silent))))
> +      (let ((noninteractive t))
> +        (with-demoted-errors "Failed to save file list: %S"
> +          (write-region nil nil filename nil 'silent))))))
>
>  ;;;###autoload
>  (defun project-remember-project (pr &optional no-write)

Good idea using noninteractive.  I agree that should signal file-locked,
so we can handle it.  That seems like the most elegant solution.

However, interestingly, this actually seems to crash Emacs!  Not sure
why yet.

Reproduction:

1. Open ~/file and edit it without saving (so Emacs takes the lock)
2. in a separate emacs -Q, run with M-:
(let ((noninteractive t)) (write-region nil nil "~/file"))
3. Notice the separate emacs -Q immediately crashes!

This is really a separate bug, but since we're talking about
noninteractively handling lock conflicts, we might as well solve it here
- or decide if it really should be solved.




This bug report was last modified 1 year and 268 days ago.

Previous Next


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