Reinventing the wheel 0

Posted by sjs
on Wednesday, June 20

Emacs is very impressive. I only felt lost and unproductive for minutes and now it seems natural to use and get around in. I’ve got ElSchemo set as the default scheme, and running inferior processes interactively is an absolute dream. My scheme doesn’t have readline support (which bothers me to the point where I’ve thought about adding it just so I can use the thing) but when running it under Emacs there’s absoutely no need for anything like that since I have the power of my editor when interacting with any program.

There has been a considerable amount of work done to aide in Rails development which makes Emacs especially comfortable for me. I now know why people have Emacs windows maximized on their screens. Because of its age Emacs is a handy window manager that basically eliminates the need for anything like GNU screen or a window manager such as Rat poison (which is great if you like screen), just maximize that Emacs “frame” or open one for each display and get to it. If you need a shell you just split the window and run your shell, when you’re done you can easily switch back to your editing and your shell will wait in the background until you need it again. With rails-mode on I can run script/console (or switch back to it) with C-c C-c s c. My zsh alias for script/console is sc and I have other similarly succint ones for other stuff, so I took right to the shortcuts for all the handy things that I no longer have to switch applications to do:

  • C-c C-c . – Run the tests for this file. If I’m in a unit test it runs it, if I’m in the model it runs the corresponding unit tests.
  • C-c C-c w s – Run the web server (script/server).
  • C-c C-c t – Run tests. The last value entered is the default choice, and the options are analogous to the rake test:* tasks.
  • and so on…

The Rails integration is simply stunning and I could go on all day about the mature indentation support, the Speedbar and what not, but I won’t. I’m fairly sure that Emacs has taken the place of TextMate as my weapon of choice now, on all platforms. And after only 2 days!

Anyway, the point of all this was to mention the one thing that’s missing: support for intelligent snippets which insert text at more than one point in the document (well, they appear to do so). I don’t have any E-Lisp-fu to break out and solve the deficiency but if it ever bugs me enough I might try implementing it for Emacs one day. If they were useful to me outside of writing migrations I might have more incentive to do so, but I guess they aren’t useful in normal editing situations (maybe I just haven’t recognised the need).

Intelligent Migration Snippets 0.1 for TextMate

Posted by sjs
on Tuesday, February 21

This should be working now. I’ve tested it under a new user account here.

This does requires the syncPeople bundle to be installed to work. That’s ok, because you should get the syncPeople on Rails bundle anyways.

 

When writing database migrations in Ruby on Rails it is common to create a table in the self.up method and then drop it in self.down. The same goes for adding, removing and renaming columns.

I wrote a Ruby program to insert code into both methods with a single snippet. All the TextMate commands and macros that you need are included.

See it in action

I think this looks cool in action. Plus I like to show off what what TextMate can do to people who may not use it, or don’t have a Mac. It’s just over 30 seconds long and weighs in at around 700kb.

Download Download Demo Video

Features

There are 3 snippets which are activated by the following tab triggers:

  • mcdt: Migration Create and Drop Table
  • marc: Migration Add and Remove Column
  • mnc: Migration Rename Column

Installation

Run Quick Install.app to install these commands to your syncPeople on Rails bundle if it exists, and to the default Rails bundle otherwise. (I highly recommend you get the syncPeople bundle if you haven’t already.)

Download Download Intelligent Migration Snippets

This is specific to Rails migrations, but there are probably other uses for something like this. You are free to use and distribute this code.

Some TextMate snippets for Rails Migrations 0

Posted by sjs
on Saturday, February 18

My arsenal of snippets and macros in TextMate is building as I read through the rails canon, Agile Web Development… I’m only 150 pages in so I haven’t had to add much so far because I started with the bundle found on the rails wiki. The main ones so far are for migrations.