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

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

llvm-svn: 360996
This commit is contained in:
Sam McCall 2019-05-17 07:22:55 +00:00
parent ee0ce302c5
commit aee9448939
4 changed files with 11 additions and 8 deletions

View File

@ -24,7 +24,7 @@ binary = 'clang-format'
# 'clang-format --help' for a list of supported styles. The default looks for # '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 # a '.clang-format' or '_clang-format' file to indicate the style that should be
# used. # used.
style = 'file' style = None
class ClangFormatCommand(sublime_plugin.TextCommand): class ClangFormatCommand(sublime_plugin.TextCommand):
def run(self, edit): def run(self, edit):
@ -32,7 +32,9 @@ class ClangFormatCommand(sublime_plugin.TextCommand):
if encoding == 'Undefined': if encoding == 'Undefined':
encoding = 'utf-8' encoding = 'utf-8'
regions = [] regions = []
command = [binary, '-style', style] command = [binary]
if style:
command.extend(['-style', style])
for region in self.view.sel(): for region in self.view.sel():
regions.append(region) regions.append(region)
region_offset = min(region.a, region.b) region_offset = min(region.a, region.b)

View File

@ -58,7 +58,6 @@
(should-not display) (should-not display)
(should (equal args (should (equal args
'("-output-replacements-xml" "-assume-filename" "foo.cpp" '("-output-replacements-xml" "-assume-filename" "foo.cpp"
"-style" "file"
;; Beginning of buffer, no byte-order mark. ;; Beginning of buffer, no byte-order mark.
"-offset" "0" "-offset" "0"
;; We have two lines with 2×2 bytes for the umlauts, ;; We have two lines with 2×2 bytes for the umlauts,

View File

@ -45,14 +45,14 @@ A string containing the name or the full path of the executable."
:type '(file :must-match t) :type '(file :must-match t)
:risky t) :risky t)
(defcustom clang-format-style "file" (defcustom clang-format-style nil
"Style argument to pass to clang-format. "Style argument to pass to clang-format.
By default clang-format will load the style configuration from By default clang-format will load the style configuration from
a file named .clang-format located in one of the parent directories a file named .clang-format located in one of the parent directories
of the buffer." of the buffer."
:group 'clang-format :group 'clang-format
:type 'string :type '(choice (string) (const nil))
:safe #'stringp) :safe #'stringp)
(make-variable-buffer-local 'clang-format-style) (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 ;; https://bugs.llvm.org/show_bug.cgi?id=34667
,@(and assume-file-name ,@(and assume-file-name
(list "-assume-filename" assume-file-name)) (list "-assume-filename" assume-file-name))
"-style" ,style ,@(and style (list "-style" style))
"-offset" ,(number-to-string file-start) "-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end file-start)) "-length" ,(number-to-string (- file-end file-start))
"-cursor" ,(number-to-string cursor)))) "-cursor" ,(number-to-string cursor))))

View 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 # '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 # a '.clang-format' or '_clang-format' file to indicate the style that should be
# used. # used.
style = 'file' style = None
fallback_style = None fallback_style = None
if vim.eval('exists("g:clang_format_fallback_style")') == "1": if vim.eval('exists("g:clang_format_fallback_style")') == "1":
fallback_style = vim.eval('g:clang_format_fallback_style') fallback_style = vim.eval('g:clang_format_fallback_style')
@ -91,9 +91,11 @@ def main():
startupinfo.wShowWindow = subprocess.SW_HIDE startupinfo.wShowWindow = subprocess.SW_HIDE
# Call formatter. # Call formatter.
command = [binary, '-style', style, '-cursor', str(cursor)] command = [binary, '-cursor', str(cursor)]
if lines != ['-lines', 'all']: if lines != ['-lines', 'all']:
command += lines command += lines
if style:
command.extend(['-style', style])
if fallback_style: if fallback_style:
command.extend(['-fallback-style', fallback_style]) command.extend(['-fallback-style', fallback_style])
if vim.current.buffer.name: if vim.current.buffer.name: