Emacs auto indent on sequential parenthesis doesn't work fine:
int main() {
something(int i)(
"test", "something"
);
}
How to fix this indentation to be like normal indentation:
int main() {
something(int i)(
"test", "something"
);
}
major mode info:
- major-mode is a variable defined in ‘C source code’.
- Its value is ‘c++-mode’
SOLUTION:
Thanks, @pickle rick, and @0x5453,
(c-add-style "cc-style"
'("linux" ;; it can be google or k&r or other c-style.
(c-basic-offset . 2)
(c-offsets-alist
(arglist-close . c-lineup-close-paren))))
(add-hook 'c++-mode-hook
(lambda()
(c-set-style "cc-style")))
cc-modeis able to intelligently guess the settings you want forc-offsets-alistbased on the indentation in the buffer. To do this, align the code in the buffer as you want it, and evaluate M-xc-guess.Indent the buffer, and assuming it looks OK, you can see the guessed settings with M-x
c-guess-view. Then, you could copy the entire style into your init somewhere, or cherry pick the relevant settings.Additionally, you can get an idea of which rules apply to a given line by running M-x
c-show-syntactic-informationwith the point positioned there. Note, however, that this won't give all the relevant info since other rules/styles affect each others, but will tell identifyarglist-closeas the relevant rule in your example.