ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Clang Format

by rosshemsley ST3

A C++ code formatter based on Clang Format, for beautiful code with minimal effort in Sublime Text 3

Details

Installs

  • Total 6K
  • Win 2K
  • OS X 2K
  • Linux 2K
Jul 28 Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6 Jul 5 Jul 4 Jul 3 Jul 2 Jul 1 Jun 30 Jun 29 Jun 28 Jun 27 Jun 26 Jun 25 Jun 24 Jun 23 Jun 22 Jun 21 Jun 20 Jun 19 Jun 18 Jun 17 Jun 16 Jun 15 Jun 14 Jun 13
Windows 4 5 7 4 5 13 1 1 4 6 4 7 4 9 6 6 2 6 8 5 8 5 7 5 5 6 7 4 8 2 4 4 7 6 8 5 4 7 4 1 7 5 6 10 4 5
OS X 4 5 3 9 5 9 3 3 2 6 3 5 4 5 4 2 5 3 2 3 1 9 7 4 2 6 2 4 4 1 4 4 5 6 8 8 4 5 4 6 2 4 6 7 4 5
Linux 4 5 5 3 5 5 5 10 4 2 2 3 5 6 4 6 7 5 4 8 8 8 11 3 6 7 7 3 9 8 5 9 6 3 7 11 10 2 2 10 8 10 7 9 3 4

Readme

Source
raw.​githubusercontent.​com

Clang Format

Updates: Preliminary support for JavaScript has been added! Update to latest version of clang-format provided with LLVM 3.6 to avoid known bugs.

What it does

Clang-format is a tool for re-formatting C++, built on LLVM. This is a package that allows you to run it easily from within Sublime Text.

demo

About

In this package, we provide an alternative wrapper around clang-format for use within Sublime Text 3. Whilst LLVM does provide a very simple plugin to work with Sublime Text already: https://llvm.org/svn/llvm-project/cfe/trunk/tools/clang-format/clang-format-sublime.py, it doesn't really exploit any of the Sublime Text package functionality. We add new features such as customising the style from a settings file, selecting styles using the Command Palette, and easier installation.

Installing

If you prefer, you can download the entire LLVM toolchain and extract the clang-format binary yourself. Just extract the .tar.xz file and copy bin/clang-format into your PATH (e.g. /usr/local/bin). - Set the path to the clang-format binaries. You can do this from within Sublime Text by choosing Clang Format - Set Path from the command palette. Hint: the path should look something like this [path/to/clang]/clang/bin/clang-format. If clang-format is in your system path, you shouldn't need to do anything.

Use

  • Default shortcut is super+option+a on OSX and ctrl+option+a otherwise. This will apply clang-format to the selection.
  • From the command palette, you can select the formatting type by using Clang Format: Select Style. You will find the small number of defaults, and also a new 'Custom' entry. Selecting this entry allows you to customise the style through a settings file. You can access it from the main menu, under Package Settings. In this file you can add custom rules, such as Allmen style braces, and different indents. For examples see http://clang.llvm.org/docs/ClangFormatStyleOptions.html.
  • Settings for the 'Custom' format and others are available through the Sublime Text preferences.
  • It is possible to enable the formatter on every save to a C/C++ file. To change settings on a per-package basis, check out the package “Project-Specific”.

If You Liked This

If you like this plugin, maybe you'll like my other plugin, iOpener. It makes opening files significantly easier and will feel completely natural if you're used to using a shell. Otherwise, why not pop over and star this repo on GitHub?

Credits

Thanks to the LLVM project for doing the hard work, including writing clang format, and also the original Sublime Text plugin on which this package is based.

Also thanks to y0ssar1an and Bendtherules for their improvements!

Finally

Why not go and watch the video that got me interested in clang-format in the first place?

The Care and Feeding of C++'s Dragons