From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: Making windows have same number of columns Date: Fri, 27 Nov 2020 16:37:38 +0100 Message-ID: <87360u7qv1.fsf@rub.de> References: <87wny8t89u.fsf@gmx.net> <87o8jkt0c0.fsf@gmx.net> <87k0u7udo1.fsf@gmx.net> <87czzzucqt.fsf@gmx.net> <878sanuafx.fsf@gmx.net> <871rgfu63v.fsf@gmx.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5713"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Help Gnu Emacs To: daniela-spit@gmx.it Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 27 16:39:53 2020 Return-path: Envelope-to: geh-help-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 1kifqh-0001Lu-Tw for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 27 Nov 2020 16:39:51 +0100 Original-Received: from localhost ([::1]:37712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kifqg-00027w-Rp for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 27 Nov 2020 10:39:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kifoi-00011o-W9 for help-gnu-emacs@gnu.org; Fri, 27 Nov 2020 10:37:49 -0500 Original-Received: from mout.gmx.net ([212.227.17.22]:38253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kifof-0004OC-MK for help-gnu-emacs@gnu.org; Fri, 27 Nov 2020 10:37:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1606491463; bh=lRNzUHghqedzkvIBSvNBRxW6t9ZMehd3507M/g/SRdI=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=cv4xgSntiRsr8lKEU1SqNdTWdEluFlOSINEiaU2TWaeSMuH3f7eskRQkdIE00Vmnw QJYGHr+5k8StLOJOmKKizsgQrAlZu6Szh6KyDPj4+j+Teu66i2p5nO/zpXQFXWYdOJ kOPxQBewU6gTxSDRO0onldqZ6j7upaK4BZ8h6Tvg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from strobe-jhalfs ([92.73.68.54]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N2mBQ-1k4Cio3WMm-0136Ly; Fri, 27 Nov 2020 16:37:42 +0100 In-Reply-To: <871rgfu63v.fsf@gmx.net> (Stephen Berman's message of "Thu, 26 Nov 2020 23:05:08 +0100") X-Provags-ID: V03:K1:sfXotmmFa+X1CiirA1VNC6TuXpyLMxSAiPM+ennRW42TVaIS3O5 CWN5lgmjbGoJe9ZDLPQN0ege1eB4AUtx8Tkdpg4nIPry8NC/FQxqfBiS+J4NSwdrUocghyu OgQJvbyhHxLWSFo1BrW3BZctPwmqnGwLyE26zTQoA0ky5I69hc5rG0sg4Vv0X/tWmHUs92O pm3Z1K2btCXeMXXtyHG7Q== X-UI-Out-Filterresults: notjunk:1;V03:K0:ZByX6vMBfr8=:XORaH0bZPAvPcTJTSgDUV+ YBH0zEFkNCE026seYCpVr+3iaWJXtJYFwbCkZtOmUqx1zK3t3tfkQ1CU3Sv7znCBdqNUZNWi+ lkSkNvpv97ojj5tJkKYXwg4hbfH2g8Rwwh9acSlUWTxcFDtLe18MKWQTHQWjCgm7bkKUOlgso YMucs01SFWMrQCN7AFc7DnI0m9DfzFUDTTEU8DJ3igbqSVcZYa5/A8vpn4ftHDSf6IFKikMlN o2GYrjK4VVBYxClWdas3iLL67keFA189Oto3extGL5FMzOIImf6mEOyOZcRz7x96HhA+Ky4EO UZM6FavtxtVWHEvkLD6a7StHRf6KWfMewXbobCmtfCvNM5vNvpJTUogNSiA2hSMdwA5TxRQ7A Jq2JqVClkjLa8jMaPsEcPfNm0l0mfHPPosTZIRnElxDtLbfy41cSOgZlSfkktEY6b8NDkV9jG WtlUq5aBKz06RCoXR7XFxeb51s2EUifiBgFH/iDNXDIqfk3ol4RdATB7RvI1s+yp6x8acBgaT gbgwVlFMsMqGmPm9iZkj4OqPcyyuNCrRdMFZn8gEWZ8wKMnkrvBu8tpqRB5ygiN5JZMzVO/vh m12Jnzuezu+7CsMkByXqb5Z26j18WgivtG6FZyXAni7WzZWX7DRXy/WPL2OC5H2y3XnYqb3po QghQZ48dlB4L5HoJ1XWn8QNWf6J9+uNV5xkvwXgfDj4W9khCOr5Gq/WOoumv+Cm9jkoioeSAd 92dN59MTn6N56s9BaXo1Wv1jZpGjlEJIbZe/7cEm8jNsBPlJ7gbEUS5PmTErMlDbYSRbPkjJ Received-SPF: pass client-ip=212.227.17.22; envelope-from=stephen.berman@gmx.net; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:125665 Archived-At: On Thu, 26 Nov 2020 23:05:08 +0100 Stephen Berman wrote: > On Thu, 26 Nov 2020 22:19:48 +0100 daniela-spit@gmx.it wrote: > >> A solution could be to make a defun that performs (text-scale-adjust -) >> until (window-body-width) is less than a number N. > > Instead of changing the window width, one at first sight plausible idea > is to check the column at the end the longest line in the buffer after > each application of text-scale-adjust; unfortunately, this doesn't work, > because using text-scale-adjust does not change how many columns a line > takes up: e.g., if the longest line ends at column 82 and > window-body-width is 72, then after apply text-scale-adjust until the > longest line appears to be shorter than 72, it still ends at column 82. > In other words, text-scale-adjust also adjusts the column width. So > that approach won't work. I can't think off hand of a way to get what > you want, but maybe someone else knows a way. I did think of a way after all: (defun srb-shrink-font () "Shrink font to make longest line fit in window width." (interactive) (save-excursion (let ((max 0) line) (goto-char (point-min)) (while (not (eobp)) (let* ((inhibit-field-text-motion t) (col (progn (end-of-line) (current-column)))) (when (> col max) (setq max col) (setq line (line-beginning-position))) (forward-line))) (goto-char line)) (let ((eol (line-end-position)) (eovl (lambda () (progn (end-of-visual-line) (point))))) (while (> eol (funcall eovl)) (let ((text-scale-mode-step 1.05)) (text-scale-decrease 1)))))) But I suspect there will be many cases where the result isn't really satisfying. You can experiment with text-scale-mode-step: in the above I let-bound it to the smallest value that seemed to work reasonably well, but sometimes it still seems to shrink the font too much and other times not enough. I think this has to do with the algorithm text-scale-adjust uses to change the size, using exponentiation, which means that sometimes the change will be too small for the available font sizes and other times too large. I also didn't implement the case of increasing the font size, because the only way I could think of to do that involves increasing too much and then decreasing again, which probably is visually annoying. Steve Berman