0

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

Does GNU emacs have similar to equalize window sizes?

9
  • 3
    See: gnu.org/software/emacs/manual/html_node/emacs/… E.g., C-x + ["Make all windows the same height (balance-windows)."]
    – lawlist
    Commented Apr 5, 2023 at 19:38
  • 1
    @lawlist This is the answer so please make it an answer rather than a comment. Commented Apr 5, 2023 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.
    – oOosys
    Commented Apr 5, 2023 at 21:21
  • 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
    Commented Apr 5, 2023 at 21:49
  • 4
    Does this answer your question? 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
    Commented Apr 6, 2023 at 1:31

1 Answer 1

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

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.