From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ian Dunn Newsgroups: gmane.emacs.devel Subject: Re: Tabulated list recenter issue Date: Tue, 11 Apr 2017 20:56:31 -0400 Organization: Silverblock Systems, Inc. Message-ID: <87mvbm30lc.fsf@escafil> References: <87h93dogki.fsf@escafil> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1491958864 5000 195.159.176.226 (12 Apr 2017 01:01:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 12 Apr 2017 01:01:04 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 12 03:01:00 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 1cy6ea-0001C1-LP for ged-emacs-devel@m.gmane.org; Wed, 12 Apr 2017 03:01:00 +0200 Original-Received: from localhost ([::1]:41714 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy6eg-0005sb-JV for ged-emacs-devel@m.gmane.org; Tue, 11 Apr 2017 21:01:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cy6dw-0005sV-Oz for emacs-devel@gnu.org; Tue, 11 Apr 2017 21:00:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cy6dq-0000gc-Nm for emacs-devel@gnu.org; Tue, 11 Apr 2017 21:00:20 -0400 Original-Received: from [195.159.176.226] (port=43148 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cy6dq-0000gI-GG for emacs-devel@gnu.org; Tue, 11 Apr 2017 21:00:14 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cy6dh-0000H9-DO for emacs-devel@gnu.org; Wed, 12 Apr 2017 03:00:05 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 56 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:sbMfyxIgSW1HfKbRL1a61f0RE9c= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 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:213889 Archived-At: --=-=-= Content-Type: text/plain > 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tabulated-list.el.diff 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) --=-=-= Content-Type: text/plain -- Ian Dunn --=-=-=--