Subject: Re: bug#47287: 28.0.50; [PATCH] Add command project-remove-known-project

From: Theodor Thornhill <[email-masked]>
Date: Mon, 22 Mar 2021 00:21:42 +0100

Hi,

>> Mainly since the message seems specialized, and I didnt want to alter existing, used behavior.
>
> Perhaps we can move the 'message' call from it to its current caller 
> (project-current).

See attached, improved patch, hopefully adressing Elis comments, and
using the already defined function. I did not yet add a manual entry.

Does this approach seem reasonable to you?

--
Theo

>From 45245b872982f50c2093fda0c797b6dad7d205ed Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Mon, 22 Mar 2021 00:19:23 +0100
Subject: [PATCH] Add command project-remove-known-project

* etc/NEWS: Mention the new command.

* lisp/progmodes/project.el (project--remove-from-project-list): Add
new argument, report-message, used to signal various messages when
removal has happened.

* lisp/progmodes/project.el (project-remove-known-project): New
command that removes the selected directory from the project-list-file.

* lisp/progmodes/project.el (project-current): Add the report message.
---
 etc/NEWS                  |  4 ++++
 lisp/progmodes/project.el | 18 ++++++++++++++----
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 49a4bb8106..abe7107f12 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1573,6 +1573,10 @@ project's root directory, respectively.
 +++
 *** New user option 'project-list-file'.
 
+*** New command 'project-remove-known-project'.
+This command lets you interactively remove an entry from the list of projects
+in 'project-list-file'
+
 ** xref
 
 ---
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index b6a886f731..b3d49c288e 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -201,7 +201,8 @@ of the project instance object."
     (when maybe-prompt
       (if pr
           (project-remember-project pr)
-        (project--remove-from-project-list directory)
+        (project--remove-from-project-list
+         directory "Project `%s' not found; removed from list")
         (setq pr (cons 'transient directory))))
     pr))
 
@@ -1217,17 +1218,26 @@ Save the result in `project-list-file' if the list of projects has changed."
       (push (list dir) project--list)
       (project--write-project-list))))
 
-(defun project--remove-from-project-list (pr-dir)
+(defun project--remove-from-project-list (pr-dir report-message)
   "Remove directory PR-DIR 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."
+from the list using REPORT-MESSAGE."
   (project--ensure-read-project-list)
   (when-let ((ent (assoc pr-dir project--list)))
     (setq project--list (delq ent project--list))
-    (message "Project `%s' not found; removed from list" pr-dir)
+    (message report-message pr-dir)
     (project--write-project-list)))
 
+;;;###autoload
+(defun project-remove-known-project (pr-dir)
+  "Remove directory PR-DIR from the project-list.
+PR-DIR is the root-directory of a known project listed in the
+project list."
+  (interactive (list (project-prompt-project-dir)))
+  (project--remove-from-project-list
+   dir "Project `%s' removed from known projects"))
+
 (defun project-prompt-project-dir ()
   "Prompt the user for a directory that is one of the known project roots.
 The project is chosen among projects known from the project list,
-- 
2.24.3 (Apple Git-128)