I would like to have the following behavior:
int main(){
to result in:
int main(){
|
}
Where pipe is the cursor, and I DON'T have to press RETURN key after '{'.
I have already achieved the following behavior:
int main(){
which results in:
int main()
{
|
}
Using c-toggle-auto-indent and electric-pair-mode.
So, how do I make it the way I want to? i.e to:
int main(){
|
}
I have been looking around and found this page:
First you need to find the syntactic context of the brace—type a RET before the brace to get it on a line of its own, then type C-c C-s. That will tell you something like:
((substatement-open 1061))
So here you need to put the entry (substatement-open . (after)) into c-hanging-braces-alist
This is what I have tried:
- Found the syntactic context to be:
substatement-open
- Putting
(setq c-hanging-braces-alist '(substatement-open . (after)))
in init.el.
But this isn't working.
I really have no idea how to do this. Can someone help me?
setq
, you are clobbering any previous value of thec-hanging-braces-alist
variable. You should try customizing that variable: doC-h v c-hanging-braces-alist
and then click on thecustomize
link. That will allow you to do selective surgery on it. But I don't know what(key value)
pair(s) you should add/modify to get the effect you want. In my case,substatement-open
already has the valueafter
. A closer reading of theCC mode
manual is indicated.