Given the file test.c
:
int main()
{
if (a)
foo();
else
if (b) // line 6
bar();
else
baz();
}
Whenever a comma or paren is typed while point is on line 6 (second if
), Emacs reindents the line one indent level deeper, i.e.:
int main()
{
if (a)
foo();
else
if (b)
bar();
else
baz();
}
Is there any way to disable this annoying behaviour just for this situation?
- I'm aware that I could use
else if
on one line instead of puttingelse
andif
on separate lines. However:- I don't like this style, as the
if
conditions are no longer aligned - I'm working on existing projects with an existing code style
- The editor should not dictate the code style anyway.
- I don't like this style, as the
- I'm aware that I could disable electric indentation entirely, however this disables useful behaviour such as correct indentation after typing
{
and}
. The Emacs manual lists which characters trigger electric indentation:
The electric characters are
{
,}
,:
,#
,;
,,
,<
,>
,/
,*
,(
, and)
.However, there is no mention of any way to customizing them. I think leaving just
{
and}
would be fine.
else if
on the same line. Then the indentation code will do the right thing. – Stefan Feb 25 '17 at 13:44electric-indent-chars
, but IIRC cc-mode doesn't obey this yet. I suggest you report this as a bug withM-x report-emacs-bug RET
. – Stefan Feb 25 '17 at 14:27