I’ve made a patch to improve the ruby-electric-mode for Emacs. If you use Emacs to edit Ruby code, please try it out and tell me what you think!
I’ve created a patch to the ruby-electric-mode for Emacs, which makes pressing return after certain keywords automatically
insert an “end” statement, just like pressing space does.
So, if you type this:
when you press return, it will become:
It will put the cursor on the line between “begin” and “end” and automatically indent, so you can
start typing more code right away!
It will work with the other keywords that electric-space does, too. For example, when writing RSpec, you can type:
it "should be empty" do
and then press return, it will insert the “end” for you.
Before, you would have to press space and then return, which seemed unnatural to me. However, I have made
ruby-electric-return smart enough not to work against you if you have the habit of doing space and then return: it will
only insert the “end” if you press return with the cursor directly after the keyword.
Also, I added a customizable variable, “ruby-electric-return”, which can be used to disable this feature if
you don’t like it. I made it on by default, but I won’t be offended if you change the patch (line 7) to make it off
by default instead.
I welcome any suggestions or comments.