unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ian Dunn <dunni@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Tabulated list recenter issue
Date: Wed, 12 Apr 2017 13:19:42 +0300	[thread overview]
Message-ID: <83h91uj5c1.fsf@gnu.org> (raw)
In-Reply-To: <87mvbm30lc.fsf@escafil> (message from Ian Dunn on Tue, 11 Apr 2017 20:56:31 -0400)

> From: Ian Dunn <dunni@gnu.org>
> Date: Tue, 11 Apr 2017 20:56:31 -0400
> 
> 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)

Regardless of whether this will be installed by default or as an
option, this code might behave unexpectedly when the entries are not
all of the same height, because AFAIU it counts the entries
disregarding their height.  Also, window-screen-lines might return a
fractional value, and I wonder whether the behavior will be correct
when the number of entries differs from the window height by less than
a whole line.



      parent reply	other threads:[~2017-04-12 10:19 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
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 [this message]

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=83h91uj5c1.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=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).