I'm fairly new to TextMate, and completely new to Snippets, so I may be asking something overly ambitious for a newbie. If so, I beg your indulgence ;)
I'm working on a snippet which will automate the creation of versioned tables, a la the acts_as_versioned plugin[1]. I've started with a tab trigger which will paste in the outer self.up and self.down definitions. Following the example in the "for ... in ... end" snippet, I've figured out how to have my specified table name repeated throughout all the appropriate places in the snippet. So all ready, what I've got is a huge key-stroke saver :) But obviously, an ideal snippet would go further yet.
Here's what I've got:
def self.up create_table :${1:table}s do |t| t.column :version, :int $0 end
${1/./\u$0/}.create_versioned_table do |t| t.column :${1:table}_id, :int t.column :version, :int
end end
def self.down drop_table :${1:table}s drop_table :${1:table}_versions end EOS
As you can see, the snippet currently fills in a couple of default columns for both my main table and its versioned partner. Is it possible to then begin typing in column definitions for the primary table (where the cursor currently ends at $0), and have those columns mirrored in the versioned table below?
Thanks in advance for any pointers someone can offer!
Gwendy
On 12/9/2006, at 15:13, gwendy wrote:
[...] As you can see, the snippet currently fills in a couple of default columns for both my main table and its versioned partner. Is it possible to then begin typing in column definitions for the primary table (where the cursor currently ends at $0), and have those columns mirrored in the versioned table below?
You may want to look at the existing Rails migration snippets.
However, to trigger a snippet in the “up” part and have that snippet mirror stuff int he (already created) “down” part, one need to instead make a command/macro which replace from the caret till the end of the document/up method with a snippet.
For more info I’d recommend you check out Duane Johnson’s articles on TextMate (he did all the Rails migration stuff and a lot of other cool stuff not bundled with TM): http://blog.inquirylabs.com/category/ textmate/
Allan Odgaard wrote:
However, to trigger a snippet in the �up� part and have that snippet mirror stuff int he (already created) �down� part, one need to instead make a command/macro which replace from the caret till the end of the document/up method with a snippet.
For more info I�d recommend you check out Duane Johnson�s articles on TextMate (he did all the Rails migration stuff and a lot of other cool stuff not bundled with TM): http://blog.inquirylabs.com/category/textmate/
Thanks for the tip and the link; this looks like a great starting point for figuring this stuff out!
gwendy
p.s. I just noticed that my subject line makes no sense for the current question. Sorry about that! I had originally started posting another question regarding string formatting, but had answered it before sending ;)