Mon, 19 Jun 2006

Make Emacs take the full screen height

I’ve been on a rather serious Emacs kick lately. One of the things that always frustrated me a little bit about EMACS is that the X11 variant wouldn’t make itself the full size of the monitor at start up without help from the window manager. This is fine and all; after all, I could always make the window manager do the right thing. At least until now.

Now, I use Carbon Emacs most of the time, and MacOS X doesn’t let you muck around with the window manager. However, after a bit of digging, I figured out how to make Emacs re-size the initial window (in emacs-speak, the initial frame):

; Put initial frame at the top left of the screen and make it full
; height, assuming we're not in a terminal.
(if window-system
     (set 'initial-frame-alist
          ; Check out the elisp documentation on Backquote to
          ; understand the `( ,() ) construct.
          `((left . 0) (top . 0)
          ; This attempts to automatically determine the emacs frame
          ; height by computing it from the screen resolution.  We
          ; subtract 3 chars to account for the minibuffer and window
          ; decorations.
            (height . ,(- (/ (x-display-pixel-height) (frame-char-height)) 
                          3)))))

There you have it. That only took me 4 hours to figure out. The tricky part was understanding the backquote notation (it lets you have a quoted lisp structure that you can “un-quote” parts of in order to have them be evaluated). Now that I have shared this information, of course, I feel better about spending the time on it. Besides, I get happy every time my emacs starts up and then makes itself the right size, as if by magic!

[/hacks] permanent link