Hi djasper,

This allows formatting of buffers before saving them without warnings.

http://llvm-reviews.chandlerc.com/D3019

Files:
  tools/clang-format/clang-format.py

Index: tools/clang-format/clang-format.py
===================================================================
--- tools/clang-format/clang-format.py
+++ tools/clang-format/clang-format.py
@@ -29,8 +29,8 @@
 # Change this to format according to other formatting styles. See the output of
 # 'clang-format --help' for a list of supported styles. The default looks for
 # a '.clang-format' or '_clang-format' file to indicate the style that should 
be
-# used.
-style = 'file'
+# used if the vim buffer is associated with a file, or LLVM otherwise.
+style = None
 
 def main():
   # Get the current text.
@@ -52,9 +52,15 @@
     startupinfo.wShowWindow = subprocess.SW_HIDE
 
   # Call formatter.
-  command = [binary, '-lines', lines, '-style', style, '-cursor', str(cursor)]
+  command = [binary, '-lines', lines, '-cursor', str(cursor)]
   if vim.current.buffer.name:
     command.extend(['-assume-filename', vim.current.buffer.name])
+  if style:
+    command.extend(['-style', style])
+  elif vim.current.buffer.name:
+    command.extend(['-style', 'file'])
+  else:
+    command.extend(['-style', 'LLVM'])
   p = subprocess.Popen(command,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                        stdin=subprocess.PIPE, startupinfo=startupinfo)
Index: tools/clang-format/clang-format.py
===================================================================
--- tools/clang-format/clang-format.py
+++ tools/clang-format/clang-format.py
@@ -29,8 +29,8 @@
 # Change this to format according to other formatting styles. See the output of
 # 'clang-format --help' for a list of supported styles. The default looks for
 # a '.clang-format' or '_clang-format' file to indicate the style that should be
-# used.
-style = 'file'
+# used if the vim buffer is associated with a file, or LLVM otherwise.
+style = None
 
 def main():
   # Get the current text.
@@ -52,9 +52,15 @@
     startupinfo.wShowWindow = subprocess.SW_HIDE
 
   # Call formatter.
-  command = [binary, '-lines', lines, '-style', style, '-cursor', str(cursor)]
+  command = [binary, '-lines', lines, '-cursor', str(cursor)]
   if vim.current.buffer.name:
     command.extend(['-assume-filename', vim.current.buffer.name])
+  if style:
+    command.extend(['-style', style])
+  elif vim.current.buffer.name:
+    command.extend(['-style', 'file'])
+  else:
+    command.extend(['-style', 'LLVM'])
   p = subprocess.Popen(command,
                        stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                        stdin=subprocess.PIPE, startupinfo=startupinfo)
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to