Emacs smart split for programmers

I spend most of my conscious hours in front of Emacs in a terminal window these days, and I share my configuration across all my computers. At work I have a huge monitor, so I split the emacs frame into 3 side-by-side 80-column windows. At home I have a smaller screen with room only enough for two windows. To share the same configuration file, I use the following snippet:

(defun smart-split ()
  "Split the frame into 80-column sub-windows, and make sure no window has
   fewer than 80 columns."
  (interactive)
  (defun smart-split-helper (w)
    "Helper function to split a given window into two, the first of which has 
     80 columns."
    (if (> (window-width w) (* 2 81))
    (let ((w2 (split-window w 82 t)))
      (smart-split-helper w2))))
  (smart-split-helper nil))

(smart-split)

The smart-split function split the emacs frame into a maximum number of 80-column windows. A very portable solution.

Comments 3

  1. Arun wrote:

    Thanks for this script. With more widescreen computers these days, it really doesn’t make sense to split vertically as emacs traditionally used to do.

    The smart thing about emacs is that the notifications will now respect the newly split arrangement. Truly ahead of its time :)

    Posted 13 Mar 2009 at 6:19 am
  2. hui wrote:

    I wonder why not use (ctrl x)+3 directly? I alway split emacs into two windows.

    Posted 29 Mar 2009 at 5:57 am
  3. j wrote:

    hui: because I have a larger screen ;-)

    Posted 31 Mar 2009 at 8:45 pm

Post a Comment

Your email is never published nor shared.