[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making windows have same number of columns
From: |
Stephen Berman |
Subject: |
Re: Making windows have same number of columns |
Date: |
Fri, 27 Nov 2020 16:37:38 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
On Thu, 26 Nov 2020 23:05:08 +0100 Stephen Berman <stephen.berman@gmx.net>
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
- Re: Making windows have same number of columns, (continued)
- Re: Making windows have same number of columns, Stephen Berman, 2020/11/26
- Re: Making windows have same number of columns, daniela-spit, 2020/11/26
- Re: Making windows have same number of columns, Stephen Berman, 2020/11/26
- Re: Making windows have same number of columns, daniela-spit, 2020/11/26
- Re: Making windows have same number of columns, Stephen Berman, 2020/11/26
- RE: Making windows have same number of columns, Drew Adams, 2020/11/26
- Re: RE: Making windows have same number of columns, daniela-spit, 2020/11/26
- Re: RE: Making windows have same number of columns, daniela-spit, 2020/11/26
- RE: RE: Making windows have same number of columns, Drew Adams, 2020/11/26
- Re: Making windows have same number of columns, daniela-spit, 2020/11/26
- Re: Making windows have same number of columns,
Stephen Berman <=
- Re: Making windows have same number of columns, daniela-spit, 2020/11/26
- Re: Making windows have same number of columns, Michael Heerdegen, 2020/11/27
- Re: Making windows have same number of columns, daniela-spit, 2020/11/26