0

tmux has ctrl b, shift e, to equalize pane sizes.

Does GNU emacs have similar to equalize window sizes?

Claudio
  • 410
  • 2
  • 11
digit
  • 101
  • 2
  • 3
    See: https://www.gnu.org/software/emacs/manual/html_node/emacs/Change-Window.html E.g., `C-x +` ["*Make all windows the same height (`balance-windows`).*"] – lawlist Apr 05 '23 at 19:38
  • 1
    @lawlist This is the answer so please make it an answer rather than a comment. – Fran Burstall Apr 05 '23 at 20:31
  • @NickD : no I haven't tried it. Just checked out the documentation telling it equalizes only the windows heights. But it seems not to be true. – Claudio Apr 05 '23 at 21:21
  • @FranBurstall : an answer is there and provides as an add-on the feature of toggling between horizontal and vertical orientation in case of exactly two windows. – Claudio Apr 05 '23 at 21:30
  • It is considered good form to wait for @lawlist to provide an answer (or to state that he won't) before providing your answer (even with your emendations). And in any case, you need to [acknowledge](https://emacs.stackexchange.com/help/referencing) your sources. – NickD Apr 05 '23 at 21:41
  • 1
    @NickD -- I'm usually pretty busy with work and so forth. In the context of this particular question, it would be necessary for me (or someone else) to Google and search this site to see if there are similar or same questions with answers already in existence. If there are no duplicate questions with answers already in existence, then the answer by "Claudio" is okay. – lawlist Apr 05 '23 at 21:49
  • I suspected as much, but @Claudio is a new user so a reminder about how to operate on this site wouldn't be amiss. – NickD Apr 05 '23 at 21:57
  • @NickD: by the way: the comment by *lawlist* has prevented me from trying `balanced-windows` because it suggests the function makes only same heights not widths. Probably it would be even better to delete it, even if it is a hint in the right direction. Pointing to the documentation is also misleading - it was waste of time to look there for balancing the widths. That's the reason for my first version of the answer. Than you asked to try it out ... and it turned out to be the right hint so it became necessary to update the answer. – Claudio Apr 05 '23 at 22:19
  • 4
    Does this answer your question? [How to Change size of split screen emacs windows?](https://emacs.stackexchange.com/questions/582/how-to-change-size-of-split-screen-emacs-windows) The question might sound the opposite of what you want but the accepted answer answers your question (and more). – NickD Apr 06 '23 at 01:31

1 Answers1

1

Question: Which command in GNU emacs resizes windows to equal sizes?

Answer: balance-windows

With "C-h f" balance-windows you can view the entire documentation of it. Here an excerpt:

balance-windows is an interactive byte-compiled Lisp function in ‘window.el’.

It is bound to C-x +.

And please don't care about the documentation stating that it balances only the heights of the windows because it balances also the widths.

In addition to the in Emacs available functionality you can also use the code below code which although covers only the case of exactly two windows, but provides next to the feature of making the windows the same size the option to toggle between the horizontal and vertical way of splitting. In other words if you use the code below you need in order to equalize the size of the windows keeping the orientation to run it twice:

;; ----------------------------------------------------------------------
;;  M-x -> t-w-sp : toggle two windows from horizontal to vertical split:
(defun toggle-window-split ()
  " Toogle two window split between horizontal and vertical " 
  (interactive)
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
             (next-win-buffer (window-buffer (next-window)))
             (this-win-edges (window-edges (selected-window)))
             (next-win-edges (window-edges (next-window)))
             (this-win-2nd (not (and (<= (car this-win-edges)
                                         (car next-win-edges))
                                     (<= (cadr this-win-edges)
                                         (cadr next-win-edges)))))
             (splitter
              (if (= (car this-win-edges)
                     (car (window-edges (next-window))))
                  'split-window-horizontally
                'split-window-vertically)))
        (delete-other-windows)
        (let ((first-win (selected-window)))
          (funcall splitter)
          (if this-win-2nd (other-window 1))1
          (set-window-buffer (selected-window) this-win-buffer)
          (set-window-buffer (next-window) next-win-buffer)
          (select-window first-win)
          (if this-win-2nd (other-window 1))))))
Claudio
  • 410
  • 2
  • 11