textmate ruby snippet to yasnippet
posted by hitesh on 2008-08-11
Dr. Nic recently put together a screencast of adding a Ruby snippet to TextMate. This particular snippet makes a class definition using the filename as the default classname. I always enjoy listening to Dr. Nic, so definitely check out the 'cast.
I used to love TextMate, but I can't use it anymore since I'm working on multiple platforms. Emacs is my editor of choice now and I can't say that I'm missing anything.
Dr. Nic's example was interesting enough that I decided to replicate it using yasnippet and elisp. As you'll see in the video, TextMate supports shelling out to bash or Ruby to do complex processing of snippets. Yasnippet supports inline elisp to handle complex snippets and allows shelling out to other processes when necessary.
Usage
If you're editing a file named foo.rb and use the snippet, it will create a class definition for Foo. If you're editing a file named currency_converter.rb, it will create a class named CurrencyConverter.
Installation
Put the following code into a file named kls in the ruby-mode directory. Then use it like you would any other yasnippet.
#name : class ... end
#contributor : hitesh <hitesh.jasani@gmail.com>
# --
class ${1:$
(let ((fn (capitalize (file-name-nondirectory
(file-name-sans-extension
(buffer-file-name))))))
(cond
((string-match "_" fn) (replace-match "" nil nil fn))
(t fn)))}
$0
end
Referrers
- http://www.reddit.com/r/ruby/
- http://www.google.com/reader/view/
- http://www.artima.com/forums/flat.jsp?forum=123&thread=236339
- http://www.artima.com/buzz/community.jsp?forum=123
- http://www.reddit.com/
- http://www.google.com/search?q=yasnippet&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
- http://swik.net/snippets+Emacs
- http://www.reddit.com/r/ruby
- http://reddit.com/r/ruby/
- http://search.live.com/results.aspx?q=textmate
About
Hitesh wrote his first program on a punch card in 1979 ... he's been debugging it ever since.