4
votes

(I use the words "window" and "frame" in the same way the Emacs manual uses them.)

I like to split my Emacs frame vertically when I work because I like to see two buffers side-by-side. Since I have a small screen and I prefer a larger than usual font size, neither of the windows is large enough to show me even 80 characters per line. As I switch between windows, I find myself having to fiddle with their sizes to prevent my code from wrapping.

Is there a way Emacs can automatically make the currently active window at least 80 characters wide? I want that, whenever I switch to a window, Emacs should resize it in a way that I can comfortably see my code on a single line.

E.g, let's say this is the original split:

     ____________________
    |          |         |
    |          |         |
    |          |         |
    |          |         |
    |          |         |
    |          |         |
    |          |         |
     --------------------

Now I move my insertion point to the left window. Emacs should resize the window so that the setup looks like this:

     ____________________
    |             |      |
    |             |      |
    |             |      |
    |insertion    |      |
    |point        |      |
    |             |      |
    |             |      |
     --------------------

I've done editing the buffer in the left window. Now I move my insertion point to the right window. Emacs should resize the window so it looks like this:

     ____________________
    |       |           |
    |       |           |
    |       |           |
    |       |insertion  |
    |       |point      |
    |       |           |
    |       |           |
     --------------------

I'm certain I've seen some elisp that does exactly this, but I can't figure out the right incantations I should put into the Google Search box.

1

1 Answers

7
votes

Assuming you're using other-window (bound to C-x o by default) to switch between windows you can simply advice it like this:

(defadvice other-window (after other-window-now activate)
  (when (< (window-width) 80)
    (enlarge-window (- 80 (window-width)) t)))

That would automatically enlarge a window by (80 - it's current width columns), making it 80 columns wide.