summaryrefslogtreecommitdiffstats
path: root/docs/ClangFormat.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/ClangFormat.rst')
-rw-r--r--docs/ClangFormat.rst87
1 files changed, 71 insertions, 16 deletions
diff --git a/docs/ClangFormat.rst b/docs/ClangFormat.rst
index 964fc84..bc6b8a2 100644
--- a/docs/ClangFormat.rst
+++ b/docs/ClangFormat.rst
@@ -15,26 +15,73 @@ to format C/C++/Obj-C code.
.. code-block:: console
- $ clang-format --help
+ $ clang-format -help
OVERVIEW: A tool to format C/C++/Obj-C code.
If no arguments are specified, it formats the code from standard input
and writes the result to the standard output.
- If <file> is given, it reformats the file. If -i is specified together
- with <file>, the file is edited in-place. Otherwise, the result is
- written to the standard output.
+ If <file>s are given, it reformats the files. If -i is specified
+ together with <file>s, the files are edited in-place. Otherwise, the
+ result is written to the standard output.
- USAGE: clang-format [options] [<file>]
+ USAGE: clang-format [options] [<file> ...]
OPTIONS:
- -fatal-assembler-warnings - Consider warnings as error
- -help - Display available options (-help-hidden for more)
- -i - Inplace edit <file>, if specified.
- -length=<int> - Format a range of this length, -1 for end of file.
- -offset=<int> - Format a range starting at this file offset.
- -stats - Enable statistics output from program
- -style=<string> - Coding style, currently supports: LLVM, Google, Chromium.
- -version - Display the version of this program
+
+ Clang-format options:
+
+ -cursor=<uint> - The position of the cursor when invoking
+ clang-format from an editor integration
+ -dump-config - Dump configuration options to stdout and exit.
+ Can be used with -style option.
+ -i - Inplace edit <file>s, if specified.
+ -length=<uint> - Format a range of this length (in bytes).
+ Multiple ranges can be formatted by specifying
+ several -offset and -length pairs.
+ When only a single -offset is specified without
+ -length, clang-format will format up to the end
+ of the file.
+ Can only be used with one input file.
+ -lines=<string> - <start line>:<end line> - format a range of
+ lines (both 1-based).
+ Multiple ranges can be formatted by specifying
+ several -lines arguments.
+ Can't be used with -offset and -length.
+ Can only be used with one input file.
+ -offset=<uint> - Format a range starting at this byte offset.
+ Multiple ranges can be formatted by specifying
+ several -offset and -length pairs.
+ Can only be used with one input file.
+ -output-replacements-xml - Output replacements as XML.
+ -style=<string> - Coding style, currently supports:
+ LLVM, Google, Chromium, Mozilla, WebKit.
+ Use -style=file to load style configuration from
+ .clang-format file located in one of the parent
+ directories of the source file (or current
+ directory for stdin).
+ Use -style="{key: value, ...}" to set specific
+ parameters, e.g.:
+ -style="{BasedOnStyle: llvm, IndentWidth: 8}"
+
+ General options:
+
+ -help - Display available options (-help-hidden for more)
+ -help-list - Display list of available options (-help-list-hidden for more)
+ -version - Display the version of this program
+
+
+When the desired code formatting style is different from the available options,
+the style can be customized using the ``-style="{key: value, ...}"`` option or
+by putting your style configuration in the ``.clang-format`` or ``_clang-format``
+file in your project's directory and using ``clang-format -style=file``.
+
+An easy way to create the ``.clang-format`` file is:
+
+.. code-block:: console
+
+ clang-format -style=llvm -dump-config > .clang-format
+
+Available style options are described in :doc:`ClangFormatStyleOptions`.
Vim Integration
@@ -96,6 +143,13 @@ menu item by renaming the script, and can assign the menu item a keyboard
shortcut in the BBEdit preferences, under Menus & Shortcuts.
+Visual Studio Integration
+=========================
+
+Download the latest Visual Studio plugin from the `alpha build site
+<http://llvm.org/builds/>`_. The default key-binding is Ctrl-R,Ctrl-F.
+
+
Script for patch reformatting
=============================
@@ -106,18 +160,19 @@ a unified diff and reformats all contained lines with :program:`clang-format`.
usage: clang-format-diff.py [-h] [-p P] [-style STYLE]
- Reformat changed lines in diff
+ Reformat changed lines in diff.
optional arguments:
-h, --help show this help message and exit
-p P strip the smallest prefix containing P slashes
- -style STYLE formatting style to apply (LLVM, Google, Chromium)
+ -style STYLE formatting style to apply (LLVM, Google, Chromium, Mozilla,
+ WebKit)
So to reformat all the lines in the latest :program:`git` commit, just do:
.. code-block:: console
- git diff -U0 HEAD^ | clang-format-diff.py
+ git diff -U0 HEAD^ | clang-format-diff.py -p1
The :option:`-U0` will create a diff without context lines (the script would format
those as well).
OpenPOWER on IntegriCloud