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)

1 Answer 1


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.)

  • Sometimes, when I scale down, I see that the next line continuation marker gets displayed in the fringe.
    – Dilna
    Aug 21, 2022 at 2: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, 2022 at 2:37
  • The vanilla behavior is available with option text-scale-resize-window = nil.
    – Drew
    Aug 21, 2022 at 3: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, 2022 at 3: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, 2022 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.