Add new user option to exclude projects from being remembered

* 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)
This commit is contained in:
Visuwesh 2025-03-03 13:56:04 +05:30 committed by Dmitry Gutov
parent 4b5cc0bfc6
commit 6aa60038ee
3 changed files with 35 additions and 2 deletions

View file

@ -2041,6 +2041,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

View file

@ -336,6 +336,13 @@ It can be used when switching between projects with similar file trees
(such as Git worktrees of the same repository). It supports being
invoked standalone or from the 'project-switch-commands' dispatch menu.
+++
*** New user option 'project-list-exclude'.
This user option describes projects that should always be skipped by
'project-remember-project'.
***
** Registers
*** New functions 'buffer-to-register' and 'file-to-register'.

View file

@ -1837,6 +1837,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).")
@ -1902,9 +1912,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.
@ -2274,7 +2291,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 (if (symbolp project-switch-commands)
project-switch-commands
(project--switch-project-command dir)))