How to make Emacs automatically reindent Ruby code on the fly?
for example, with this in Emacs,
def hello
puts "hello"
en
After I type 'd', I want it to turn into this,
def hello
puts "hello"
end
This is the default in Vim, but how can I achieve that in Emacs?
ruby-electric
is old news. Emacs 24 has a built-in minor mode called electric-indent-mode
that automatically inserts newlines after some chars and you can of course remap the RETURN
key to newline-and-indent
(it's mapped only to indent by default). In Emacs 24 you can get matching delims with electric-pairs-mode
and ruby-end
mode will insert automatically end
for you when needed. You can have a look at the prelude-ruby.el for more details.
If you add ruby-electric (also part of Rinari) you get the following:
If you don't want to add extra modes, the end
will be indented correctly once you press Enter. Or you press Tab to re-indent the current line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With