🕷 zenspider.com

by ryan davis

Looking for the Ruby Quickref?

Control your emacs frames programatically

Published 2007-02-27 @ 13:59

Tagged emacs

I use these two functions to set the frame (emacs parlance for top-level window) size and the display font:

  (defun arrange-frame (w h &optional nosplit)
    "Rearrange the current frame to a custom width and height and split unless prefix."
    (let ((frame (selected-frame)))
      (when (equal 'mac (framep frame))
        (set-frame-position frame 5 25)
        (set-frame-size frame w h)
        (if (not nosplit)
  (defun my-set-mac-font (name  size)
     (list (completing-read "font-name: "
                            (mapcar (lambda (p) (list (car p) (car p)))
                                    (x-font-family-list)) nil t)
           (read-number "size: " 12)))
    (set-face-attribute 'default nil
                        :family name
                        :slant  'normal
                        :weight 'normal
                        :width  'normal
                        :height (* 10 size))
    (frame-parameter nil 'font))

Then I have a bunch of functions like this to set my window as needed:

  (defun medium (&optional nosplit)
    "Create a large window suitable for coding on a macbook."
    (interactive "P")
    (my-set-mac-font "bitstream vera sans mono" 12)
    (arrange-frame 170 45 nosplit))
  (defun presentation ()
    "Create a giant font window suitable for doing live demos."
    (arrange-frame 85 25 t)
    (my-set-mac-font "bitstream vera sans mono" 24))