Setting An Emacs Per-System Height

Every time I start Emacs I have to adjust the frame size. That’s because my two main systems are a 15 inch MacBook Pro and a 27 inch iMac. In both cases I want the width to be 80 cols so I just set that with set-frame-width in my init.el file. I always ended up setting the height though because the MacBook can handle only 53 rows while the iMac can do 87. I finally got tired of that and added a bit of code to check the system name and set the height appropriately. I’m not even sure this is the best way of handling the problem but it’s simple and works. Here’s the code for anyone else who has a similar problem

(defconst jcs-system-heights '(("aineko" . 87) ("manfred" . 53)))
(let* ((system (car (split-string (system-name) "\\.")))
       (height (assoc system jcs-system-heights)))
  (when height
      (set-frame-height (selected-frame) (cdr height))))

Once you have the system name, you can make any other system-specific adjustments you need. If this init.el is used for another system (such as one of my servers), height will be nil and no action will be taken. If you are using Linux, you can probably get the same effect by setting the X-defaults; I couldn’t find a way of doing this for OS X.

This entry was posted in General and tagged . Bookmark the permalink.

8 Responses to Setting An Emacs Per-System Height

  1. Chris says:

    Since managing frames is the window manager’s job I leave this task to it, Openbox. It comes up so often that I set a keybinding, W-v, for vertically maximizing the current window, so I use this on Emacs all the time. Openbox can also position/resize/maximize specific application windows when they appear. I do this with my terminal emulator, Firefox, and Pidgin, but I’ve found it doesn’t work with Emacs, since it jerks the frame around too much during init (bringing the window up, then removing the menu bar, tool bar, and scroll bar).

  2. Haider says:

    You may want to look at x-display-pixel-width and -height functions, may be make for a more flexible solution. I have the following function, can’t recall where I got it from so can’t attribute correctly.

    ;; increase the frame size to cover the screen mostly
    (defun enlarge-frame ()
    “Enlarge the selected frame to fill a sizeable portion of the screen,
    based on the current screen resolution”
    (interactive)
    ;; Set the frame size
    ;; set the new width, with a little space on the sides
    (setq lframe-width (- (/ (x-display-pixel-width) (frame-char-width)) 20))
    ;; set the new height, allowing for title bars
    (setq lframe-height (- (/ (x-display-pixel-height) (frame-char-height)) 5))
    ;; apply to the selected frame
    (set-frame-size (selected-frame) lframe-width lframe-height))

  3. Mark Hepburn says:

    I don’t really need it much these days, but I have a snippet to load both a machine- and a OS-specific file, as an alternative to hard-coding their names in the config itself.
    https://github.com/markhepburn/dotemacs/blob/master/init.el#L43
    (ie, I can have linux-specific code, and code specific to one machine)

    Also, just looking at one reason I started doing that, you might want to look at maxframe-el.

  4. Les Harris says:

    Just wanted to say your Accelerando inspired system names made me smile!

  5. Chad says:

    The OSX version of Xdefaults is ‘defaults write org.gnu.Emacs Emacs.geometry -string “80×53″‘.

    You can also use something like “80×50+77-0″ , which starts Emacs 77 pixels from the left and at the bottom, and used named frames by setting Name.geometry instead of Emacs.geometry.

  6. Lee says:

    For OS X there is the display-usable-bounds function that will show you how big an area you have, taking into account things like the Dock and menu bar. The following code in my .emacs lets me modify the current frames and the default-frame-alist so any new frames have the correct size as well.


    (defun lh-get-height-max ()
    (- (/ (cadddr (display-usable-bounds))
    (frame-char-height))
    2))

    (defun lh-max-frames ()
    (interactive)
    (modify-all-frames-parameters (list (cons 'height (lh-get-height-max)))))

    (lh-max-frames)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>