aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/vtable.el68
1 files changed, 42 insertions, 26 deletions
diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el
index 925961f012c..043b9ca55c4 100644
--- a/lisp/emacs-lisp/vtable.el
+++ b/lisp/emacs-lisp/vtable.el
@@ -850,32 +850,48 @@ If NEXT, do the next column."
850 (error "Invalid spec: %s" spec)))) 850 (error "Invalid spec: %s" spec))))
851 851
852(defun vtable--compute-widths (table cache) 852(defun vtable--compute-widths (table cache)
853 "Compute the display widths for TABLE." 853 "Compute the display widths for TABLE.
854 (seq-into 854CACHE is TABLE's cache data as returned by `vtable--compute-cache'."
855 (seq-map-indexed 855 (let* ((n-0cols 0) ; Count the number of zero-width columns.
856 (lambda (column index) 856 (widths (seq-map-indexed
857 (let ((width 857 (lambda (column index)
858 (or 858 (let ((width
859 ;; Explicit widths. 859 (or
860 (and (vtable-column-width column) 860 ;; Explicit widths.
861 (vtable--compute-width table (vtable-column-width column))) 861 (and (vtable-column-width column)
862 ;; Compute based on the displayed widths of 862 (vtable--compute-width table (vtable-column-width column)))
863 ;; the data. 863 ;; If the vtable is empty and no explicit width is given,
864 (seq-max (seq-map (lambda (elem) 864 ;; set its width to 0 and deal with it below.
865 (nth 1 (elt (cdr elem) index))) 865 (when (null cache)
866 cache))))) 866 (setq n-0cols (1+ n-0cols))
867 ;; Let min-width/max-width specs have their say. 867 0)
868 (when-let* ((min-width (and (vtable-column-min-width column) 868 ;; Otherwise, compute based on the displayed widths of the
869 (vtable--compute-width 869 ;; data.
870 table (vtable-column-min-width column))))) 870 (seq-max (seq-map (lambda (elem)
871 (setq width (max width min-width))) 871 (nth 1 (elt (cdr elem) index)))
872 (when-let* ((max-width (and (vtable-column-max-width column) 872 cache)))))
873 (vtable--compute-width 873 ;; Let min-width/max-width specs have their say.
874 table (vtable-column-max-width column))))) 874 (when-let* ((min-width (and (vtable-column-min-width column)
875 (setq width (min width max-width))) 875 (vtable--compute-width
876 width)) 876 table (vtable-column-min-width column)))))
877 (vtable-columns table)) 877 (setq width (max width min-width)))
878 'vector)) 878 (when-let* ((max-width (and (vtable-column-max-width column)
879 (vtable--compute-width
880 table (vtable-column-max-width column)))))
881 (setq width (min width max-width)))
882 width))
883 (vtable-columns table))))
884 ;; If there are any zero-width columns, divide the remaining window
885 ;; width evenly over them.
886 (when (> n-0cols 0)
887 (let* ((combined-width (apply #'+ widths))
888 (default-width (/ (- (window-width nil t) combined-width) n-0cols)))
889 (setq widths (mapcar (lambda (width)
890 (if (zerop width)
891 default-width
892 width))
893 widths))))
894 (seq-into widths 'vector)))
879 895
880(defun vtable--compute-cache (table) 896(defun vtable--compute-cache (table)
881 (seq-map 897 (seq-map