[PATCH] D49719: [ClangFormat] Editor integrations inherit default style from clang-format binary

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 24 00:00:57 PDT 2018


sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added a subscriber: cfe-commits.

This allows downstream customizations to the default style to work without
needing to also modify the editor integrations.


Repository:
  rC Clang

https://reviews.llvm.org/D49719

Files:
  tools/clang-format/clang-format-sublime.py
  tools/clang-format/clang-format-test.el
  tools/clang-format/clang-format.el
  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
@@ -44,7 +44,7 @@
 # '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'
+style = None
 fallback_style = None
 if vim.eval('exists("g:clang_format_fallback_style")') == "1":
   fallback_style = vim.eval('g:clang_format_fallback_style')
@@ -91,9 +91,11 @@
     startupinfo.wShowWindow = subprocess.SW_HIDE
 
   # Call formatter.
-  command = [binary, '-style', style, '-cursor', str(cursor)]
+  command = [binary, '-cursor', str(cursor)]
   if lines != ['-lines', 'all']:
     command += lines
+  if style:
+    command.extend(['-style', style])
   if fallback_style:
     command.extend(['-fallback-style', fallback_style])
   if vim.current.buffer.name:
Index: tools/clang-format/clang-format.el
===================================================================
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -45,14 +45,14 @@
   :type '(file :must-match t)
   :risky t)
 
-(defcustom clang-format-style "file"
+(defcustom clang-format-style nil
   "Style argument to pass to clang-format.
 
 By default clang-format will load the style configuration from
 a file named .clang-format located in one of the parent directories
 of the buffer."
   :group 'clang-format
-  :type 'string
+  :type '(choice (string) (const nil))
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-style)
 
@@ -160,7 +160,7 @@
                                ;; https://bugs.llvm.org/show_bug.cgi?id=34667
                                ,@(and assume-file-name
                                       (list "-assume-filename" assume-file-name))
-                               "-style" ,style
+                               ,@(and style (list "-style" style))
                                "-offset" ,(number-to-string file-start)
                                "-length" ,(number-to-string (- file-end file-start))
                                "-cursor" ,(number-to-string cursor))))
Index: tools/clang-format/clang-format-test.el
===================================================================
--- tools/clang-format/clang-format-test.el
+++ tools/clang-format/clang-format-test.el
@@ -57,7 +57,6 @@
        (should-not display)
        (should (equal args
                       '("-output-replacements-xml" "-assume-filename" "foo.cpp"
-                        "-style" "file"
                         ;; Beginning of buffer, no byte-order mark.
                         "-offset" "0"
                         ;; We have two lines with 2×2 bytes for the umlauts,
Index: tools/clang-format/clang-format-sublime.py
===================================================================
--- tools/clang-format/clang-format-sublime.py
+++ tools/clang-format/clang-format-sublime.py
@@ -24,15 +24,17 @@
 # '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'
+style = None
 
 class ClangFormatCommand(sublime_plugin.TextCommand):
   def run(self, edit):
     encoding = self.view.encoding()
     if encoding == 'Undefined':
       encoding = 'utf-8'
     regions = []
     command = [binary, '-style', style]
+    if style:
+      command.extend(['-style', style])
     for region in self.view.sel():
       regions.append(region)
       region_offset = min(region.a, region.b)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49719.156971.patch
Type: text/x-patch
Size: 3660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180724/30f0f249/attachment-0001.bin>


More information about the cfe-commits mailing list