emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 233d350: Improve display of tabulated list header line labels (bu


From: Stephen Berman
Subject: master 233d350: Improve display of tabulated list header line labels (bug#44068)
Date: Wed, 4 Nov 2020 17:52:36 -0500 (EST)

branch: master
commit 233d350d1984bcb4e0f636ddfa29482b815fa2f2
Author: Stephen Berman <stephen.berman@gmx.net>
Commit: Stephen Berman <stephen.berman@gmx.net>

    Improve display of tabulated list header line labels (bug#44068)
    
    * lisp/emacs-lisp/tabulated-list.el (tabulated-list-init-header):
    Ensure sort indicator appears after the label of any selected
    sortable column that is wide enough and enable label truncation
    when narrowing a column.
    
    * lisp/emacs-lisp/timer-list.el (timer-list-mode): Improve column
    alignment.
    (timer-list--function-predicate): Correct typo in doc string.
---
 lisp/emacs-lisp/tabulated-list.el | 32 +++++++++++++++++++-------------
 lisp/emacs-lisp/timer-list.el     |  6 +++---
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/lisp/emacs-lisp/tabulated-list.el 
b/lisp/emacs-lisp/tabulated-list.el
index b13f609..3057767 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -269,42 +269,48 @@ Populated by `tabulated-list-init-header'.")
   ;; FIXME: Should share code with tabulated-list-print-col!
   (let ((x (max tabulated-list-padding 0))
        (button-props `(help-echo "Click to sort by column"
-                       mouse-face header-line-highlight
-                       keymap ,tabulated-list-sort-button-map))
+                                 mouse-face header-line-highlight
+                                 keymap ,tabulated-list-sort-button-map))
+        (len (length tabulated-list-format))
        (cols nil))
     (if display-line-numbers
         (setq x (+ x (tabulated-list-line-number-width))))
     (push (propertize " " 'display `(space :align-to ,x)) cols)
-    (dotimes (n (length tabulated-list-format))
+    (dotimes (n len)
       (let* ((col (aref tabulated-list-format n))
+             (not-last-col (< n (1- len)))
             (label (nth 0 col))
+             (lablen (length label))
+             (pname label)
             (width (nth 1 col))
             (props (nthcdr 3 col))
             (pad-right (or (plist-get props :pad-right) 1))
              (right-align (plist-get props :right-align))
              (next-x (+ x pad-right width)))
+        (when (and (>= lablen 3) (> lablen width) not-last-col)
+          (setq label (truncate-string-to-width label (- lablen 1) nil nil t)))
        (push
         (cond
          ;; An unsortable column
          ((not (nth 2 col))
-          (propertize label 'tabulated-list-column-name label))
+          (propertize label 'tabulated-list-column-name pname))
          ;; The selected sort column
          ((equal (car col) (car tabulated-list-sort-key))
           (apply 'propertize
-                 (concat label
-                         (cond
-                          ((> (+ 2 (length label)) width) "")
-                          ((cdr tabulated-list-sort-key)
+                  (concat label
+                          (cond
+                           ((and (< lablen 3) not-last-col) "")
+                           ((cdr tabulated-list-sort-key)
                             (format " %c"
                                     tabulated-list-gui-sort-indicator-desc))
-                          (t (format " %c"
+                           (t (format " %c"
                                       tabulated-list-gui-sort-indicator-asc))))
-                 'face 'bold
-                 'tabulated-list-column-name label
-                 button-props))
+                  'face 'bold
+                  'tabulated-list-column-name pname
+                  button-props))
          ;; Unselected sortable column.
          (t (apply 'propertize label
-                   'tabulated-list-column-name label
+                   'tabulated-list-column-name pname
                    button-props)))
         cols)
         (when right-align
diff --git a/lisp/emacs-lisp/timer-list.el b/lisp/emacs-lisp/timer-list.el
index 4bda9ac..024f003 100644
--- a/lisp/emacs-lisp/timer-list.el
+++ b/lisp/emacs-lisp/timer-list.el
@@ -95,8 +95,8 @@
   (setq-local revert-buffer-function #'list-timers)
   (setq tabulated-list-format
         '[("Idle" 6 timer-list--idle-predicate)
-          ("        Next" 12 timer-list--next-predicate)
-          ("      Repeat" 12 timer-list--repeat-predicate)
+          ("Next" 12 timer-list--next-predicate :right-align t :pad-right 1)
+          ("Repeat" 12 timer-list--repeat-predicate :right-align t :pad-right 
1)
           ("Function" 10 timer-list--function-predicate)]))
 
 (defun timer-list--idle-predicate (A B)
@@ -121,7 +121,7 @@
     (string< rA rB)))
 
 (defun timer-list--function-predicate (A B)
-  "Predicate to sort Timer-List by the Next column."
+  "Predicate to sort Timer-List by the Function column."
   (let ((fA (aref (cadr A) 3))
         (fB (aref (cadr B) 3)))
     (string< fA fB)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]