Emacs is my favorite text editor. I have been used Emacs for 8 months. And recently I’m learning Ruby on Rails following the Ruby on Rails Tutorial written by Michael Hartl.
Here is my Emacs tricks for programming Rails:
Shortcut For Inserting Arrows
There are so many hash rockets. It’s a good practise to bind some key to insert it handy.
1 2 3 4 5 6 7 8
Ruby 1.9 added a new syntax for hashes.
Modify Ruby Syntax
mark-multipleto highlight symbols/variables in the buffer. But I found it can’t distinguish the four types of scoped variable. This can be solved by modify the syntax table.
1 2 3 4
I also use
auto-complete to complete symbols/variables. Some times, I say
then I want auto-complete the reset of
newer_micropost. So I press
TAB, oops! nothing completed.
That’s because the punctuation character
: had been declared to be a part of a word. It means that the
:newer_micropost and the
newer_micropost are two independent words. Yes, they are. But what I want is they should be completed by the
auto-complete. This can be accomplished by a little hacky fragment:
1 2 3
hs-minor-modeto fold/unfold blocks, add following snippet to support ruby block syntax.
1 2 3 4
Outline-mode is a good choice too.
1 2 3 4
Actually, I don’t use fold/unfold frequently, I have no idea which is a better solution. Any other good folding add-on?
YARI(Yet Another Ri Interface) provides an Emacs frontend to Ruby’s
ridocumentation tool. It offers lookup and completion. It’s a good practice to bind a help-command for call YARI handy.
Now you can just type
C-h R to call yari anywhere. Yari will show
ri in Ido-style. It also support Anything-style, but
Anything had renamed to Helm, you should add some snippet to support ‘Helm-style’
1 2 3 4 5 6 7
Rinari Is Not A Ruby IDE. Must have add-on.
The forgotten TextMate
TextMate is a minor mode to mimick the TextMate’s awesome. It’s quite common used to navigate between project files. The
⌘is bound to
Meta(Alt)on the Ubuntu.
Other useful add-ons
Ruby tools is a collection of handy functions for Emacs ruby-mode.
Ruby block will show you which block you are in. Since there are too many
describe blocks in rspec, this will be helpful.
1 2 3 4
PS: More tips are welcome!