Patches: Browse | Submit New | Admin

[#19503] Emacs ruby electric mode: ruby-electric-return

Date:
2008-04-14 02:16
Priority:
3
Submitted By:
John Croisant (jacius)
Assigned To:
Shyouhei Urabe (shyouhei)
Category:
Misc / Other Standard Library
State:
Open
Summary:
Emacs ruby electric mode: ruby-electric-return

Detailed description
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:

  begin

when you press return, it will become:

  begin
    
  end

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.

Add A Comment: Notepad

Please login


Followup

Message
Date: 2008-12-11 14:53
Sender: Roger Pack

feel free to submit a patch to the new bug tracker
[http://redmine.ruby-lang.org/] if this patch still applies.
Thanks!
Date: 2008-05-28 01:53
Sender: John Croisant

Oops, I just realized I uploaded the wrong file last time.
Here is the correct file, ruby-electric-return-v2.patch.
Please ignore the ruby-electric.el file.
Date: 2008-04-15 01:24
Sender: John Croisant

Attached a better patch, which fixes a problem I noticed in
the behavior from the earlier patch. Specifically: pressing
return on a blank line after the keyword would insert
additional "end" words.

This patch is also created against the current ruby trunk,
instead of 1.8.

Attached Files:

Name Description Download
ruby-electric-return.patch Patch to add ruby-electric-return behavior. Download
ruby-electric.el Improved patch. Download
ruby-electric-return-v2.patch Improved patch. (Really) Download

Changes:

Field Old Value Date By
File Added3771: ruby-electric-return-v2.patch2008-05-28 01:53jacius
File Added3595: ruby-electric.el2008-04-15 01:24jacius
File Added3590: ruby-electric-return.patch2008-04-14 02:16jacius