aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2017-08-19 13:37:31 +0300
committerEli Zaretskii2017-08-19 13:37:31 +0300
commit1e2fbb5e6345591cfe618fea90ac1ff8f82f3d33 (patch)
tree0731756c836ac365326ad215f0427fbdc8f78179
parent3baf2d840f90a86acd9c6180179e127d8e715897 (diff)
downloademacs-1e2fbb5e6345591cfe618fea90ac1ff8f82f3d33.tar.gz
emacs-1e2fbb5e6345591cfe618fea90ac1ff8f82f3d33.zip
Improve support of display-line-numbers in tabulated-list-mode
* lisp/emacs-lisp/tabulated-list.el (tabulated-list-line-number-width): New function. (tabulated-list-init-header, tabulated-list-print-entry): Use it. (Bug#27895)
-rw-r--r--lisp/emacs-lisp/tabulated-list.el15
1 files changed, 13 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el
index 955b664b8c5..a0a74ce7f92 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -186,6 +186,17 @@ If ADVANCE is non-nil, move forward by one line afterwards."
186Populated by `tabulated-list-init-header'.") 186Populated by `tabulated-list-init-header'.")
187(defvar tabulated-list--header-overlay nil) 187(defvar tabulated-list--header-overlay nil)
188 188
189(defun tabulated-list-line-number-width ()
190 "Return the width taken by display-line-numbers in the current buffer."
191 ;; line-number-display-width returns the value for the selected
192 ;; window, which might not be the window in which the current buffer
193 ;; is displayed.
194 (let ((cbuf-window (get-buffer-window (current-buffer))))
195 (if (window-live-p cbuf-window)
196 (with-selected-window cbuf-window
197 (+ (line-number-display-width) 2))
198 4)))
199
189(defun tabulated-list-init-header () 200(defun tabulated-list-init-header ()
190 "Set up header line for the Tabulated List buffer." 201 "Set up header line for the Tabulated List buffer."
191 ;; FIXME: Should share code with tabulated-list-print-col! 202 ;; FIXME: Should share code with tabulated-list-print-col!
@@ -195,7 +206,7 @@ Populated by `tabulated-list-init-header'.")
195 keymap ,tabulated-list-sort-button-map)) 206 keymap ,tabulated-list-sort-button-map))
196 (cols nil)) 207 (cols nil))
197 (if display-line-numbers 208 (if display-line-numbers
198 (setq x (+ x (line-number-display-width) 2))) 209 (setq x (+ x (tabulated-list-line-number-width))))
199 (push (propertize " " 'display `(space :align-to ,x)) cols) 210 (push (propertize " " 'display `(space :align-to ,x)) cols)
200 (dotimes (n (length tabulated-list-format)) 211 (dotimes (n (length tabulated-list-format))
201 (let* ((col (aref tabulated-list-format n)) 212 (let* ((col (aref tabulated-list-format n))
@@ -413,7 +424,7 @@ of column descriptors."
413 (ncols (length tabulated-list-format)) 424 (ncols (length tabulated-list-format))
414 (inhibit-read-only t)) 425 (inhibit-read-only t))
415 (if display-line-numbers 426 (if display-line-numbers
416 (setq x (+ x (line-number-display-width) 2))) 427 (setq x (+ x (tabulated-list-line-number-width))))
417 (if (> tabulated-list-padding 0) 428 (if (> tabulated-list-padding 0)
418 (insert (make-string x ?\s))) 429 (insert (make-string x ?\s)))
419 (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). 430 (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506).