Function: treemacs--flatten-dirs

treemacs--flatten-dirs is a byte-compiled function defined in treemacs-rendering.el.

Signature

(treemacs--flatten-dirs DIRS)

Documentation

Display DIRS as flattened.

Go to each dir button, expand its label with the collapsed dirs, set its new path and give it a special parent-path property so opening it will add the correct cache entries.

DIRS: List of Collapse Paths. Each Collapse Path is a list of
 1) the extra text that must be appended in the view,
 2) The original full and un-collapsed path,
 3) a series of intermediate steps which are the result of appending the
    collapsed path elements onto the original, ending in
 4) the full path to the
    directory that the collapsing leads to. For Example:
    ("/26.0/elpa"
     "/home/a/Documents/git/treemacs/.cask"
     "/home/a/Documents/git/treemacs/.cask/26.0"
     "/home/a/Documents/git/treemacs/.cask/26.0/elpa")

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-rendering.el
(defun treemacs--flatten-dirs (dirs)
  "Display DIRS as flattened.
Go to each dir button, expand its label with the collapsed dirs, set its new
path and give it a special parent-path property so opening it will add the
correct cache entries.

DIRS: List of Collapse Paths.  Each Collapse Path is a list of
 1) the extra text that must be appended in the view,
 2) The original full and un-collapsed path,
 3) a series of intermediate steps which are the result of appending the
    collapsed path elements onto the original, ending in
 4) the full path to the
    directory that the collapsing leads to.  For Example:
    (\"/26.0/elpa\"
     \"/home/a/Documents/git/treemacs/.cask\"
     \"/home/a/Documents/git/treemacs/.cask/26.0\"
     \"/home/a/Documents/git/treemacs/.cask/26.0/elpa\")"
  (when dirs
    (-let [project (-> dirs (car) (cadr) (treemacs--find-project-for-path))]
      (dolist (it dirs)
        (let* ((label-to-add (car it))
               (original-path (cadr it))
               (extra-steps (cddr it))
               (new-path (-last-item extra-steps))
               (coll-count (length extra-steps)))
          ;; use when-let because the operation may fail when we try to move to a node
          ;; that us not visible because treemacs ignores it
          (-when-let (b (treemacs-find-file-node original-path project))
            ;; no warning since filewatch mode is known to be defined
            (when (with-no-warnings treemacs-filewatch-mode)
              (treemacs--start-watching original-path)
              (dolist (step extra-steps)
                (treemacs--start-watching step t)))
            ;; make extra dom entries for the flattened steps
            (-let [dom-node (treemacs-find-in-dom original-path)]
              (dolist (step extra-steps)
                (ht-set! treemacs-dom step dom-node))
              (setf (treemacs-dom-node->collapse-keys dom-node) extra-steps))
            (-let [props (text-properties-at (treemacs-button-start b))]
              (treemacs-button-put b :path new-path)
              ;; if the collapsed path leads to a symlinked directory the button needs to be marked as a symlink
              ;; so `treemacs--expand-dir-node' will know to start a new git future under its true-name
              (treemacs-button-put b :symlink (or (treemacs-button-get b :symlink)
                                                  (--first (file-symlink-p it) extra-steps)))
              ;; number of directories that have been appended to the original path plus all extra steps
              ;; to use as dom keys when the node is expanded
              (treemacs-button-put b :collapsed (cons coll-count (cons original-path extra-steps)))
              (end-of-line)
              (-let [beg (point)]
                (insert label-to-add)
                (add-text-properties beg (point) props)
                (unless (treemacs--non-simple-git-mode-enabled)
                  (add-text-properties
                   beg (point)
                   '(face treemacs-directory-collapsed-face)))
                (-when-let* ((ann (treemacs-get-annotation new-path))
                             (git-cache
                              (->> original-path
                                   (treemacs--parent-dir)
                                   (ht-get treemacs--git-cache))))
                  (treemacs-button-put
                   b 'face
                   (treemacs-annotation->face-value ann)))))))))))