3

When running clang-format-buffer or clang-format-region when a region has been been selected, no change is made to the formatting. However, in *Messages*, I see (clang-format: success). Using clang-format in the terminal works fine, and the emacs package clang-format is configured to point towards the correct location where clang-format is installed.

These are the only lines I have in my init.el related to clang-format (I've also tried all variations of setting / not setting clang-format-style and clang-format-style-option):

;; Clang stuff
(require 'clang-format)
(setq clang-format-style "file")

Is there something I'm missing?

5

You need to generate a .clang-format file in your project's root, with the command clang-format -style=llvm -dump-config > .clang-format.

More info on this page.

| improve this answer | |
  • Thank you! I thought I had already completed this step but turns out I hadn't. – jidiculous Feb 20 at 15:08
1

You set clang-format-style to "file". In that case, clang-format.el will first look for a .clang-format file. It it finds one, it will use it. Otherwise, it will check the clang-format-fallback-style. If that is set to "none", no changes will be made.

If that is not want you want, you have two options:

  • Provide a .clang-format file (*)
  • Change the clang-format-fallback-style to "llvm"

(*) To generate a .clang-format file, you can use:

clang-format -style=llvm -dump-config > .clang-format
| improve this answer | |

Your Answer

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

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