Function: treemacs--format-bookmark-title
treemacs--format-bookmark-title is a byte-compiled function defined in
treemacs-bookmarks.el.
Signature
(treemacs--format-bookmark-title BTN)
Documentation
Format the bookmark title for BTN with treemacs-bookmark-title-template.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-bookmarks.el
(defun treemacs--format-bookmark-title (btn)
"Format the bookmark title for BTN with `treemacs-bookmark-title-template'."
(s-format
treemacs-bookmark-title-template
(lambda (pattern)
(or
(cond
;; ${label} - Label of the current button
((string= pattern "label")
(treemacs--get-label-of btn))
;; ${label:1} - Label of Nth parent
((s-starts-with? "label:" pattern)
(let ((depth (string-to-number (s-chop-prefix "label:" pattern)))
(current-button btn))
(dotimes (_ depth)
(setq current-button (when current-button (treemacs-button-get current-button :parent))))
(when current-button
(treemacs--get-label-of current-button))))
;; ${label-path} and ${label-path:4} - Path of labels, optionally limited by a number.
((or (string= pattern "label-path") (s-starts-with? "label-path:" pattern))
(let ((depth (when (s-starts-with? "label-path:" pattern)
(string-to-number (s-chop-prefix "label-path:" pattern))))
(current-button btn)
(path))
(while (and current-button (not (eq 0 depth)))
(push (treemacs--get-label-of current-button) path)
(when depth (cl-decf depth))
(setq current-button (treemacs-button-get current-button :parent)))
(s-join "/" path)))
;; ${project} - Label of the project or top-level extension node.
((string= pattern "project")
;; Find the root button by iterating - don't use `treemacs-project-of-node`
;; to make this work for variadic top-level extensions.
(let ((current-button btn))
(while (> (treemacs-button-get current-button :depth) 0)
(setq current-button (treemacs-button-get current-button :parent)))
(treemacs--get-label-of current-button)))
;; ${file-path} - Filesystem path.
((string= pattern "file-path")
(treemacs--nearest-path btn))
;; ${file-path:3} - N components of the file path
((s-starts-with? "file-path:" pattern)
(let ((n (string-to-number (s-chop-prefix "file-path:" pattern))))
(-when-let (path (treemacs--nearest-path btn))
(let ((components (last (s-split "/" path) (1+ n))))
;; Add the leading slash for absolute paths
(when (and (> (length components) n) (not (string= "" (car components))))
(pop components))
(s-join "/" components)))))
(t
;; Don't rely on treemacs-pulse-on-failure to display the error, since the
;; error must be handled in bookmark.el.
(treemacs-pulse-on-failure)
(user-error "Bookmark template pattern %s was not recognized" pattern)))
""))))