Function: treemacs--create-branch
treemacs--create-branch is a byte-compiled function defined in
treemacs-rendering.el.
Signature
(treemacs--create-branch ROOT DEPTH GIT-FUTURE FLATTEN-FUTURE &optional PARENT)
Documentation
Create a new treemacs branch under ROOT.
The branch is indented at DEPTH and uses the eventual outputs of GIT-FUTURE to decide on file buttons' faces and FLATTEN-FUTURE to determine which directories should be displayed as one. The buttons' parent property is set to PARENT.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-rendering.el
(define-inline treemacs--create-branch (root depth git-future flatten-future &optional parent)
"Create a new treemacs branch under ROOT.
The branch is indented at DEPTH and uses the eventual outputs of
GIT-FUTURE to decide on file buttons' faces and FLATTEN-FUTURE to determine
which directories should be displayed as one. The buttons' parent property is
set to PARENT."
(inline-letevals (root depth git-future flatten-future parent)
(inline-quote
(save-excursion
(let* ((dirs-and-files (treemacs--get-dir-content ,root))
(dirs (car dirs-and-files))
(files (cadr dirs-and-files))
(parent-node (treemacs-find-in-dom ,root))
(dir-dom-nodes)
(file-dom-nodes)
(git-info)
(file-strings)
(dir-strings))
(setq dir-strings
(treemacs--create-buttons
:nodes dirs
:depth ,depth
:node-name node
:node-action (treemacs--create-dir-button-strings node prefix ,parent ,depth)))
(setq file-strings
(treemacs--create-buttons
:nodes files
:depth ,depth
:node-name node
:node-action (treemacs--create-file-button-strings node prefix ,parent ,depth)))
(end-of-line)
;; the files list contains 3 item tuples: the prefix the icon and the filename
;; direcories are different, since dirs do not have different icons the icon is part if the prefix
;; therefore when filtering or propertizing the files and dirs only every 3rd or 2nd item must be looked at
;; as reopening is done recursively the parsed git status is passed down to subsequent calls
;; so there are two possibilities: either the future given to this function is a pfuture object
;; that needs to complete and be parsed or it's an already finished git status hash table
;; additionally when git mode is deferred we don't parse the git output right here, it is instead done later
;; by means of an idle timer. The git info used is instead fetched from `treemacs--git-cache', which is
;; based on previous invocations
;; if git-mode is disabled there is nothing to do - in this case the git status parse function will always
;; produce an empty hash table
(pcase treemacs--git-mode
((or 'simple 'extended)
(setf git-info (treemacs--get-or-parse-git-result ,git-future))
(ht-set! treemacs--git-cache ,root git-info))
('deferred
(setf git-info (or (ht-get treemacs--git-cache ,root) treemacs--empty-table)))
(_
(setf git-info treemacs--empty-table)))
(run-with-timer
0.5 nil
#'treemacs--apply-annotations-deferred
,parent ,root (current-buffer) ,git-future)
(if treemacs-pre-file-insert-predicates
(progn
(-let [result nil]
(while file-strings
(let* ((prefix (car file-strings))
(icon (cadr file-strings))
(filename (caddr file-strings))
(filepath (concat ,root "/" filename)))
(unless (--any? (funcall it filepath git-info) treemacs-pre-file-insert-predicates)
(setq result (cons filename (cons icon (cons prefix result))))
(push (treemacs-dom-node->create! :parent parent-node :key filepath)
file-dom-nodes)))
(setq file-strings (cdddr file-strings)))
(setq file-strings (nreverse result)))
(-let [result nil]
(while dir-strings
(let* ((prefix (car dir-strings))
(icon (cadr dir-strings))
(dirname (caddr dir-strings))
(dirpath (concat ,root "/" dirname)))
(unless (--any? (funcall it dirpath git-info) treemacs-pre-file-insert-predicates)
(setq result (cons dirname (cons icon (cons prefix result))))
(push (treemacs-dom-node->create! :parent parent-node :key dirpath)
dir-dom-nodes)))
(setq dir-strings (cdddr dir-strings)))
(setq dir-strings (nreverse result))))
(setf
file-dom-nodes
(--map (treemacs-dom-node->create! :parent parent-node :key it) files)
dir-dom-nodes
(--map (treemacs-dom-node->create! :parent parent-node :key it) dirs)))
;; do nodes can only be created *after* any potential fitering has taken place,
;; otherwise we end up with dom entries for files that are not rendered
(setf (treemacs-dom-node->children parent-node)
(nconc dir-dom-nodes file-dom-nodes (treemacs-dom-node->children parent-node)))
(dolist (it (treemacs-dom-node->children parent-node))
(treemacs-dom-node->insert-into-dom! it))
(setf dir-strings
(treemacs--inplace-map-when-unrolled dir-strings 3
(-if-let* ((ann (treemacs-get-annotation (concat ,root "/" it)))
(face (treemacs-annotation->face-value ann)))
(progn
(put-text-property
0
(length it)
'face
face
it)
(concat it (treemacs-annotation->suffix-value ann)))
(put-text-property
0
(length it)
'face
'treemacs-directory-face
it)
it)))
(insert (apply #'concat dir-strings))
(end-of-line)
(setf file-strings
(treemacs--inplace-map-when-unrolled file-strings 3
(-if-let* ((ann (treemacs-get-annotation (concat ,root "/" it)))
(face (treemacs-annotation->face-value ann)))
(progn
(put-text-property
0
(length it)
'face
face
it)
(concat it (treemacs-annotation->suffix-value ann)))
(put-text-property
0
(length it)
'face
'treemacs-git-unmodified-face
it)
it)))
(insert (apply #'concat file-strings))
(save-excursion
(treemacs--flatten-dirs
(treemacs--parse-flattened-dirs ,root ,flatten-future))
(treemacs--reentry ,root ,git-future ,flatten-future))
(with-no-warnings
(line-end-position)))))))