]> granicus.if.org Git - clang/commitdiff
[ClangFormat] Editor integrations inherit default style from clang-format binary
authorSam McCall <sam.mccall@gmail.com>
Fri, 17 May 2019 07:22:55 +0000 (07:22 +0000)
committerSam McCall <sam.mccall@gmail.com>
Fri, 17 May 2019 07:22:55 +0000 (07:22 +0000)
Summary:
This allows downstream customizations to the default style to work without
needing to also modify the editor integrations.

Reviewers: ilya-biryukov

Reviewed By: ilya-biryukov

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D49719

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360996 91177308-0d34-0410-b5e6-96231b3b80d8

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 5ea9a27825cbef1dc004139e5ec5c986a1cfa829..20c867092ef55f85bc545fc26f84018062eeab45 100644 (file)
@@ -24,7 +24,7 @@ binary = 'clang-format'
 # '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):
@@ -32,7 +32,9 @@ class ClangFormatCommand(sublime_plugin.TextCommand):
     if encoding == 'Undefined':
       encoding = 'utf-8'
     regions = []
-    command = [binary, '-style', style]
+    command = [binary]
+    if style:
+      command.extend(['-style', style])
     for region in self.view.sel():
       regions.append(region)
       region_offset = min(region.a, region.b)
index 0defe7452cbc62bb7600e7d20d3b9abf2af5c4ad..ee0eaaa31e9646ebfe6d9a28b53289b6b0c119b9 100644 (file)
@@ -58,7 +58,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 4f11daf15fa9e1e331432dadbb20077fa1f8bb34..0b9dc8d6fa8b2b6a84809c4b422a584da2f38227 100644 (file)
@@ -45,14 +45,14 @@ A string containing the name or the full path of the executable."
   :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 @@ uses the function `buffer-file-name'."
                                ;; 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 fe068bd41c18bf8844aa678d9a589d3b1a3c8bb9..0c772f91f6f229979c80815ada171fb6eaa76a27 100644 (file)
@@ -44,7 +44,7 @@ if vim.eval('exists("g:clang_format_path")') == "1":
 # '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 @@ def main():
     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: