Function: treemacs--flatten-imenu-index
treemacs--flatten-imenu-index is a byte-compiled function defined in
treemacs-tag-follow-mode.el.
Signature
(treemacs--flatten-imenu-index INDEX &optional PATH)
Documentation
Flatten a nested imenu INDEX to a flat list of tag paths.
The function works recursively with PATH being the already collected tag path in each iteration.
INDEX: Imenu Tag Index PATH: String List
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-tag-follow-mode.el
(defun treemacs--flatten-imenu-index (index &optional path)
"Flatten a nested imenu INDEX to a flat list of tag paths.
The function works recursively with PATH being the already collected tag path in
each iteration.
INDEX: Imenu Tag Index
PATH: String List"
(declare (pure t) (side-effect-free t))
(let (result)
(--each index
(cond
((imenu--subalist-p it)
(setq result
(append result (treemacs--flatten-imenu-index (cdr it) (cons (car it) path)))))
;; make sure our leaf elements have a cdr where a location should be stored, it looks like there are cases,
;; at least on emacs 25, where we only get what amounts to an empty section
;; https://github.com/Alexander-Miller/treemacs/issues/283#issuecomment-427281977
((and (consp it) (cdr it))
(setq result (cons (cons it (nreverse (copy-sequence path))) result)))))
result))