Subject: bug#53375: [PATCH] Account for padding and content length in, tabulated-list-widen-current-column

From: Thuna <[email-masked]>
Date: Thu, 20 Jan 2022 00:40:41 +0300

`tabulated-list-widen-current-column' previously looked only at the
width of the column as given in `tabulated-list-format' however this
fails to account for both the padding and content length and as a
result widens the wrong column.

The issue with content length is reproducible as follows:
0. emacs -Q
1. M-x shell
2. M-x list-processes
3. C-x o
4. C-: (tabulated-list-set-col 0 (make-string 50 ?.) t)
5. M-f
6. }

This patch should solve the issue however it relies on
`tabulated-list-get-entry' which means it fails to work if the
`tabulated-list-entry' property is not set properly.  I am unsure if
this should be considered a bug on the tabulated-list end or not.

>From 4306519f28f5889c7fbf435c0d12b596f49a6a52 Mon Sep 17 00:00:00 2001
From: Thuna <[email-masked]>
Date: Tue, 18 Jan 2022 23:51:30 +0300
Subject: [PATCH] Fix tabulated-list-widen-current-column widening wrong column

* tabulated-list.el (tabulated-list-widen-current-column): Account for the
padding and the content width when calculating column width.
---
 lisp/emacs-lisp/tabulated-list.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el
index 4a9814b5da..32a046e0fb 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -731,6 +731,7 @@ tabulated-list-widen-current-column
 1."
   (interactive "p")
   (let ((start (current-column))
+        (entry (tabulated-list-get-entry))
         (nb-cols (length tabulated-list-format))
         (col-nb 0)
         (total-width 0)
@@ -741,9 +742,14 @@ tabulated-list-widen-current-column
       (if (> start
              (setq total-width
                    (+ total-width
-                      (setq col-width
-                            (cadr (aref tabulated-list-format
-                                        col-nb))))))
+                      (max (setq col-width
+                                 (cadr (aref tabulated-list-format
+                                             col-nb)))
+                           (string-width (aref entry col-nb)))
+                      (or (plist-get (nthcdr 3 (aref tabulated-list-format
+                                                     col-nb))
+                                     :pad-right)
+                          1))))
           (setq col-nb (1+ col-nb))
         (setq found t)
         (setf (cadr (aref tabulated-list-format col-nb))
-- 
2.25.1