Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ababo opened this issue Mar 19, 2020 · 1 comment
Open

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

ababo opened this issue Mar 19, 2020 · 1 comment

Comments

@ababo
Copy link

ababo commented Mar 19, 2020

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
Copy link

manenko commented May 23, 2021

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants