Reputation: 2220
I'm finally making the big jump, leaving Vim for Emacs, and I can say I'm pretty delighted already (not in term of speed for now... but that will catch up).
However, there is this thing I'm trying to figure out...
When I code a for loop in C, for example, and add an opening braces, this is what I get
Then I expand braces by pressing C-j
and this is where I end.
The issue is, I'm used to end there (this is how my vim was configured)
But I can't figure out how to do this... I'm just starting with emacs and lisp and seem overwhelmed already by that tiny thing. I've already mapped a chord so when I press kk
I insert an empty line above the current line and indent it properly. So for now, what I do is RET kk
but i'd like my return key to do that by itself.
Upvotes: 3
Views: 509
Reputation: 74058
You can configure where newlines are inserted with c-hanging-braces-alist
Hanging Braces
To specify which kinds of braces you want auto-newlines put around, you set the style variablec-hanging-braces-alist
.
E.g., to keep the brace on the same line as for
and insert a newline after it
(custom-set-variables
'(c-hanging-braces-alist (quote ((substatement-open . (after))))))
Another approach could be to use Yasnippet and define an appropriate template
# -*- mode: snippet -*-
# name: for
# --
for ($1; $2; $3) {
$0
}
Now you can enter for and tab and Yasnippet will automatically insert
for (; ; ) {
}
and wait for you to insert the fields leaving the cursor between the braces when finished.
Upvotes: 3