Sublime Forum

Clang-format plugin (from clang)

#1

Hi,

Firstly, I have nothing to do with this plugin other than trying it out, but I figured it might be of interest to any C/C++ programmers, and possibly any plugin experts who could help improve it.

The clang compiler package includes a tool to do code formatting (clang-format), which also includes a plugin to run it from ST:

llvm.org/svn/llvm-project/cfe/tr … sublime.py

I have been playing with it today (on Win7 64) and it seems to work well. I can press ctrl-shift-c and it will format the current line, or highlight something and format that.

0 Likes

#2

[quote]Firstly, I have nothing to do with this plugin other than trying it out, but I figured it might be of interest to any C/C++ programmers, and possibly any plugin experts who could help improve it.
[/quote]

My thoughts exactly! I’m not sure I count as a plugin ‘expert’… but I did go ahead and write a package:

sublime.wbond.net/packages/Clang%20Format

It offers the following extensions over the old simple plugin:

  • It has far fewer bugs.
  • You can select the current style from the command palette.
  • You can customise the style (different indent behaviour etc.) using the standard ST
    settings interface.
  • It has an item in the main menu for accessing preference (shortcut keys + custom styles)
  • You can set the path easily and quickly from ST.
  • The shortcuts are limited to C/C++ files (so clang-format doesn’t go crazy on your Python code…)
  • It actually shows error output from CF. to the user (and doesn’t write over your buffer if they occurred).
  • You can get it on package control!

Do let me know if you find any bugs!

0 Likes

#3

Just installed it, looks awesome so far – great work :smiley:

0 Likes

#4

Great package! I’ve been using it for quite sometime now.
Noticed small issues with a couple of options:

  1. AllowShortFunctionsOnASingleLine: To make user setting for this option, I need to use the string “AllowShortFunctionsOnaSingleLine”, else the script fails to recognize the keyword
  2. NamespaceIndentation: User setting doesn’t seem to have any impact. It always indents in a namespace.
0 Likes

#5

Great Package! The clang-format has several styles to have, but I would like to use my own prefered style, I noticed there is “Custom” in the “Select Style” option, but I didn’t know how to configure that, I know the configuration file is exported as .clang-format, but how to apply it in the package?

0 Likes