From 003962fa5f2b9cc6c5a78fc52b91fb3d930b9300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Marks?= Date: Sat, 14 Feb 2026 07:48:10 -0500 Subject: [PATCH] vtable fixes for tty rendering (bug#80312) * lisp/emacs-lisp/vtable.el (vtable--insert-line): Do not produce a divider after the final column. This thinko is more noticeable on a tty. (vtable--insert-header-line): On a tty, nullify indicator padding. (vtable-tty-char-pixel-width): New defconst. (vtable--compute-width): On a tty, adjust column width specified in pixels down by a factor of 'vtable-tty-char-pixel-width'. (vtable--alter-column-width): On a tty, adjust column width in characters, otherwise in pixels. --- lisp/emacs-lisp/vtable.el | 40 ++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lisp/emacs-lisp/vtable.el b/lisp/emacs-lisp/vtable.el index 994d8aac4b9..4db3e933551 100644 --- a/lisp/emacs-lisp/vtable.el +++ b/lisp/emacs-lisp/vtable.el @@ -680,7 +680,7 @@ itself in the new buffer." (add-face-text-property start (point) (elt column-colors (mod index (length column-colors))))) - (when divider + (when (and divider (not last)) (insert divider) (setq start (point)))))) (cdr line)) @@ -770,10 +770,17 @@ itself in the new buffer." buffer) name)) (let* ((indicator-lead-width - ;; We want the indicator to not be quite flush right. - (/ (vtable--char-width table) 2.0)) - (indicator-pad-width (- (vtable--char-width table) - indicator-lead-width)) + (if (display-graphic-p) + ;; On a graphical frame, we want the indicator to + ;; not be quite flush right... + (/ (vtable--char-width table) 2.0) + 0)) + (indicator-pad-width + (if (display-graphic-p) + ;; ...and adjust its padding. + (- (vtable--char-width table) + indicator-lead-width) + 0)) (fill-width (+ (- (elt widths index) (string-pixel-width displayed buffer) @@ -885,6 +892,13 @@ If NEXT, do the next column." (string-pixel-width (propertize "x" 'face (vtable-face table)) (vtable-buffer table))) +(defconst vtable-tty-char-pixel-width 10 + "This is a conversion factor from pixels to characters for tty terminals. +This represents the average number of pixels of a character displayed on +a tty terminal. +This is applied if a column's width is specified in pixels and the +vtable is being rendered on a tty terminal.") + (defun vtable--compute-width (table spec) (cond ((numberp spec) @@ -892,7 +906,9 @@ If NEXT, do the next column." ((string-match "\\([0-9.]+\\)ex" spec) (* (string-to-number (match-string 1 spec)) (vtable--char-width table))) ((string-match "\\([0-9.]+\\)px" spec) - (string-to-number (match-string 1 spec))) + (/ (string-to-number (match-string 1 spec)) + ;; Adjust pixels down by a factor for tty terminals. + (if (display-graphic-p) 1 vtable-tty-char-pixel-width))) ((string-match "\\([0-9.]+\\)%" spec) (/ (* (string-to-number (match-string 1 spec)) (window-width nil t)) 100)) @@ -1034,13 +1050,15 @@ Interactively, N is the prefix argument." (- (* (vtable--char-width table) (or n 1)))))) (defun vtable--alter-column-width (table column delta) - (let ((widths (vtable--cache-widths (vtable--current-cache table)))) - (setf (aref widths column) - (max (* (vtable--char-width table) 2) - (+ (aref widths column) delta))) + (let* ((widths (vtable--cache-widths (vtable--current-cache table))) + (new-width (max (* (vtable--char-width table) 2) + (+ (aref widths column) delta)))) + (setf (aref widths column) new-width) ;; Store the width so it'll be respected on a revert. (setf (vtable-column-width (elt (vtable-columns table) column)) - (format "%dpx" (aref widths column))) + (if (display-graphic-p) + (format "%dpx" new-width) + new-width)) (vtable-revert table))) (defun vtable-widen-current-column (&optional n)