Recently in Emacs Category

emacs is über

| | Comments (2)

My current favorite emacs hack, thanks to SeanO. This extends find-file-at-point (which I have bound to C-x C-p) to automatically look a bit further for a line number and use it if available:

(defadvice find-file-at-point (around goto-line compile activate)
  (let ((line (and (looking-at ".*:\\([0-9]+\\)")
                   (string-to-number (match-string 1)))))
    ad-do-it
    (and line (goto-line line))))

I just released toggle.el, version 1.2 and autotest.el 1.0 beta 2.

Get them via: http://www.emacswiki.org/cgi-bin/wiki/RyanDavis

toggle.el

toggle.el allows you to quickly open corresponding files via a dynamic mapping. In this release I added some bug fixes and a mapping for rspec.

There are now 4 different mapping styles in this version: zentest, rails, rspec, and ruby. Feel free to submit more and I'll incorporate them.

Example Mapping (rspec style):

app/models/blah.rb      <-> spec/models.blah_spec.rb
app/controllers/blah.rb <-> spec/controllers/blah_spec.rb
app/views/blah.rb       <-> spec/views/blah_spec.rb
app/helpers/blah.rb     <-> spec/helpers/blah_spec.rb

autotest.el

autotest.el is a godsend for me. It runs all my tests inside emacs itself, providing hyperlinks in backtraces and the ability to quickly switch between the autotest output and the last buffer I was working in. The combination of autotest.el and autotest speeds me up tremendously.

toggle.el

| | Comments (0)

I just released toggle.el, allowing you to quickly open corresponding files via a dynamic mapping.

From the description:

This package provides the ability to quickly open a corresponding file for the current buffer by using a bi-directional mapping of regular expression pairs. You can select a mapping style from toggle-mapping-styles using the toggle-style function or set your default style via the toggle-mapping-style variable.

There are 3 different mapping styles in this version: zentest, rails, and ruby. Feel free to submit more and I'll incorporate them.

Example Mapping (ruby style):

blah.rb <-> test_blah.rb
lib/blah.rb <-> test/test_blah.rb

Get it (and other packages I'll release soon) via: http://www.emacswiki.org/cgi-bin/wiki/RyanDavis

autotest bindings

| | Comments (0)

I should add that I keep the previous autotest code in autotest.el and the following in my setup-modes.el (I have my emacs setup broken up):

(autoload 'autotest-switch "autotest" "doco" t)
(autoload 'autotest "autotest" "doco" t)
(add-hook 'ruby-mode-hook
          '(lambda ()
             (define-key ruby-mode-map (kbd "C-c C-a") 'autotest-switch))

This allows me to use C-c C-a to toggle back and forth between autotest and ruby files. I should also have it hooked in for grep buffers and other things, but I'll leave that as an exercise for the reader. :P

autotest for emacs

| | Comments (0)

I've been using this for a while now. It works pretty well for me, but I'm sure stuff could be ironed out and made a bit smoother/cleaner. Please provide any and all suggestions/patches as you see fit. This will be incorporated and eventually released with ZenTest once it feels good.

autotest.el behind the cut.

locate and spotlight

| | Comments (0)

locate and spotlight each have their pros and cons. I like both for different reasons, but recently I caught on to using mdfind (spotlight's command-line interface) to search for file-names only. It is still a little slower than locate (but not much) but always up to date:

(defun locate-make-mdfind-command-line (search-string)
  (list "mdfind" (concat "kMDItemDisplayName=*" search-string "*")))

(defun spotlight ()
  "Search for files by name using spotlight"
  (interactive)
  (let ((locate-command "mdfind")
        (locate-make-command-line 'locate-make-mdfind-command-line))
    (call-interactively 'locate nil)))

(defun spotlight-full ()
  "Search using spotlight"
  (interactive)
  (let ((locate-command "mdfind"))
    (call-interactively 'locate nil)))

If you're feeling adventurous, keep the first defun and set locate-command and locate-make-command-line via customize. I did that for a few weeks but I like the flexibility of having both available.

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 ]

great hacking tonight

| | Comments (1)

Tonight's Seattle.rb weekly hackfest featured Francis Hwang who is in Washington visiting his family this week. Good food and much fun was had. Eric Hodel and I did some bug squashing and feature implementing on ZenTest. We actually closed out every bug on ZenTest so I'll be releasing tomorrow!

I also wrote a small emacs library called toggle.el that lets you teach it a bunch of patterns so it can easily toggle between two related files. A simple example of that is "blah.rb and "test_blah.rb", but I've provided it with patterns to work with rubygems-style "lib/blah.rb" and "test/test_blah.rb" and rails-style "app/model/blah.rb" and "test/unit/blah_test.rb" as well. It is pretty clean and you can use it for any languages you want. I've been wanting this in emacs for a while and am surprised that I haven't found something like it yet (the reason I got on #emacs was "most people probably roll their own"). I'll be releasing that tomorrow as well.

About this Archive

This page is a archive of recent entries in the Emacs category.

MetaRuby is the next category.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.1