8

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?

jidicula
  • 251
  • 4
  • 12

2 Answers2

8

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.

Ian
  • 1,321
  • 10
  • 12
3

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
Philipp Claßen
  • 169
  • 1
  • 6