Function: projectile-project-buffer-p

projectile-project-buffer-p is a byte-compiled function defined in projectile.el.

Signature

(projectile-project-buffer-p BUFFER PROJECT-ROOT &optional TRUENAME-CACHE)

Documentation

Check if BUFFER is under PROJECT-ROOT.

Optional TRUENAME-CACHE is a hash table used to memoize file-truename calls when checking multiple buffers against the same project root.

For buffers visiting remote (TRAMP) files we skip the file-truename call: each such call is a remote round-trip, and resolving symlinks across a TRAMP boundary is rarely what users want. The downside is that a remote project reached via two different symlinked paths won't be matched - we trade that edge case for not stalling projectile-project-buffers on networks with high latency.

Source Code

;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
(defun projectile-project-buffer-p (buffer project-root &optional truename-cache)
  "Check if BUFFER is under PROJECT-ROOT.
Optional TRUENAME-CACHE is a hash table used to memoize `file-truename'
calls when checking multiple buffers against the same project root.

For buffers visiting remote (TRAMP) files we skip the `file-truename'
call: each such call is a remote round-trip, and resolving symlinks
across a TRAMP boundary is rarely what users want.  The downside is
that a remote project reached via two different symlinked paths won't
be matched - we trade that edge case for not stalling
`projectile-project-buffers' on networks with high latency."
  (with-current-buffer buffer
    (let ((directory (if buffer-file-name
                         (file-name-directory buffer-file-name)
                       default-directory)))
      (and (not (string-prefix-p " " (buffer-name buffer)))
           (not (projectile-ignored-buffer-p buffer))
           directory
           (string-equal (file-remote-p directory)
                         (file-remote-p project-root))
           (not (string-match-p "^http\\(s\\)?://" directory))
           (let ((compare-dir
                  (cond
                   ((file-remote-p directory) directory)
                   (truename-cache
                    (or (gethash directory truename-cache)
                        (puthash directory (file-truename directory) truename-cache)))
                   (t (file-truename directory)))))
             (string-prefix-p project-root compare-dir (eq system-type 'windows-nt)))))))