Search code examples
emacsslime

Emacs / Slime / Hard Code Vertical Split Ratio


I'm currently in mode: C-x 2

Normally, I don't care much about vertical splitting. However, I'm coding on a 13" display, which makes vertical space rather precious.

I would like some setup where when I do C-x 2, my window is not split 50/50, but rather 70/30 [this way I can send the repl to the bottom portion of the screen, and stll see quite a bit of code.]

C-h a vertical split

brings up:

split-window-vertically, table-split-call-vertically

However, I suspect there is some parameter that changes / controls the split ratio.

What emacs option tells my computer to split 70/30 rather than 50/50?

Thanks!


Solution

  • You can use a prefix argument to tell Emacs how many lines to give each of the two windows.

    See: C-hk C-x2
    or C-hf split-window-below RET

    If optional argument SIZE is omitted or nil, both windows get the same height, or close to it. If SIZE is positive, the upper (selected) window gets SIZE lines. If SIZE is negative, the lower (new) window gets -SIZE lines.

    So you could give the upper window 20 lines and the lower window the remainder with: C-u 20 C-x2
    (or M-2M-0C-x2, etc...)

    And you could give the lower window 10 lines and the upper window the remainder with: C-u -10 C-x2
    (or M--M-1M-0C-x2, etc...)

    See How to change size of split screen emacs windows? for lots of ways to modify the size of windows after splitting.

    Edit:

    You can use the following function to do what you want:

    (defun my-split-window-below (&optional arg)
      "Split the current window 70/30 rather than 50/50.
    A single-digit prefix argument gives the top window arg*10%."
      (interactive "P")
      (let ((proportion (* (or arg 7) 0.1)))
        (split-window-below (round (* proportion (window-height))))))
    
    (global-set-key (kbd "C-c x 2") 'my-split-window-below)
    

    The default ratio is 70/30, but you can supply a single-digit prefix argument to specify the size of the top window in 10% increments.

    If you bound this command to C-x2 then C-9C-x2 would give the top window 90% and the bottom 10%.


    Edit 2: I ended up using a variation of that as my own C-x2 binding. This version defaults to a normal 50/50 split, but provides the same prefix arg functionality of the other function in case I want something different.

    (defun my-split-window-below (&optional arg)
      "Split the current window 50/50 by default.
    A single-digit prefix argument gives the top window ARG * 10%
    of the available lines."
      (interactive "P")
      (let* ((proportion (and arg (* arg 0.1)))
             (size (and proportion (round (* proportion (window-height))))))
        (split-window-below size)))