As mentioned in this answer on SO, you can do:
(setq c-default-style "bsd")
This will set the style for all C-based modes. If you want to set it only for one, do e.g.:
(add-to-list 'c-default-style '(c-mode "bsd"))
However, setting c-default-style
will change various other style settings, which may not be what you want. To only change the post-for-loop-brace indentation, do:
(add-to-list 'c-offsets-alist '(substatement-open . 0))
(This will shadow the old value, which AFAIK shouldn't cause any problems. See this question and its answers for possible ways to actually replace the old value.)
Now to generalize: how do you find the specific syntactic symbol in the c-offsets-alist
that you need to modify?
Note the line that has faulty indentation (in this case, the one with the {
after the for
loop), and move the point to that line. Then do:
M-x c-show-syntactic-information
(or C-c C-s
). This will give you e.g.:
Syntactic analysis: ((substatement-open 16))
Another option is to do M-x c-set-offset
(or C-c C-o
), which will give you the following prompt:
Syntactic symbol to change: |substatement-open
Here the |
marks the position of the cursor, with the relevant symbol auto-filled for you.
Thanks to @nispio for the info!