This post originated from an RSS feed registered with Ruby Buzz
by Ryan Davis.
Original Post: Control your emacs frames programatically
Feed Title: Polishing Ruby
Feed URL: http://blog.zenspider.com/index.rdf
Feed Description: Musings on Ruby and the Ruby Community...
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))
(delete-other-windows)
(set-frame-position frame 5 25)
(set-frame-size frame w h)
(if (not nosplit)
(split-window-horizontally)))))
(defun my-set-mac-font (name size)
(interactive
(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."
(interactive)
(arrange-frame 85 25 t)
(my-set-mac-font "bitstream vera sans mono" 24))