1

I often have multiple windows in emacs. I would like to have a function that modifies the width of a window to a certain value, then scales the text such that the longest line in the buffer fits the window leaving a small margin at the end (e.g. of two or three characters)

Dilna
  • 1,173
  • 3
  • 10

1 Answers1

0

Commands text-scale-decrease, text-scale-increase, and text-scale-adjust (bound to C-x C--, C-x C-+, C-x C-=, and C-x C-0) let you resize the text in the current buffer by changing its scale factor. When you shrink or enlarge the apparent text size this way, however, the window takes no notice of it. In particular, although shrinking text can result in extra horizontal space at the right, window commands do not see this space as extra.

If you use library face-remap+.el then you can do what you want, or at least something similar, which you can modify.

User option text-scale-resize-window lets you automatically resize the selected window (horizontally, vertically, or both) when text is resized, so that the way the window fits the buffer text remains relatively constant. Shrinking the text in one window shrinks that window, giving more space to adjacent windows.

If you also use library fit-frame.el, then one-window frames also respond to text resizing by scaling. If not, then the text-scale commands have no effect on frame size for one-window frames. (See also Shrink-Wrapping Frames.)

Drew
  • 75,699
  • 9
  • 109
  • 225
  • Sometimes, when I scale down, I see that the next line continuation marker gets displayed in the fringe. – Dilna Aug 21 '22 at 02:35
  • I also see that you have redefined the scaling commands. I am critical of such design, because the normal functionality has its use. – Dilna Aug 21 '22 at 02:37
  • The vanilla behavior is available with option `text-scale-resize-window` = `nil`. – Drew Aug 21 '22 at 03:12
  • Good. Have found a slight problem because `(require 'face-remap+)` seems to enable the resize feature. But most functionality, does not take effect simply by requiring a feature. – Dilna Aug 21 '22 at 03:54
  • Could you fix the situation where the resizing ends up continuing on next line, even when at first there is some space between the longest line and the window edge? – Dilna Aug 21 '22 at 03:58
  • Using the library is optional. Setting the option to nil, as I said, gives you vanilla behavior. – Drew Aug 21 '22 at 04:58
  • Have you noticed the line continuation effect? – Dilna Aug 21 '22 at 05:18