2

Within CC mode, for C and C++ files inside a directory, I'd like to have the open braces following a case/do/for/if/while not indented, whatever the style is and without having to change anything in .emacs (in particular creating a global new style).

I've found I have to set substatement-open to 0 in c-offsets-alist for the buffer.

In .dir-locals.el, I've tried to modify c-offsets-alist, either directly:

((nil . ((eval . (add-to-list 'c-offsets-alist '(substatement-open . 0))))))

Or by using c-set-offset:

((nil . ((eval . (c-set-offset 'substatement-open 0)))))

Then I've tried to use c-file-offsets, still in .dir-locals.el:

((nil . ((c-file-offsets . ((substatement-open . 0))))))

But none seems to work.

How I can set substatement-open to 0 from .dir-locals.el for C and C++ mode ?

  • I just tried your third option and it worked perfectly. Are you accessing these files via TRAMP? By default Emacs doesn't check for a .dir-locals.el file when loading files with TRAMP. Barring that, try this with emacs -Q; perhaps there's something wrong with your configuration. – db48x May 26 '17 at 22:59
  • third option did not work for me as well, just like others – Draif Kroneg Dec 12 '17 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.