10

I have some comments in my code:

//asdf

when I use clang-format on it, it adds a space just after the // characters:

// asdf

How can I prevent that from happening in the clang-format configuration ?

Thanks

Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110
  • 2
    Interesting... neither the [documentation](http://clang.llvm.org/docs/ClangFormatStyleOptions.html) nor `clang-format -dump-config | grep -i 'space\|comment'` seem to mention anything about that. – maddouri Oct 06 '15 at 12:43
  • `SpacesBeforeTrailingComments` appears to mean spaces _before_ the `//` if it trails on a code line, but the documentation isn't terribly clear; worth giving it a try, at least. – Lightness Races in Orbit Oct 12 '15 at 13:36
  • Earlier, I've had a look at the [clang::format::FormatStyle class documentation](http://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html) (which _"is used to configure the formatting to follow specific guidelines"_)... still couldn't find a suitable option for controlling this behavior. As jpw said, your best bet would be to implement the feature in a custom-built clang-format. Or... perhaps you could submit a report in [the LLVM Bug Tracking System](http://llvm.org/bugs/enter_bug.cgi) ? – maddouri Oct 12 '15 at 14:19

1 Answers1

8

Combining the answers to these two questions should solve the problem:

So the following line in your .clang-format file should do the trick (I did not test it):

CommentPragmas:  '^[^ ]'

That tells clang-format not to mess with comments that start with something other than a space.

For completeness, clang-format documentation here.

Community
  • 1
  • 1
amdn
  • 11,314
  • 33
  • 45