4

Upon pressing enter inside a newly created block I would like the Emacs to move the ending curly brace an extra newline down, and then indent the cursor. Is this possible?

Example

Before pressing Enter

for i := range x {<cursor>}

After pressing Enter once I get this

for i := range x {
<cursor>}

However what I would like to get is this

for i := range x {
    <cursor>
}
Drew
  • 75,699
  • 9
  • 109
  • 225
jsfr
  • 43
  • 2

1 Answers1

4

I use smartparens for exactly this. It uses sort of a cryptic syntax in the :post-handlers keyword for doing things after you insert a pair and press a button. Here's a pair config to do what you want:

(sp-pair "{" nil :post-handlers '(("||\n[i]" "RET")))

And the relevant documentation on the Github wiki: Pre and Post Action Hooks

Scott Weldon
  • 2,695
  • 1
  • 17
  • 31
nanny
  • 5,704
  • 18
  • 38
  • This was _exactly_ what I was looking for :) I actually already use smartparens (which is the whole reason my cursor ends up in between the curly braces) but must admit I didn't quite get the action hooks. – jsfr May 13 '15 at 13:05