From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#66993: [PATCH] project.el: avoid asking user about project-list-file lock Date: Wed, 08 Nov 2023 10:06:27 -0500 Message-ID: References: <7089f7f2-3000-75fe-768a-dd12d979d81c@gutov.dev> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36214"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 66993@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 08 16:07:41 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r0k9c-0009BD-Ld for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 08 Nov 2023 16:07:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0k9N-0007ow-MQ; Wed, 08 Nov 2023 10:07:25 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r0k9M-0007oR-8j for bug-gnu-emacs@gnu.org; Wed, 08 Nov 2023 10:07:24 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r0k9M-0005fd-0x for bug-gnu-emacs@gnu.org; Wed, 08 Nov 2023 10:07:24 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r0k9y-0003aa-AD for bug-gnu-emacs@gnu.org; Wed, 08 Nov 2023 10:08:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 08 Nov 2023 15:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66993 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 66993-submit@debbugs.gnu.org id=B66993.169945603413738 (code B ref 66993); Wed, 08 Nov 2023 15:08:02 +0000 Original-Received: (at 66993) by debbugs.gnu.org; 8 Nov 2023 15:07:14 +0000 Original-Received: from localhost ([127.0.0.1]:46118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0k9B-0003ZV-SX for submit@debbugs.gnu.org; Wed, 08 Nov 2023 10:07:14 -0500 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]:37217) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r0k9A-0003ZJ-9E for 66993@debbugs.gnu.org; Wed, 08 Nov 2023 10:07:12 -0500 In-Reply-To: <7089f7f2-3000-75fe-768a-dd12d979d81c@gutov.dev> (Dmitry Gutov's message of "Wed, 8 Nov 2023 02:24:13 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:273991 Archived-At: Dmitry Gutov 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.