Function: treemacs-fit-window-width

treemacs-fit-window-width is an interactive and byte-compiled function defined in treemacs-interface.el.

Signature

(treemacs-fit-window-width)

Documentation

Make treemacs wide enough to display its entire content.

Specifically this will increase (or reduce) the width of the treemacs window to that of the longest line, counting all lines, not just the ones that are visible.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-interface.el
(defun treemacs-fit-window-width ()
  "Make treemacs wide enough to display its entire content.

Specifically this will increase (or reduce) the width of the treemacs window to
that of the longest line, counting all lines, not just the ones that are
visible."
  (interactive)
  (let ((longest 0)
        (depth 0))
    (save-excursion
      (goto-char (point-min))
      (while (= 0 (forward-line 1))
        (-let [new-len (- (line-end-position) (line-beginning-position))]
          (when (> new-len longest)
            (setf longest new-len
                  depth (treemacs--prop-at-point :depth))))))
    (let* ((icon-px-diff (* depth (- treemacs--icon-size (frame-char-width))))
           (icon-offset (% icon-px-diff (frame-char-width)))
           (new-width (+ longest icon-offset)))
      (setf treemacs-width new-width)
      (treemacs--set-width new-width)
      (treemacs-pulse-on-success "Width set to %s"
        (propertize (format "%s" new-width) 'face 'font-lock-string-face)))))