Function: treemacs--call-imenu-and-goto-tag
treemacs--call-imenu-and-goto-tag is a byte-compiled function defined
in treemacs-tags.el.
Signature
(treemacs--call-imenu-and-goto-tag TAG-PATH &optional ORG?)
Documentation
Call the imenu index of the tag at TAG-PATH and go to its position.
ORG? should be t when this function is called for an org buffer and index since
org requires a slightly different position extraction because the position of a
headline with sub-elements is saved in an org-imenu-marker text property.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-tags.el
(defun treemacs--call-imenu-and-goto-tag (tag-path &optional org?)
"Call the imenu index of the tag at TAG-PATH and go to its position.
ORG? should be t when this function is called for an org buffer and index since
org requires a slightly different position extraction because the position of a
headline with sub-elements is saved in an `org-imenu-marker' text property."
(let* ((file (car tag-path))
(path (-butlast (cdr tag-path)))
(tag (-last-item tag-path)))
(condition-case e
(progn
(find-file-noselect file)
(let ((index (treemacs--get-imenu-index file)))
(dolist (path-item path)
(setq index (cdr (assoc path-item index))))
(-let [(buf . pos) (treemacs--extract-position
(-let [item (--first
(equal (car it) tag)
index)]
(if org? item (cdr item)))
(car tag-path))]
;; some imenu implementations, like markdown, will only provide
;; a raw buffer position (an int) to move to
(switch-to-buffer (or buf (get-file-buffer file)))
(if (functionp pos)
(funcall pos)
(goto-char pos))
;; a little bit of convenience - reveal those nested headlines
(when (and (eq major-mode 'org-mode)
(fboundp 'org-reveal))
(org-reveal)))))
(error
(treemacs-log-err "Something went wrong when finding tag '%s': %s"
(propertize tag 'face 'treemacs-tags-face)
e)))))