Function: project--find-default-from

project--find-default-from is a byte-compiled function defined in project.el.gz.

Signature

(project--find-default-from FILENAME PROJECT)

Documentation

Ensure FILENAME is in PROJECT.

Usually, just return FILENAME. But if project-current-directory-override is set, adjust it to be relative to PROJECT instead.

This supports using a relative file name from the current buffer when switching projects with project-switch-project and then using a command like project-find-file.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/project.el.gz
(defun project--find-default-from (filename project)
  "Ensure FILENAME is in PROJECT.

Usually, just return FILENAME.  But if
`project-current-directory-override' is set, adjust it to be
relative to PROJECT instead.

This supports using a relative file name from the current buffer
when switching projects with `project-switch-project' and then
using a command like `project-find-file'."
  (if-let* ((filename-proj (and project-current-directory-override
                                (project-current nil default-directory))))
      ;; file-name-concat requires Emacs 28+
      (concat (file-name-as-directory (project-root project))
              (file-relative-name filename (project-root filename-proj)))
    filename))