[Top][All Lists]

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

Re: Tabulated list recenter issue

From: Ian Dunn
Subject: Re: Tabulated list recenter issue
Date: Tue, 11 Apr 2017 20:56:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

>   If moving the window to keep the current entry at the same line would leave
> blank space at the end of the window, don't move the window, but keep point on
> the current entry.

I made this modification and tried it out on ENWC and the Package List.

I'd like to apply this to master, but, since it will affect the Package List, I 
want to get feedback on it first.

diff --git a/lisp/emacs-lisp/tabulated-list.el 
index b6b49b1bfa..57dca910a8 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -395,10 +395,21 @@ changing `tabulated-list-sort-key'."
     (set-buffer-modified-p nil)
     ;; If REMEMBER-POS was specified, move to the "old" location.
     (if saved-pt
-       (progn (goto-char saved-pt)
-              (move-to-column saved-col)
-              (when window-line
-                 (recenter window-line)))
+       (let* ((lines (window-screen-lines))
+               (id (tabulated-list-get-id saved-pt))
+               (entries (if (functionp tabulated-list-entries)
+                            (funcall tabulated-list-entries)
+                          tabulated-list-entries))
+               (position (seq-position (map-keys entries) id))
+               (num-entries (length entries))
+               (remaining-entries (- num-entries position)))
+          (goto-char saved-pt)
+          (move-to-column saved-col)
+          ;; Only recenter if there are enough lines so that there's no empty
+          ;; space below the end of the text
+          (when (and window-line
+                     (> remaining-entries lines))
+            (recenter window-line)))
       (goto-char (point-min)))))
 (defun tabulated-list-print-entry (id cols)
Ian Dunn

reply via email to

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