From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#66993: [PATCH] project.el: avoid asking user about project-list-file lock Date: Sat, 18 Nov 2023 15:48:33 +0000 (UTC) Message-ID: <87sf53m59w.fsf@catern.com> References: <83sf5g1lko.fsf@gnu.org> <9d460f36-6035-da54-3abc-12171ac8977f@gutov.dev> <83h6lw19zw.fsf@gnu.org> <894f674f-76ea-90af-3acc-73ca6e7caf35@gutov.dev> <834jhv1lfw.fsf@gnu.org> <83ttpvyxn0.fsf@gnu.org> <42fe7d0e-024c-3e0d-3bc5-b0e6ec50f260@gutov.dev> <83r0kzyo93.fsf@gnu.org> <4b4a190a-ec88-6f50-1f94-900b3afdfc41@gutov.dev> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18455"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Spencer Baugh , Eli Zaretskii , 66993@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 18 16:49:21 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 1r4NZQ-0004Za-Ao for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 18 Nov 2023 16:49:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r4NZA-0002pk-4x; Sat, 18 Nov 2023 10:49:04 -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 1r4NZ8-0002pU-M8 for bug-gnu-emacs@gnu.org; Sat, 18 Nov 2023 10:49:02 -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 1r4NZ7-0006ah-FF for bug-gnu-emacs@gnu.org; Sat, 18 Nov 2023 10:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r4NZ8-0003ud-AJ for bug-gnu-emacs@gnu.org; Sat, 18 Nov 2023 10:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 18 Nov 2023 15:49: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.170032252514998 (code B ref 66993); Sat, 18 Nov 2023 15:49:02 +0000 Original-Received: (at 66993) by debbugs.gnu.org; 18 Nov 2023 15:48:45 +0000 Original-Received: from localhost ([127.0.0.1]:49322 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4NYq-0003tn-2d for submit@debbugs.gnu.org; Sat, 18 Nov 2023 10:48:44 -0500 Original-Received: from s.wfbtzhsw.outbound-mail.sendgrid.net ([159.183.224.105]:36772) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r4NYn-0003sv-2C for 66993@debbugs.gnu.org; Sat, 18 Nov 2023 10:48:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: cc:content-type:from:subject:to; s=s1; bh=RQp8bW4Yw5o8tUKiCETaG/I6Lng1yVPbeVg8+LTjYmM=; b=jjCkL7tFYvQ3I4LdIoHwL9UfHteQ+Xxylk2cZCXnzwVd90tTF0lhgSs+njRLhV7oXKa0 Zx+2/vGzgLE+0VI0AcVvZo5rMRMelTABRqjJ7von+NSfG1xKSYtQ8Ztd/M52mZKKG9q5SA LXOjnWdCXpvow5HNjN1iJnX9cTKKct3eoCRGO/ZXT4aiErL0WjNcCObhv9xlM8RptvriGO 8NqwSBJCvyj7nWbcjCX1o3KvSHo/3C/K3gdpCHDRY5kmeoxbG2aOngmb2rmg4jhl6ZHb3v /QNE1lPLN7uamFbZ0Yxch8y9Nt9ByPbz7kzJJ1Me1fdbEV+spz/BFflFMwlfJr2w== Original-Received: by filterdrecv-b85775b64-8p4fq with SMTP id filterdrecv-b85775b64-8p4fq-1-6558DCD1-9 2023-11-18 15:48:33.148405207 +0000 UTC m=+2754446.778438054 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-20 (SG) with ESMTP id KaNLh6h6Tra_ifb0J8XDGg Sat, 18 Nov 2023 15:48:32.849 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=74.101.51.129; helo=localhost; envelope-from=sbaugh@catern.com; receiver=gutov.dev Original-Received: from localhost (unknown [74.101.51.129]) by earth.catern.com (Postfix) with ESMTPSA id A18C262DFF; Sat, 18 Nov 2023 15:48:27 +0000 (UTC) In-Reply-To: <4b4a190a-ec88-6f50-1f94-900b3afdfc41@gutov.dev> (Dmitry Gutov's message of "Sat, 18 Nov 2023 03:41:04 +0200") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbKRuLH+31s7YlP04u/QQOPdR6tA4bZM2fgLzIwY2HnwRy46hxBCepMdUmzvu7uyA69bF9/rhcRJuZwQWzUZQkHuqv7YSXz65fS+yPfxQqfxgDZznmlmNQOVUw2Irq0h+RfVbHhGq7u+Vey31zuEVNoKpJNiPoCGTRpr5KkaYica5w== X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== 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:274555 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Dmitry Gutov writes: > On 15/11/2023 22:49, Spencer Baugh wrote: >> project--list is the new history variable. Using it is mostly trivial; >> a small bit of work is necessary in project-prompt-project-name to get >> project-names for the history, but that worked out great. Everything >> else just seems to work. >> And with savehist-mode enabled, project--list just gets stored >> automatically without any code in project.el. >> I can implement a backwards-compatible version if this seems like a >> reasonable direction to go in. > > I haven't tried using it, but there's indeed a lot to like about this patch. > > What happens if savehist-mode is nil, though? Which it is by > default. For users with this setup the project history will just > disappear. Indeed. > What kind of backward compatibility did you have in mind? I was thinking about either keeping our code for saving to project-list-file around in some obsoleted form, or using a subset of the savehist code to save only project--list when it's not otherwise enabled. But actually, maybe it's time that we just enable savehist by default. I'll try that first - I mailed emacs-devel about it. Then we could delete our project-list-file code once project.el eventually starts requiring Emacs 30. Regardless, how about the below patch which changes the default behavior to only write project-list-file when Emacs exits? I think this is a useful first step no matter what else we do, since it matches the behavior of savehist better. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Only-save-project-list-file-on-exit-by-default.patch >From 1e2ca2abf98f2589db384dc56e68ed4b8e73f1a3 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 18 Nov 2023 15:43:44 +0000 Subject: [PATCH] Only save project-list-file on exit by default. Saving on most project commands can cause conflicts between Emacs instances. Saving on exit only is more reliable, and it matches the behavior of savehist better, which we might use eventually instead of our own code. To allow opting in to the old behavior, add a new defcustom project-list-file-save defaulting to on-exit. * lisp/progmodes/project.el (project-list-file-save) (project--project-list-changed, project--kill-emacs-hook): Add. (bug#66993) (kill-emacs-hook): Call project--kill-emacs-hook. (project-remember-project, project--remove-from-project-list) (project-remember-projects-under, project-forget-projects-under): Call project--project-list-changed. --- etc/NEWS | 5 +++++ lisp/progmodes/project.el | 45 +++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 8324eb7da1e..bbb27183e96 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1062,6 +1062,11 @@ the current project. The look of the key prompt in the project switcher has been changed slightly. To get the previous one, set this option to 'brackets'. +*** New user option 'project-list-file-save', defaulting to on-exit. +By default, 'project-list-file' is now only saved on exit. To get the +old behavior of saving whenever the project list changed, set this +option to 'on-change' or 'on-change-and-exit'. + *** 'project-try-vc' tries harder to find the responsible VCS. When 'project-vc-extra-root-markers' is non-nil, and causes subdirectory project to be detected which is not a VCS root, we now diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 0855f76aa13..da2cec6abb2 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -1713,6 +1713,21 @@ project--ensure-read-project-list (when (eq project--list 'unset) (project--read-project-list))) +(defcustom project-list-file-save 'on-exit + "When to save `project-list-file'. + +If non-nil, the list of known projects is saved in +`project-list-file'. + +If set to `on-change', the list is saved every time it changes. +If set to `on-exit', the list is saved when Emacs exits. If set +to `on-change-and-exit', the list is saved in both cases." + :type '(choice (const :tag "Save on change" on-change) + (const :tag "Save when exiting" on-exit) + (const :tag "Save on change and when exiting" on-change-and-exit)) + :group 'project + :version "30.1") + (defun project--write-project-list () "Save `project--list' in `project-list-file'." (let ((filename project-list-file)) @@ -1728,11 +1743,22 @@ project--write-project-list (current-buffer))) (write-region nil nil filename nil 'silent)))) +(defun project--project-list-changed () + (when (memq project-list-file-save '(on-change on-change-and-exit)) + (project--write-project-list))) + +(defun project--kill-emacs-hook () + (when (memq project-list-file-save '(on-exit on-change-and-exit)) + (project--write-project-list))) + +(add-hook 'kill-emacs-hook #'project--kill-emacs-hook) + ;;;###autoload (defun project-remember-project (pr &optional no-write) "Add project PR to the front of the project list. Save the result in `project-list-file' if the list of projects -has changed, and NO-WRITE is nil." +has changed, `project-list-file-save' is configured to save on +change, and NO-WRITE is nil." (project--ensure-read-project-list) (let ((dir (abbreviate-file-name (project-root pr)))) (unless (equal (caar project--list) dir) @@ -1741,19 +1767,20 @@ project-remember-project (setq project--list (delq ent project--list)))) (push (list dir) project--list) (unless no-write - (project--write-project-list))))) + (project--project-list-changed))))) (defun project--remove-from-project-list (project-root report-message) "Remove directory PROJECT-ROOT of a missing project from the project list. -If the directory was in the list before the removal, save the -result in `project-list-file'. Announce the project's removal -from the list using REPORT-MESSAGE, which is a format string -passed to `message' as its first argument." +If the directory was in the list before the removal and +`project-list-file-save' is configured to save on change, save +the result in `project-list-file'. Announce the project's +removal from the list using REPORT-MESSAGE, which is a format +string passed to `message' as its first argument." (project--ensure-read-project-list) (when-let ((ent (assoc (abbreviate-file-name project-root) project--list))) (setq project--list (delq ent project--list)) (message report-message project-root) - (project--write-project-list))) + (project--project-list-changed))) ;;;###autoload (defun project-forget-project (project-root) @@ -1892,7 +1919,7 @@ project-remember-projects-under (setq count (1+ count)))) (if (zerop count) (message "No projects were found") - (project--write-project-list) + (project--project-list-changed) (message "%d project%s were found" count (if (= count 1) "" "s"))) count)) @@ -1923,7 +1950,7 @@ project-forget-projects-under (setq count (1+ count))))) (if (zerop count) (message "No projects were forgotten") - (project--write-project-list) + (project--project-list-changed) (message "%d project%s were forgotten" count (if (= count 1) "" "s"))) count)) -- 2.42.1 --=-=-=--