I'd like to format my code using clang-format in CLion. I've gone through the settings and haven't found any setting that would allow me to run an external command to transform code. How are such things normally done in CLion?
To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows. The workflow to format your changed code: Make codes changes in Electron repository.
clang-format is located in clang/tools/clang-format and can be used to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code.
Provide the path to your custom Clang-Tidy binary in Settings/Preferences | Languages & Frameworks | C/C++ (or click Specify Clang-Tidy executable in the Inspections Settings dialog). This setting is IDE-wide: your custom Clang-Tidy binary will be used for all projects.
Press Ctrl+Alt+S to open the IDE settings and select Tools | Actions on Save. Enable the Reformat code option. Additionally, you can configure the way the IDE will reformat your code: Click Configure scope to specify the patterns of filenames and directories that you want to exclude from reformatting.
You can use External Tools in CLion.
Go to File->Settings->Tools->External Tools
and click on the plus sign.
A window should pop up. Use a name of your choice.
For the Tool settings
tab I'm using this configuration:
Program: clang-format-3.7
(you should use the name of your executable here)
Parameters: -i $FileName$
Working directory: $FileDir$
Now, with your file open, you can go to Tools->External tools
and run the config above. It basically calls clang-format and does inplace formatting.
You can also set a custom keymap to it, just search the name of your external tool in "Keymap" of the Settings menu.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With