]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix subtle problems in tabulated-list-mode with line numbers
authorEli Zaretskii <eliz@gnu.org>
Sat, 4 Nov 2017 14:28:25 +0000 (16:28 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sat, 4 Nov 2017 14:28:25 +0000 (16:28 +0200)
* lisp/emacs-lisp/tabulated-list.el
(tabulated-list-watch-line-number-width): Call
tabulated-list-init-header instead of tabulated-list-revert.
(tabulated-list-window-scroll-function): New function.
(tabulated-list-mode): Put 'tabulated-list-window-scroll-function'
on the buffer-local 'window-scroll-functions' list.

lisp/emacs-lisp/tabulated-list.el

index 73ddadfb80582b0aefbc6d98c2daca06aff8495e..3889ba8e587a569e6077a25662df0c9ddea60092 100644 (file)
@@ -603,7 +603,16 @@ With a numeric prefix argument N, sort the Nth column."
       (let ((lnum-width (tabulated-list-line-number-width)))
         (when (not (= tabulated-list--current-lnum-width lnum-width))
           (setq-local tabulated-list--current-lnum-width lnum-width)
-          (tabulated-list-revert)))))
+          (tabulated-list-init-header)))))
+
+(defun tabulated-list-window-scroll-function (window _start)
+  (if display-line-numbers
+      (let ((lnum-width
+             (with-selected-window window
+               (line-number-display-width 'columns))))
+        (when (not (= tabulated-list--current-lnum-width lnum-width))
+          (setq-local tabulated-list--current-lnum-width lnum-width)
+          (tabulated-list-init-header)))))
 
 ;;; The mode definition:
 
@@ -654,7 +663,9 @@ as the ewoc pretty-printer."
   ;; the line-number width needs to change due to scrolling.
   (setq-local tabulated-list--current-lnum-width 0)
   (add-hook 'pre-redisplay-functions
-            #'tabulated-list-watch-line-number-width nil t))
+            #'tabulated-list-watch-line-number-width nil t)
+  (add-hook 'window-scroll-functions
+            #'tabulated-list-window-scroll-function nil t))
 
 (put 'tabulated-list-mode 'mode-class 'special)