unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ian Dunn <dunni@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: Tabulated list recenter issue
Date: Tue, 11 Apr 2017 20:56:31 -0400	[thread overview]
Message-ID: <87mvbm30lc.fsf@escafil> (raw)
In-Reply-To: 87h93dogki.fsf@escafil

[-- Attachment #1: Type: text/plain, Size: 372 bytes --]


>   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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: tabulated-list.el.diff --]
[-- Type: text/x-diff, Size: 1355 bytes --]

diff --git a/lisp/emacs-lisp/tabulated-list.el b/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)

[-- Attachment #3: Type: text/plain, Size: 13 bytes --]


--
Ian Dunn

  reply	other threads:[~2017-04-12  0:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-01  2:51 Tabulated list recenter issue Ian Dunn
2017-04-12  0:56 ` Ian Dunn [this message]
2017-04-12  6:03   ` Eli Zaretskii
2017-04-12  6:25     ` Clément Pit-Claudel
2017-04-12  7:15       ` Eli Zaretskii
2017-04-12 12:28         ` Clément Pit-Claudel
2017-04-12 12:44           ` Eli Zaretskii
2017-04-12 13:11             ` Clément Pit-Claudel
2017-04-12 14:06               ` Eli Zaretskii
2017-04-12 15:13                 ` Clément Pit-Claudel
2017-04-13  1:10                 ` Ian Dunn
2017-04-13  6:17                   ` Eli Zaretskii
2017-04-15 21:02                     ` Ian Dunn
2017-04-12 10:19   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87mvbm30lc.fsf@escafil \
    --to=dunni@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).