Harry R. Schwartz

Software engineer, nominal scientist, gentleman of the internet. Member, ←Hotline Webring→.

· 1B41 8F2C 23DE DD9C 807E A74F 841B 3DAE 25AE 721B

Opening Your Last Rails Migration in Emacs

Published 12 Mar 2014. Tags: emacs, rails.

I was pairing with a Vim user the other day, and I noticed that he had a nifty shortcut (from rails.vim?) to open up the last Rails migration.

Emacs being Emacs, I decided to implement it myself.

(defun visit-last-dired-file ()
  "Open the last file in an open dired buffer."

(defun visit-last-migration ()
  "Open the last file in 'db/migrate/'."
  (dired (expand-file-name "db/migrate" (projectile-project-root)))
  (kill-buffer "migrate"))

Just run that with M-x visit-last-migration and it’ll summon up your last migration. I haven’t bothered binding it to a key, since I don’t really need it that often.

It’s a bit of a hack, and it depends on projectile-mode, so if you have an alternate solution I’d sure appreciate an email or pull request!