From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gregory Heytings Newsgroups: gmane.emacs.bugs Subject: bug#57837: 29.0.50; fit-window-to-buffer should reposition the buffer Date: Thu, 15 Sep 2022 19:34:38 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34237"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 57837@debbugs.gnu.org To: Sam Steingold Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 15 21:35:30 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oYue1-0008YL-VA for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Sep 2022 21:35:30 +0200 Original-Received: from localhost ([::1]:43552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYue0-0001Hh-BC for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Sep 2022 15:35:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYudb-0001HP-4K for bug-gnu-emacs@gnu.org; Thu, 15 Sep 2022 15:35:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYuda-00038s-Sp for bug-gnu-emacs@gnu.org; Thu, 15 Sep 2022 15:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oYuda-0003Eo-4q for bug-gnu-emacs@gnu.org; Thu, 15 Sep 2022 15:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Gregory Heytings Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Sep 2022 19:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57837 X-GNU-PR-Package: emacs Original-Received: via spool by 57837-submit@debbugs.gnu.org id=B57837.166327048312414 (code B ref 57837); Thu, 15 Sep 2022 19:35:02 +0000 Original-Received: (at 57837) by debbugs.gnu.org; 15 Sep 2022 19:34:43 +0000 Original-Received: from localhost ([127.0.0.1]:59200 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYudG-0003EA-Qx for submit@debbugs.gnu.org; Thu, 15 Sep 2022 15:34:43 -0400 Original-Received: from heytings.org ([95.142.160.155]:43022) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYudE-0003E0-87 for 57837@debbugs.gnu.org; Thu, 15 Sep 2022 15:34:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=heytings.org; s=20220101; t=1663270478; bh=Q6q+MOrTNjV4tStrGHC6FxDqs1iq6GKWJCquPoKEb+A=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:From; b=RX2EbKiiYWJhrhr8Obt/sXXV1E7tUHy1MI0/ZIRIQmeR9duAszAmDsb7c+iApP7Qt ikg8IyQpVxm/5LCghKmDcWnkCG1UmJ3qPDrsEqzL3BRgatHXxj/aE3xPS3z2Ikx3Ir DDbBOIn4iC+mS+THwvfD9Y9wyZuTU8I5Y91axrDd5otyQe/TUovJJBLJIjnTPzI2BH i4tFId/8j/0/3T2w/cQLY9/iG73H+NXnD2tzRWpuFt1y2HixzqJb8YV15ZxpulWMLh 9vMelWimbnhPdAF7oRpmF0nInFOE15Se4alrmqqxduDoev9YGV4vRtcbPatTHP3aDA 47iDbz6Is/a/w== In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242638 Archived-At: > > When the buffer is smaller than the window, move the point to the end > and do `C-x w -` (fit-window-to-buffer). > > The window shrinks, but it is empty - the whole buffer is above. > Is that with emacs -Q? With emacs -Q the buffer is recentered after fit-window-to-buffer, and half of it (with your example) is visible. If you want to see the whole buffer in that case, you can one of the following lines to your init file: (advice-add 'fit-window-to-buffer :before (lambda () (or (< (point) (point-max)) (previous-line)))) (advice-add 'fit-window-to-buffer :after (lambda () (enlarge-window 1))) But that still does not guarantee that after fit-window-to-buffer the whole buffer will be visible, if you press C-l and repeat fit-window-to-buffer only the second half of the buffer is visible. If you want to handle that case as well, you can use this for example: (advice-add 'fit-window-to-buffer :after (lambda () (and (= (count-lines (point-min) (point-max)) (1- (window-height))) (or (< (point) (point-max)) (forward-line -1) t) (set-window-start nil (point-min))))) > > Basically, after `fit-window-to-buffer' is called, the following should > evaluate to t: > > (and (pos-visible-in-window-p (point-min)) > (pos-visible-in-window-p (point-max))) > That would only be possible under the condition you mention: "when the buffer is smaller than the window".