From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Tabulated list recenter issue Date: Wed, 12 Apr 2017 13:19:42 +0300 Message-ID: <83h91uj5c1.fsf@gnu.org> References: <87h93dogki.fsf@escafil> <87mvbm30lc.fsf@escafil> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1491992374 1655 195.159.176.226 (12 Apr 2017 10:19:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 12 Apr 2017 10:19:34 +0000 (UTC) Cc: emacs-devel@gnu.org To: Ian Dunn Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 12 12:19:30 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cyFN3-0000Jv-UA for ged-emacs-devel@m.gmane.org; Wed, 12 Apr 2017 12:19:30 +0200 Original-Received: from localhost ([::1]:43346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyFN9-0006fo-Ox for ged-emacs-devel@m.gmane.org; Wed, 12 Apr 2017 06:19:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59332) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyFN4-0006ff-H1 for emacs-devel@gnu.org; Wed, 12 Apr 2017 06:19:31 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cyFMz-00068w-G4 for emacs-devel@gnu.org; Wed, 12 Apr 2017 06:19:30 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:41644) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cyFMz-00068q-Ch for emacs-devel@gnu.org; Wed, 12 Apr 2017 06:19:25 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3330 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cyFMx-00078L-NN; Wed, 12 Apr 2017 06:19:24 -0400 In-reply-to: <87mvbm30lc.fsf@escafil> (message from Ian Dunn on Tue, 11 Apr 2017 20:56:31 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:213902 Archived-At: > From: Ian Dunn > 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.