Function: projectile-cache-current-file
projectile-cache-current-file is an autoloaded, interactive and
byte-compiled function defined in projectile.el.
Signature
(projectile-cache-current-file &optional PROJECT-ROOT)
Documentation
Add the currently visited file to the cache.
PROJECT-ROOT defaults to the current project.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
;;;###autoload
(defun projectile-cache-current-file (&optional project-root)
"Add the currently visited file to the cache.
PROJECT-ROOT defaults to the current project."
(interactive)
(let ((current-project (or project-root (projectile-project-root))))
(when (and (buffer-file-name)
(file-exists-p (buffer-file-name))
(gethash current-project projectile-projects-cache))
(let* ((abs-current-file (file-truename (buffer-file-name)))
(current-file (file-relative-name abs-current-file current-project)))
(unless (or (projectile-file-cached-p current-file current-project)
;; A file under an ignored directory is ignored too, so
;; the single file check covers its parents as well.
(projectile-ignored-file-p abs-current-file current-project)
;; Projectile's own rules don't know what the VCS
;; ignores, and under `alien'/`hybrid' the VCS is what
;; produced the file list - so caching an opened file it
;; ignores would put something in the cache that indexing
;; never would (issue #1075). `native' walks the tree
;; itself and lists such files anyway, so it's left alone.
(and (memq projectile-indexing-method '(alien hybrid))
(projectile-vcs-ignored-file-p abs-current-file current-project)))
(let ((project-files (cons current-file (gethash current-project projectile-projects-cache))))
(puthash current-project project-files projectile-projects-cache)
;; Defer the disk write until Emacs is idle to avoid freezing the
;; UI immediately after the new file was created.
(when (projectile-persistent-cache-p)
(projectile--schedule-cache-flush current-project)))
(if (called-interactively-p 'interactive)
(message "Added %s to the cache of %s"
(propertize current-file 'face 'font-lock-keyword-face)
(propertize current-project 'face 'font-lock-keyword-face))
(projectile--message
"Added %s to the cache of %s"
(propertize current-file 'face 'font-lock-keyword-face)
(propertize current-project 'face 'font-lock-keyword-face))))))))