Function: projectile-toggle-related-file
projectile-toggle-related-file is an autoloaded, interactive and
byte-compiled function defined in projectile.el.
Signature
(projectile-toggle-related-file)
Documentation
Jump between the current file and its related files of other kinds.
This is the file-kinds generalization of
projectile-toggle-between-implementation-and-test. The current file's
kind and resource key are detected from the project type's :file-kinds
declaration and its related files (files of other kinds sharing the same
key) are collected in table order. When exactly one related kind exists
it is opened immediately; when several exist the first invocation prompts
for the kind, and repeated invocations cycle through them in table order.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/projectile-20260820.1509/projectile.el
;;;###autoload
(defun projectile-toggle-related-file ()
"Jump between the current file and its related files of other kinds.
This is the file-kinds generalization of
`projectile-toggle-between-implementation-and-test'. The current file's
kind and resource key are detected from the project type's `:file-kinds'
declaration and its related files (files of other kinds sharing the same
key) are collected in table order. When exactly one related kind exists
it is opened immediately; when several exist the first invocation prompts
for the kind, and repeated invocations cycle through them in table order."
(interactive)
(let ((file (buffer-file-name)))
(unless file
(user-error "The current buffer is not visiting a file"))
(let* ((project-root (projectile-acquire-root))
;; Spell the file the same way as the root (symlink-resolved), so a
;; project reached through a symlinked root doesn't yield a bogus
;; `../'-prefixed relative name and a spurious "no related files".
(rel-path (projectile--project-relative-name (file-truename file) project-root))
(ring (projectile--related-file-ring rel-path))
(others (remove rel-path ring)))
(unless others
(user-error "No related files found for `%s'"
(file-name-nondirectory file)))
(let ((target
(cond
;; A single related kind: jump straight to it.
((= (length others) 1) (car others))
;; Repeated invocation: cycle to the next kind in table order.
((eq last-command this-command)
(let ((pos (or (seq-position ring rel-path) 0)))
(nth (mod (1+ pos) (length ring)) ring)))
;; Several kinds, first invocation: let the user choose.
(t (projectile--read-related-file-target rel-path)))))
(find-file (expand-file-name target project-root))))))