Skip to content

Commit aee9448

Browse files
committedMay 17, 2019
[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
1 parent ee0ce30 commit aee9448

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed
 

‎clang/tools/clang-format/clang-format-sublime.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@
2424
# 'clang-format --help' for a list of supported styles. The default looks for
2525
# a '.clang-format' or '_clang-format' file to indicate the style that should be
2626
# used.
27-
style = 'file'
27+
style = None
2828

2929
class ClangFormatCommand(sublime_plugin.TextCommand):
3030
def run(self, edit):
3131
encoding = self.view.encoding()
3232
if encoding == 'Undefined':
3333
encoding = 'utf-8'
3434
regions = []
35-
command = [binary, '-style', style]
35+
command = [binary]
36+
if style:
37+
command.extend(['-style', style])
3638
for region in self.view.sel():
3739
regions.append(region)
3840
region_offset = min(region.a, region.b)

‎clang/tools/clang-format/clang-format-test.el

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
(should-not display)
5959
(should (equal args
6060
'("-output-replacements-xml" "-assume-filename" "foo.cpp"
61-
"-style" "file"
6261
;; Beginning of buffer, no byte-order mark.
6362
"-offset" "0"
6463
;; We have two lines with 2×2 bytes for the umlauts,

‎clang/tools/clang-format/clang-format.el

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ A string containing the name or the full path of the executable."
4545
:type '(file :must-match t)
4646
:risky t)
4747

48-
(defcustom clang-format-style "file"
48+
(defcustom clang-format-style nil
4949
"Style argument to pass to clang-format.
5050
5151
By default clang-format will load the style configuration from
5252
a file named .clang-format located in one of the parent directories
5353
of the buffer."
5454
:group 'clang-format
55-
:type 'string
55+
:type '(choice (string) (const nil))
5656
:safe #'stringp)
5757
(make-variable-buffer-local 'clang-format-style)
5858

@@ -160,7 +160,7 @@ uses the function `buffer-file-name'."
160160
;; https://bugs.llvm.org/show_bug.cgi?id=34667
161161
,@(and assume-file-name
162162
(list "-assume-filename" assume-file-name))
163-
"-style" ,style
163+
,@(and style (list "-style" style))
164164
"-offset" ,(number-to-string file-start)
165165
"-length" ,(number-to-string (- file-end file-start))
166166
"-cursor" ,(number-to-string cursor))))

‎clang/tools/clang-format/clang-format.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# 'clang-format --help' for a list of supported styles. The default looks for
4545
# a '.clang-format' or '_clang-format' file to indicate the style that should be
4646
# used.
47-
style = 'file'
47+
style = None
4848
fallback_style = None
4949
if vim.eval('exists("g:clang_format_fallback_style")') == "1":
5050
fallback_style = vim.eval('g:clang_format_fallback_style')
@@ -91,9 +91,11 @@ def main():
9191
startupinfo.wShowWindow = subprocess.SW_HIDE
9292

9393
# Call formatter.
94-
command = [binary, '-style', style, '-cursor', str(cursor)]
94+
command = [binary, '-cursor', str(cursor)]
9595
if lines != ['-lines', 'all']:
9696
command += lines
97+
if style:
98+
command.extend(['-style', style])
9799
if fallback_style:
98100
command.extend(['-fallback-style', fallback_style])
99101
if vim.current.buffer.name:

0 commit comments

Comments
 (0)
Please sign in to comment.