Emacs Smart Split

I spend a lot of time in front of Emacs in a terminal window, and I share my configuration across all my computers. At work I have a large 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. Sometimes I just use the laptop display. 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."
  (cl-lables ((smart-split-helper (lambda (w)
                (if (> (window-width w) (* 2 81))
                  (let ((w2 (split-window w 82 t)))
                    (smart-split-helper w2))))))
    (smart-split-helper nil)))


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



Loading comments ...