polishing ruby by ryan davis

New Category: Emacs

Published 2007-02-26 @ 18:29

Tagged emacs

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 ()
      (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 some_method_i_am_refactoring 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 ]