rosshemsley / SublimeClangFormat

A C++ code formatter based on Clang Format, for beautiful code with minimal effort in Sublime Text 3
Other
185 stars 52 forks source link

Clang-format doesn't honour .clang-format in the project directory #63

Open ababo opened 4 years ago

ababo commented 4 years ago

I need to pass IncludeBlocks: Preserve into clang-format and I don't know how to do it. The config file in the root of my project directory is just ignored. clang-format works properly when being launched from terminal.

manenko commented 3 years ago

Hi @ababo!

Try this:

  1. Invoke the Command Palette (Ctrl+Shift+P/Cmd+Shift+P).
  2. Type clang format.
  3. Choose and invoke Clang Format: Select Style command.
  4. Choose File from the menu.

Now it should honour the .clang-format file.

I found this when I was trying to solve the same problem. If you open default package settings, they look like this:

{
    // This is the path to the binary for clang-format. If it is in your path,
    // it should just work out-of-the-box. Otherwise, you can set the full path,
    // which will look like this: 
    //    "binary": "/path/to/clang/bin/clang-format"
    // Note that you can set this from within ST directly through the Command
    // Palette. 

    "binary": "clang-format",

    // We use the Google style by default. This can be selected from ST using
    // the Command Palette. Choosing 'Custom' means that the settings will
    // be loaded from the Sublime Text settings file (which is accessed
    // from within ST through preferences. Choosing 'File' will look in the 
    // local directories from a clang-format settings file. See the clang-format
    // documentation to see how this works. 

    "style": "Google",

    // Setting this to true will run the formatter on every save. If you want to
    // only enable this for a given project, try checking out the package
    // "Project-Specific".

    "format_on_save": false,

    // If format_on_save is set to true, ClangFormat checks if the current file
    // has its syntax set to a language in the list below. If it is in the list,
    // then the file will be formatted by ClangFormat.

    "languages": ["C", "C++", "C++11", "JavaScript", "Objective-C", "Objective-C++"]
}

The style config key has a comment that describes various options including the File.

I hope this helps :-)