[PATCH] clang-format: add an option for fallback style in vimrc

Chilledheart rwindz0 at gmail.com
Fri Mar 20 12:11:56 PDT 2015

Hi alexfh, djasper, compnerd,

It will be quite convenient to use if fallback style support is added,
so that clang-format.py will search and use existing .clang-format file
if there is any and fallback to the specific format style if not.
It should cover the projects which don't have .clang-format files
in their source.

And option fallback-style is available in clang 3.5 or later, it is safe to use.



Index: tools/clang-format/clang-format.py
--- tools/clang-format/clang-format.py
+++ tools/clang-format/clang-format.py
@@ -34,6 +34,8 @@
 # a '.clang-format' or '_clang-format' file to indicate the style that should be
 # used.
 style = 'file'
+if vim.eval('exists("g:clang_format_fallback_style")') == "1":
+  fallback_style = vim.eval('g:clang_format_fallback_style')
 def main():
   # Get the current text.
@@ -58,6 +60,8 @@
   # Call formatter.
   command = [binary, '-lines', lines, '-style', style, '-cursor', str(cursor)]
+  if fallback_style:
+    command.extend(['-fallback-style', fallback_style])
   if vim.current.buffer.name:
     command.extend(['-assume-filename', vim.current.buffer.name])
   p = subprocess.Popen(command,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8489.22366.patch
Type: text/x-patch
Size: 812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150320/cc2aaf7e/attachment.bin>

More information about the cfe-commits mailing list