Function: project-current
project-current is an autoloaded and byte-compiled function defined in
project.el.gz.
Signature
(project-current &optional MAYBE-PROMPT DIRECTORY)
Documentation
Return the project instance in DIRECTORY, defaulting to default-directory.
When no project is found in that directory, the result depends on
the value of MAYBE-PROMPT: if it is nil or omitted, return nil,
else prompt the user for the project to use. To prompt for a
project, call the function specified by project-prompter, which
returns the directory in which to look for the project. If no
project is found in that directory, return a "transient"
project instance. When MAYBE-PROMPT is a string, it's passed to the
prompter function as an argument.
The "transient" project instance is a special kind of value
which denotes a project rooted in that directory and includes all
the files under the directory except for those that match entries
in vc-directory-exclusion-list or grep-find-ignored-files(var)/grep-find-ignored-files(fun).
See the doc string of project-find-functions for the general form
of the project instance object.
Probably introduced at or before Emacs version 31.1.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/project.el.gz
;;;###autoload
(defun project-current (&optional maybe-prompt directory)
"Return the project instance in DIRECTORY, defaulting to `default-directory'.
When no project is found in that directory, the result depends on
the value of MAYBE-PROMPT: if it is nil or omitted, return nil,
else prompt the user for the project to use. To prompt for a
project, call the function specified by `project-prompter', which
returns the directory in which to look for the project. If no
project is found in that directory, return a \"transient\"
project instance. When MAYBE-PROMPT is a string, it's passed to the
prompter function as an argument.
The \"transient\" project instance is a special kind of value
which denotes a project rooted in that directory and includes all
the files under the directory except for those that match entries
in `vc-directory-exclusion-list' or `grep-find-ignored-files'.
See the doc string of `project-find-functions' for the general form
of the project instance object."
(unless directory (setq directory (or project-current-directory-override
default-directory)))
(let* ((non-essential (not maybe-prompt))
(pr (project--find-in-directory directory)))
(cond
(pr)
((unless project-current-directory-override
maybe-prompt)
(setq directory (if (stringp maybe-prompt)
(funcall project-prompter maybe-prompt)
(funcall project-prompter))
pr (project--find-in-directory directory))))
(when maybe-prompt
(if pr
(project-remember-project pr)
(project--remove-from-project-list
directory "Project `%s' not found; removed from list")
(setq pr (cons 'transient directory))))
pr))