Assuming I customized my default C indentation settings through M-x customize-variable c-offsets-alist:

    ((statement-case-open . 0)
     (substatement-open . 0)
     (case-label . +)
     (access-label . -)
     (label . 0)
     (arglist-intro . +)
     (arglist-cont . 0)
     (arglist-cont-nonempty . +)
     (arglist-close . 0)))))

When I want to edit a project using a specific indentation file, there is (or I can create) a .dir-locals.el indicating it:

((c-mode . ((c-file-style . "GNU"))))

However, the c-offsets-alist from my configuration still override the c-file-style defaults.

I've tried setting c-file-offsets and c-offsets-alist in .dir-locals, but it didn't work; setting c-file-offsets to nil had no effect, and setting c-offsets-alist to nil completely disables indentation.

Is it possible to disable c-offsets-alist from having an effect when c-file-style is non-nil?

1 Answer 1


Instead of modifying c-offsets-alist, you can modify c-file-offsets whose purpose is to set offsets via file local variables.

A small example for a .dir-locals.el file:

((nil . ((fill-column . 80)))
  (c-mode . ((c-file-style . "GNU")
              (brace-list-intro . +)))))
  • This did not work for me in emacs 27.1 on Ubuntu 22.04. I used 'add-dir-local-variable' and added c-file-offsets locally. Then I open a cxx file in the directory and C-h v 'c-file-offsets' shows it is set to nil. Commented Jun 7 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.