Function: project-prompt-project-dir
project-prompt-project-dir is a byte-compiled function defined in
project.el.gz.
Signature
(project-prompt-project-dir &optional PROMPT PREDICATE REQUIRE-KNOWN)
Documentation
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,
see project-list-file.
If PROMPT is non-nil, use it as the prompt string.
If PREDICATE is non-nil, filter possible project choices using this
function; see project-prompter for more details.
Unless REQUIRE-KNOWN is non-nil, it's also possible to enter an
arbitrary directory not in the list of known projects.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/project.el.gz
(defun project-prompt-project-dir (&optional prompt predicate require-known)
"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,
see `project-list-file'.
If PROMPT is non-nil, use it as the prompt string.
If PREDICATE is non-nil, filter possible project choices using this
function; see `project-prompter' for more details.
Unless REQUIRE-KNOWN is non-nil, it's also possible to enter an
arbitrary directory not in the list of known projects."
(project--ensure-read-project-list)
(when-let* ((pred (alist-get 'prompt project-prune-zombie-projects))
(inhibit-message t))
(project--delete-zombie-projects pred))
(let* ((dir-choice "... (choose a dir)")
(current (and-let* ((p (project-current))
(_ (or (null predicate)
(funcall predicate
(project-root p)))))
(project-root p)))
(choices
;; XXX: Just using this for the category (for the substring
;; completion style).
(project--file-completion-table
(if require-known project--list
(append project--list `(,dir-choice)))))
(project--dir-history (project-known-project-roots))
(pr-dir ""))
(while (string-empty-p pr-dir)
;; If the user simply pressed RET (and CURRENT is nil), do this
;; again until they don't.
(setq pr-dir
(let (history-add-new-input)
(completing-read
;; Emacs 28.1+: Use `format-prompt'.
(cond (prompt (format "%s: " prompt))
(current "Select project (default current project): ")
(t "Select project: "))
choices (and predicate
(lambda (choice)
(or (equal choice dir-choice)
(funcall predicate choice))))
t nil 'project--dir-history current))))
(if (equal pr-dir dir-choice)
(read-directory-name "Select directory: " default-directory nil t)
pr-dir)))