Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent clang-format to add space after comment char?

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

like image 240
Baptiste Wicht Avatar asked Oct 06 '15 12:10

Baptiste Wicht


People also ask

How do I disable Clang-format from modifying a section of code?

You can use comments in your code to disable clang-format from modifying a section of code: Note the space in between the comment start ( //) and clang-format. This space is required for the comment to be successfully detected. There are clang-format integrations for vim, emacs, BBEdit, and Visual Studio described in the clang-format documentation.

What is the space between//and Clang-format used for?

Note the space in between the comment start ( //) and clang-format. This space is required for the comment to be successfully detected. There are clang-format integrations for vim, emacs, BBEdit, and Visual Studio described in the clang-format documentation.

What is unsigned column limit in Clang?

ColumnLimit ( Unsigned) clang-format 3.7 The column limit. A column limit of 0 means that there is no column limit. In this case, clang-format will respect the input’s line breaking decisions within statements unless they contradict other rules. CommentPragmas ( String) clang-format 3.7

How do I change the style of a clang file?

clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the .clang-format or _clang-format file in the project directory.


1 Answers

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

  • clang-format breaks lint annotations
  • What regex will match every character except comma ',' or semi-colon ';'?

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.

like image 158
amdn Avatar answered Nov 14 '22 23:11

amdn