Emacs: February 2007 Archives

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))

New Category: Emacs

| | Comments (0)

I'm an emacs freak. I've been an emacs freak for... forever... no, since 1991. Anyhow, I've been continually evolving my emacs setup (under revision control) since 1996 and am always looking for things to increase my productivity without being too heavyweight. I'll share what I can here. I'll start with one of my new favorites:

(define-key isearch-mode-map (kbd "C-o")
  (lambda ()
    (interactive)
    (let ((case-fold-search isearch-case-fold-search))
      (occur (if isearch-regexp isearch-string
               (regexp-quote isearch-string))))))

This adds an extra keybinding to interactive search (C-s) that runs occur on the current search string/regexp, immediately showing all hits in the entire buffer. I use it all the time now. Example:

C-M-s ^ *\(class\|module\|def\) C-o

quickly gives me an index of the entire file:

24 matches for "^ *\(class\|module\|def\)" in buffer: autotest.rb
     57:class Autotest
     61:  def self.run
     67:  def initialize
     77:  def run
     ... and so on ...

and C-s somemethodiamrefactoring C-o

immediately shows me all the call points of the method I'm planning to refactor.

[edit: from http://www.emacswiki.org/cgi-bin/wiki/OccurFromIsearch ]