CLion 2019.2 Help

CLion_external_tools_example

Example: Uncrustify as an external tool

Uncrustify is a popular code formatter that you can configure as an external tool to use in addition or as an alternative to the CLion's built-in formatter or the integrated ClangFormat.

  1. Optionally, place the configuration file in the project directory (otherwise, you will need to provide the full path).

  2. Navigate to Settings / Preferences | Tools | External Tools and click the Add button.

  3. In the dialog that opens, specify the following:

    add external tool

    • Name: uncrustify - just for example, let's name the configuration similarly to the executable.

    • Program: uncrustify - provide the binary name (and include the full path if necessary).

    • Arguments: -c mystyle.cfg -f $FilePath$ -o $FilePath$ - style settings stored in mypath.cfg will be applied to the file currently opened in the editor (the $FileName$ macro), and the result will be written in-place (the -o flag redirects the Uncrustify output).

    • Working directory: $FileDir$ - this macro represents the current file directory.

  4. Click Ok to save the configuration.

  5. Now you can go to Tools | External tools | uncrustify and run the tool with the above settings. The changes of code formatting will be introduced right away.

Assign a shortcut to the Uncrustify external tool:

  1. Go to Settings / Preferences | Keymap and find uncrustify in the list of External Tools.

  2. Click the Edit button and choose Add Keyboard Shortcut.

  3. Press the keys to be used as shortcuts and click Ok.

Now the assigned shortcut is available, and you can see it next to the tool's name in the Tools | External Tools menu:

external tools menu

Automatically run Uncrustify before launch:

  1. In the Run | Edit configurations dialog, choose the desired run/debug configuration.

  2. Click the Add button in the Before Launch section, and select Run External Tool:

    Before launch

  3. Choose uncrustify from the list of the available external tools.

As a result, the uncrustify external tool will be called every time you choose to run or debug the selected configuration.

Last modified: 22 August 2019