]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new user option to exclude projects from being remembered
authorVisuwesh <visuweshm@gmail.com>
Mon, 3 Mar 2025 08:26:04 +0000 (13:56 +0530)
committerEshel Yaron <me@eshelyaron.com>
Sun, 9 Mar 2025 07:16:24 +0000 (08:16 +0100)
* lisp/progmodes/project.el (project-list-exclude): Add new user
option to exclude projects from being remembered.
(project-remember-project): Consider the user option above.
(project-switch-project): Use 'project-remember-project' instead.
* doc/emacs/maintaining.texi (Managing Projects): Mention the new user option.
* etc/NEWS: Announce the change.  (Bug#76587)

(cherry picked from commit 6aa60038ee999d25184a639ce0ac76b614e3afb6)

doc/emacs/maintaining.texi
lisp/progmodes/project.el

index 7d8f0c03edfcf2544ca32caefd01dd300792dee4..d69ca4df4e0f3e55d32fd6cb43008e2f9b259849 100644 (file)
@@ -2036,6 +2036,15 @@ the available projects.  @kbd{M-x project-forget-project}
 prompts you to choose one of the available projects, and then removes
 it from the file.
 
+@vindex project-list-exclude
+  The user option @code{project-list-exclude} may be set to always
+ignore certain projects from being remembered, and saved to
+@code{project-list-file}.  It is a list of regexps and predicates for
+project roots and objects.  The regexp specified is matched against the
+project root, and the predicate should take the project object as the
+only argument and should return non-@code{nil} if the project should not
+be saved to @code{project-list-file}.
+
 @node Change Log
 @section Change Logs
 
index 6c71320ae245593bc97e2f85bcf3e55108f53c03..6f6fba81c4cff975ec346298a1c56f2dbfbf6716 100644 (file)
@@ -1764,6 +1764,16 @@ Also see the `project-kill-buffers-display-buffer-list' variable."
   :version "28.1"
   :group 'project)
 
+(defcustom project-list-exclude nil
+  "Exclude projects from being remembered by `project-remember-project'.
+It should be a list of regexps and predicates for project roots and
+objects to always exclude from being remembered.  The predicate should
+take one argument, the project object, and should return non-nil if the
+project should not be remembered."
+  :type '(repeat (choice regexp function))
+  :version "31.1"
+  :group 'project)
+
 (defvar project--list 'unset
   "List structure containing root directories of known projects.
 With some possible metadata (to be decided).")
@@ -1834,9 +1844,16 @@ has changed, and NO-WRITE is nil."
 ;;;###autoload
 (defun project-remember-project (pr &optional no-write)
   "Add project PR to the front of the project list.
+If project PR satisfies `project-list-exclude', then nothing is done.
 Save the result in `project-list-file' if the list of projects
 has changed, and NO-WRITE is nil."
-  (project--remember-dir (project-root pr) no-write))
+  (let ((root (project-root pr)))
+    (unless (seq-some (lambda (r)
+                        (if (functionp r)
+                            (funcall r pr)
+                          (string-match-p r root)))
+                      project-list-exclude)
+      (project--remember-dir root no-write))))
 
 (defun project--remove-from-project-list (project-root report-message)
   "Remove directory PROJECT-ROOT of a missing project from the project list.
@@ -2109,7 +2126,7 @@ made from `project-switch-commands'.
 When called in a program, it will use the project corresponding
 to directory DIR."
   (interactive (list (funcall project-prompter)))
-  (project--remember-dir dir)
+  (project-remember-project (project-current nil dir))
   (let ((command (project--switch-project-command dir))
         (buffer (current-buffer)))
     (unwind-protect