diff options
| author | Stephen Berman | 2020-11-04 23:52:21 +0100 |
|---|---|---|
| committer | Stephen Berman | 2020-11-04 23:52:21 +0100 |
| commit | 233d350d1984bcb4e0f636ddfa29482b815fa2f2 (patch) | |
| tree | 4b49df4b5b339a347bd9fba187de7f7771681dce | |
| parent | 1c9500da6615ecaa6e7a5029e0f5d0200d66e7ef (diff) | |
| download | emacs-233d350d1984bcb4e0f636ddfa29482b815fa2f2.tar.gz emacs-233d350d1984bcb4e0f636ddfa29482b815fa2f2.zip | |
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.
| -rw-r--r-- | lisp/emacs-lisp/tabulated-list.el | 32 | ||||
| -rw-r--r-- | 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 b13f609f882..30577679f24 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'.") | |||
| 269 | ;; FIXME: Should share code with tabulated-list-print-col! | 269 | ;; FIXME: Should share code with tabulated-list-print-col! |
| 270 | (let ((x (max tabulated-list-padding 0)) | 270 | (let ((x (max tabulated-list-padding 0)) |
| 271 | (button-props `(help-echo "Click to sort by column" | 271 | (button-props `(help-echo "Click to sort by column" |
| 272 | mouse-face header-line-highlight | 272 | mouse-face header-line-highlight |
| 273 | keymap ,tabulated-list-sort-button-map)) | 273 | keymap ,tabulated-list-sort-button-map)) |
| 274 | (len (length tabulated-list-format)) | ||
| 274 | (cols nil)) | 275 | (cols nil)) |
| 275 | (if display-line-numbers | 276 | (if display-line-numbers |
| 276 | (setq x (+ x (tabulated-list-line-number-width)))) | 277 | (setq x (+ x (tabulated-list-line-number-width)))) |
| 277 | (push (propertize " " 'display `(space :align-to ,x)) cols) | 278 | (push (propertize " " 'display `(space :align-to ,x)) cols) |
| 278 | (dotimes (n (length tabulated-list-format)) | 279 | (dotimes (n len) |
| 279 | (let* ((col (aref tabulated-list-format n)) | 280 | (let* ((col (aref tabulated-list-format n)) |
| 281 | (not-last-col (< n (1- len))) | ||
| 280 | (label (nth 0 col)) | 282 | (label (nth 0 col)) |
| 283 | (lablen (length label)) | ||
| 284 | (pname label) | ||
| 281 | (width (nth 1 col)) | 285 | (width (nth 1 col)) |
| 282 | (props (nthcdr 3 col)) | 286 | (props (nthcdr 3 col)) |
| 283 | (pad-right (or (plist-get props :pad-right) 1)) | 287 | (pad-right (or (plist-get props :pad-right) 1)) |
| 284 | (right-align (plist-get props :right-align)) | 288 | (right-align (plist-get props :right-align)) |
| 285 | (next-x (+ x pad-right width))) | 289 | (next-x (+ x pad-right width))) |
| 290 | (when (and (>= lablen 3) (> lablen width) not-last-col) | ||
| 291 | (setq label (truncate-string-to-width label (- lablen 1) nil nil t))) | ||
| 286 | (push | 292 | (push |
| 287 | (cond | 293 | (cond |
| 288 | ;; An unsortable column | 294 | ;; An unsortable column |
| 289 | ((not (nth 2 col)) | 295 | ((not (nth 2 col)) |
| 290 | (propertize label 'tabulated-list-column-name label)) | 296 | (propertize label 'tabulated-list-column-name pname)) |
| 291 | ;; The selected sort column | 297 | ;; The selected sort column |
| 292 | ((equal (car col) (car tabulated-list-sort-key)) | 298 | ((equal (car col) (car tabulated-list-sort-key)) |
| 293 | (apply 'propertize | 299 | (apply 'propertize |
| 294 | (concat label | 300 | (concat label |
| 295 | (cond | 301 | (cond |
| 296 | ((> (+ 2 (length label)) width) "") | 302 | ((and (< lablen 3) not-last-col) "") |
| 297 | ((cdr tabulated-list-sort-key) | 303 | ((cdr tabulated-list-sort-key) |
| 298 | (format " %c" | 304 | (format " %c" |
| 299 | tabulated-list-gui-sort-indicator-desc)) | 305 | tabulated-list-gui-sort-indicator-desc)) |
| 300 | (t (format " %c" | 306 | (t (format " %c" |
| 301 | tabulated-list-gui-sort-indicator-asc)))) | 307 | tabulated-list-gui-sort-indicator-asc)))) |
| 302 | 'face 'bold | 308 | 'face 'bold |
| 303 | 'tabulated-list-column-name label | 309 | 'tabulated-list-column-name pname |
| 304 | button-props)) | 310 | button-props)) |
| 305 | ;; Unselected sortable column. | 311 | ;; Unselected sortable column. |
| 306 | (t (apply 'propertize label | 312 | (t (apply 'propertize label |
| 307 | 'tabulated-list-column-name label | 313 | 'tabulated-list-column-name pname |
| 308 | button-props))) | 314 | button-props))) |
| 309 | cols) | 315 | cols) |
| 310 | (when right-align | 316 | (when right-align |
diff --git a/lisp/emacs-lisp/timer-list.el b/lisp/emacs-lisp/timer-list.el index 4bda9acebf7..024f0030629 100644 --- a/lisp/emacs-lisp/timer-list.el +++ b/lisp/emacs-lisp/timer-list.el | |||
| @@ -95,8 +95,8 @@ | |||
| 95 | (setq-local revert-buffer-function #'list-timers) | 95 | (setq-local revert-buffer-function #'list-timers) |
| 96 | (setq tabulated-list-format | 96 | (setq tabulated-list-format |
| 97 | '[("Idle" 6 timer-list--idle-predicate) | 97 | '[("Idle" 6 timer-list--idle-predicate) |
| 98 | (" Next" 12 timer-list--next-predicate) | 98 | ("Next" 12 timer-list--next-predicate :right-align t :pad-right 1) |
| 99 | (" Repeat" 12 timer-list--repeat-predicate) | 99 | ("Repeat" 12 timer-list--repeat-predicate :right-align t :pad-right 1) |
| 100 | ("Function" 10 timer-list--function-predicate)])) | 100 | ("Function" 10 timer-list--function-predicate)])) |
| 101 | 101 | ||
| 102 | (defun timer-list--idle-predicate (A B) | 102 | (defun timer-list--idle-predicate (A B) |
| @@ -121,7 +121,7 @@ | |||
| 121 | (string< rA rB))) | 121 | (string< rA rB))) |
| 122 | 122 | ||
| 123 | (defun timer-list--function-predicate (A B) | 123 | (defun timer-list--function-predicate (A B) |
| 124 | "Predicate to sort Timer-List by the Next column." | 124 | "Predicate to sort Timer-List by the Function column." |
| 125 | (let ((fA (aref (cadr A) 3)) | 125 | (let ((fA (aref (cadr A) 3)) |
| 126 | (fB (aref (cadr B) 3))) | 126 | (fB (aref (cadr B) 3))) |
| 127 | (string< fA fB))) | 127 | (string< fA fB))) |