2

How do I (or try to) set the window size (not the frame size) of an Emacs window to a specific value? I know of Emacs' functions for fitting to content but none allow me to set an exact height. I'm aware of the fact that I only can do this if there exists other windows along the dimensions I'm adjusting. I need this to automatically adapt the height in my compilation buffer (up to a certain threshold of course say 2/3 of the frame-height()) to the number of message lines outputted by the compiler/interpreter.

So far I have

  (balance-windows (get-buffer-window compilation-buffer))
  (fit-window-to-buffer (get-buffer-window compilation-buffer)
                        (/ (frame-height) 2))

but for some reason the first statement has no effect when the compilation window is small. That is the code works correctly when the compilation window is too large but not when it is to small.

Nordlöw
  • 11,838
  • 10
  • 52
  • 99

1 Answers1

3
  1. Get the current height of the window you want to change.
  2. Calculate the change needed from that current height: the delta.
  3. Pass the delta to enlarge-window.

E.g.,

(let* ((curr-ht  (window-height window))
       (delta    (- DESIRED-HEIGHT curr-ht)))
  (save-excursion
    (save-selected-window (select-window window)
                          (enlarge-window delta))))      
Drew
  • 29,895
  • 7
  • 74
  • 104