diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 599a350e5ce..9cc70335afc 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -193,6 +193,10 @@ project-find-functions 'project-current-directory-override "29.1") +(defvar project-forget-functions (list #'project-vc-forget-directory) + "Special hook to clear cache for a directory tree. +Each function on this hook is passed a string, the directory file name.") + (defvar project-current-directory-override nil "Value to use instead of `default-directory' when detecting the project. When it is non-nil, `project-current' will always skip prompting too.") @@ -599,6 +603,13 @@ project-try-vc (vc-file-setprop dir 'project-vc project) project)))) +(defun project-vc-forget-directory (root) + (obarray-map + (lambda (sym) + (when (string-prefix-p root (symbol-name sym)) + (vc-file-setprop (symbol-name sym) 'project-vc nil))) + vc-file-prop-obarray)) + (defun project--submodule-p (root) ;; XXX: We only support Git submodules for now. ;; @@ -1875,6 +1886,7 @@ project-forget-project PROJECT-ROOT is the root directory of a known project listed in the project list." (interactive (list (funcall project-prompter))) + (run-hook-with-args 'project-forget-functions project-root) (project--remove-from-project-list project-root "Project `%s' removed from known projects")) @@ -1999,6 +2011,8 @@ project-remember-projects-under projects." (interactive "DDirectory: \nP") (project--ensure-read-project-list) + ;; Clear the cache for DIR and below, in case of prior visit. + (run-hook-with-args 'project-forget-functions dir) (let ((dirs (if recursive (directory-files-recursively dir "" t) (directory-files dir t)))