[TxMt] String Formatting and TM Snippets

gwendy gwendy at mag3.14159.ca
Tue Sep 12 13:13:01 UTC 2006


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



[1] http://ar-versioned.rubyforge.org/



More information about the textmate mailing list