Function: eshell-ls-find-column-widths
eshell-ls-find-column-widths is a byte-compiled function defined in
em-ls.el.gz.
Signature
(eshell-ls-find-column-widths FILES)
Documentation
Find the best fitting column widths for FILES.
It will be returned as a vector, whose length is the number of columns
to use, and each member of which is the width of that column
(including spacing).
Source Code
;; Defined in /usr/src/emacs/lisp/eshell/em-ls.el.gz
(defun eshell-ls-find-column-widths (files)
"Find the best fitting column widths for FILES.
It will be returned as a vector, whose length is the number of columns
to use, and each member of which is the width of that column
\(including spacing)."
(let* ((numcols 0)
(width 0)
(widths
(mapcar
(lambda (file)
(+ 2 (length (car file))))
files))
;; must account for the added space...
(max-width (+ (window-width) 2))
(best-width 0)
col-widths)
;; determine the largest number of columns in the first row
(let ((w widths))
(while (and w (< width max-width))
(setq width (+ width (car w))
numcols (1+ numcols)
w (cdr w))))
;; refine it based on the following rows
(while (> numcols 0)
(let ((i 0)
(colw (make-vector numcols 0))
(w widths))
(while w
(if (= i numcols)
(setq i 0))
(aset colw i (max (aref colw i) (car w)))
(setq w (cdr w) i (1+ i)))
(setq i 0 width 0)
(while (< i numcols)
(setq width (+ width (aref colw i))
i (1+ i)))
(if (and (< width max-width)
(> width best-width))
(setq col-widths colw
best-width width)))
(setq numcols (1- numcols)))
(cons (or col-widths (vector max-width)) files)))