Function: vundo--draw-tree

vundo--draw-tree is a natively compiled function defined in vundo.el.

Signature

(vundo--draw-tree MOD-LIST)

Documentation

Draw the tree in MOD-LIST in current buffer.

Source Code

;; Defined in /nix/store/386w2ds6bdh3gcz9k23jssw4cni4lfr2-emacs-packages-deps/share/emacs/site-lisp/elpa/vundo-2.4.0/vundo.el
(defun vundo--draw-tree (mod-list)
  "Draw the tree in MOD-LIST in current buffer."
  (let* ((root (aref mod-list 0))
         (node-queue (list root))
         (inhibit-read-only t)
         (inhibit-modification-hooks t))
    (erase-buffer)
    (while node-queue
      (let* ((node (pop node-queue))
             (children (vundo-m-children node))
             (parent (vundo-m-parent node))
             (siblings (and parent (vundo-m-children parent)))
             (only-child-p (and parent (eq (length siblings) 1)))
             (node-last-child-p (and parent (eq node (car (last siblings)))))
             (mod-ts (vundo--node-timestamp mod-list node 'no-buffer))
             (node-face (if (and vundo-highlight-saved-nodes mod-ts)
                            'vundo-saved 'vundo-node))
             (stem-face (if only-child-p 'vundo-stem 'vundo-branch-stem)))
        ;; Go to parent.
        (if parent (goto-char (vundo-m-point parent)))
        (let ((room-for-another-rx
               (rx-to-string
                `(or (>= ,(if vundo-compact-display 3 4) ?\s) eol))))
          (if (null parent)
              (insert (propertize (vundo--translate "○")
                                  'face node-face))
            (let ((planned-point (point)))
              ;; If a node is blocking, try next line.
              ;; Example: 1--2--3  Here we want to add a
              ;;             |     child to 1 but is blocked
              ;;             +--4  by that plus sign.
              (while (not (looking-at room-for-another-rx))
                (vundo--next-line-at-column (max 0 (1- (current-column))))
                ;; When we go down, we could encounter space, EOL, │,
                ;; ├, or └. Space and EOL should be replaced by │, ├
                ;; and └ should be replaced by ├.
                (let ((replace-char
                       (if (looking-at
                            (rx-to-string
                             `(or ,(vundo--translate "├")
                                  ,(vundo--translate "└"))))
                           (vundo--translate "├")
                         (vundo--translate "│"))))
                  (unless (eolp) (delete-char 1))
                  (insert (propertize replace-char 'face stem-face))))
              ;; Make room for inserting the new node.
              (unless (looking-at "$")
                (delete-char (if vundo-compact-display 2 3)))
              ;; Insert the new node.
              (if (eq (point) planned-point)
                  (insert (propertize
                           (vundo--translate
                            (if vundo-compact-display "─" "──"))
                           'face stem-face)
                          (propertize (vundo--translate "○")
                                      'face node-face))
                ;; We must break the line. Delete the previously
                ;; inserted char.
                (delete-char -1)
                (insert (propertize
                         (vundo--translate
                          (if node-last-child-p
                              (if vundo-compact-display "└─" "└──")
                            (if vundo-compact-display "├─" "├──")))
                         'face stem-face))
                (insert (propertize (vundo--translate "○")
                                    'face node-face))))))
        ;; Store point so we can later come back to this node.
        (setf (vundo-m-point node) (point))
        ;; Associate the text node in buffer with the node object.
        (vundo--put-node-at-point node)
        ;; Depth-first search.
        (setq node-queue (append children node-queue))))))