Skip to content

Commit 8969c39

Browse files
committed
add g:clang_format#filetype_style_options
1 parent 8894970 commit 8969c39

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

autoload/clang_format.vim

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,23 @@ function! s:system(str, ...)
3333
return output
3434
endfunction
3535

36-
function! s:make_style_options()
36+
function! s:build_extra_options()
3737
let extra_options = ""
38-
for [key, value] in items(g:clang_format#style_options)
38+
39+
let opts = copy(g:clang_format#style_options)
40+
if has_key(g:clang_format#filetype_style_options, &ft)
41+
call extend(opts, g:clang_format#filetype_style_options[&ft])
42+
endif
43+
44+
for [key, value] in items(opts)
3945
let extra_options .= printf(", %s: %s", key, value)
4046
endfor
47+
48+
return extra_options
49+
endfunction
50+
51+
function! s:make_style_options()
52+
let extra_options = s:build_extra_options()
4153
return printf("'{BasedOnStyle: %s, IndentWidth: %d, UseTab: %s%s}'",
4254
\ g:clang_format#code_style,
4355
\ (exists('*shiftwidth') ? shiftwidth() : &l:shiftwidth),
@@ -124,6 +136,7 @@ endif
124136

125137
let g:clang_format#code_style = s:getg('clang_format#code_style', 'google')
126138
let g:clang_format#style_options = s:getg('clang_format#style_options', {})
139+
let g:clang_format#filetype_style_options = s:getg('clang_format#filetype_style_options', {})
127140

128141
let g:clang_format#detect_style_file = s:getg('clang_format#detect_style_file', 1)
129142
let g:clang_format#auto_format = s:getg('clang_format#auto_format', 0)

doc/clang-format.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ g:clang_format#style_options *g:clang_format#style_options*
139139
CLANG-FORMAT STYLE OPTIONS
140140
http://clang.llvm.org/docs/ClangFormatStyleOptions.html
141141

142+
g:clang_format#filetype_style_options
143+
*g:clang_format#filetype_style_options*
144+
145+
If you want to use language-specific style options, you can use this
146+
variable. This variable is a |Dictionary| and its key is |filetype|. You
147+
can specify the filetype specific style options as a value of the key.
148+
The format to specify options is the same as |g:clang_format#style_options|.
149+
150+
For example, if you want to set "C++11" to "Standard", you can specify it
151+
only when the filetype is "cpp" as below:
152+
>
153+
" Your common style options
154+
let g:clang_format#style_options = {
155+
\ 'AllowShortIfStatementsOnASingleLine' : 'true',
156+
\ }
157+
158+
" Your filetype specific options
159+
let g:clang_format#filetype_style_options = {
160+
\ 'cpp' : {"Standard" : "C++11"},
161+
\ }
162+
<
142163
g:clang_format#extra_args *g:clang_format#extra_args*
143164

144165
Extra arguments for clang-format. This |String| value is passed to

0 commit comments

Comments
 (0)