diff options
author | Eli Zaretskii <eliz@gnu.org> | 2017-08-19 13:37:31 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2017-08-19 13:37:31 +0300 |
commit | 1e2fbb5e6345591cfe618fea90ac1ff8f82f3d33 (patch) | |
tree | 0731756c836ac365326ad215f0427fbdc8f78179 /lisp/emacs-lisp/tabulated-list.el | |
parent | 3baf2d840f90a86acd9c6180179e127d8e715897 (diff) | |
download | emacs-1e2fbb5e6345591cfe618fea90ac1ff8f82f3d33.tar.gz emacs-1e2fbb5e6345591cfe618fea90ac1ff8f82f3d33.tar.bz2 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)
Diffstat (limited to 'lisp/emacs-lisp/tabulated-list.el')
-rw-r--r-- | lisp/emacs-lisp/tabulated-list.el | 15 |
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." Populated by `tabulated-list-init-header'.") (defvar tabulated-list--header-overlay nil) +(defun tabulated-list-line-number-width () + "Return the width taken by display-line-numbers in the current buffer." + ;; line-number-display-width returns the value for the selected + ;; window, which might not be the window in which the current buffer + ;; is displayed. + (let ((cbuf-window (get-buffer-window (current-buffer)))) + (if (window-live-p cbuf-window) + (with-selected-window cbuf-window + (+ (line-number-display-width) 2)) + 4))) + (defun tabulated-list-init-header () "Set up header line for the Tabulated List buffer." ;; FIXME: Should share code with tabulated-list-print-col! @@ -195,7 +206,7 @@ Populated by `tabulated-list-init-header'.") keymap ,tabulated-list-sort-button-map)) (cols nil)) (if display-line-numbers - (setq x (+ x (line-number-display-width) 2))) + (setq x (+ x (tabulated-list-line-number-width)))) (push (propertize " " 'display `(space :align-to ,x)) cols) (dotimes (n (length tabulated-list-format)) (let* ((col (aref tabulated-list-format n)) @@ -413,7 +424,7 @@ of column descriptors." (ncols (length tabulated-list-format)) (inhibit-read-only t)) (if display-line-numbers - (setq x (+ x (line-number-display-width) 2))) + (setq x (+ x (tabulated-list-line-number-width)))) (if (> tabulated-list-padding 0) (insert (make-string x ?\s))) (let ((tabulated-list--near-rows ; Bind it if not bound yet (Bug#25506). |