From e2e1ebe8820b866d13abbd0b4616256a99ef38f3 Mon Sep 17 00:00:00 2001 From: Visuwesh Date: Mon, 3 Mar 2025 13:56:04 +0530 Subject: [PATCH] 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) (cherry picked from commit 6aa60038ee999d25184a639ce0ac76b614e3afb6) --- doc/emacs/maintaining.texi | 9 +++++++++ lisp/progmodes/project.el | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/doc/emacs/maintaining.texi b/doc/emacs/maintaining.texi index 7d8f0c03edf..d69ca4df4e0 100644 --- a/doc/emacs/maintaining.texi +++ b/doc/emacs/maintaining.texi @@ -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 diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 6c71320ae24..6f6fba81c4c 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -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 -- 2.39.5