1

There are cases where my indentation style does not follow what Emacs thinks it should be. (I believe that coding standards should be guidelines, not strict rules, and that deviations should be acceptable if there's good justification for them.)

For example, I might want to format code in C like:

if (   test_some_condition()
    && test_another_condition()
    && test_yet_another_condition())
{
    // ...
}

So I type:

if (   test_some_condition()
    && test_another_condition

but when I press (, Emacs will aggressively reindent my current line to:

if (   test_some_condition()
       && test_another_condition(

Is there any way disable that? That is:

  • I do want new lines to be automatically indented based on the previous line.
  • Once I start typing, I've already indented the current line the way I want it, and I don't want it to be reformatted when I press (, ), RET, etc.
jamesdlin
  • 111
  • 3

2 Answers2

2

You can try

(add-hook 'c-mode-hook
          (lambda () (setq-local electric-indent-inhibit t)))

tho I'm not sure if the C mode obeys this variable. If it doesn't work, I suggest M-x report-emacs-bug.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • Ah, "electric indent" is the term I was missing. Now that I know that, I think https://emacs.stackexchange.com/questions/20896/change-the-behaviour-of-ret-with-electric-indent-to-only-indent-the-new-line (and the other questions it referenced) are applicable to me. – jamesdlin Jan 26 '18 at 03:26
1

What I do is press C-q before typing any electric character, such as ();{} which serves to remove their electric behavior temporarily.

InHarmsWay
  • 1,309
  • 7
  • 8