@@ -50,21 +50,22 @@ function! s:stringize_options(opts) abort
50
50
endfunction
51
51
52
52
function ! s: build_extra_options () abort
53
- let extra_options = ' '
54
-
55
53
let opts = copy (g: clang_format #style_options)
56
54
if has_key (g: clang_format #filetype_style_options, &ft )
57
55
call extend (opts, g: clang_format #filetype_style_options[&ft ])
58
56
endif
59
57
60
- let extra_options .= ' , ' . s: stringize_options (opts)
58
+ let extra_options = s: stringize_options (opts)
59
+ if ! empty (extra_options)
60
+ let extra_options = ' , ' . extra_options
61
+ endif
61
62
62
63
return extra_options
63
64
endfunction
64
65
65
66
function ! s: make_style_options () abort
66
67
let extra_options = s: build_extra_options ()
67
- return printf (" ' {BasedOnStyle: %s, IndentWidth: %d, UseTab: %s%s}' " ,
68
+ return printf (" {BasedOnStyle: %s, IndentWidth: %d, UseTab: %s%s}" ,
68
69
\ g: clang_format #code_style,
69
70
\ (exists (' *shiftwidth' ) ? shiftwidth () : &l: shiftwidth ),
70
71
\ &l: expandtab== 1 ? ' false' : ' true' ,
@@ -193,6 +194,8 @@ let g:clang_format#style_options = s:getg('clang_format#style_options', {})
193
194
let g: clang_format #filetype_style_options = s: getg (' clang_format#filetype_style_options' , {})
194
195
195
196
let g: clang_format #detect_style_file = s: getg (' clang_format#detect_style_file' , 1 )
197
+ let g: clang_format #enable_fallback_style = s: getg (' clang_format#enable_fallback_style' , 1 )
198
+
196
199
let g: clang_format #auto_format = s: getg (' clang_format#auto_format' , 0 )
197
200
let g: clang_format #auto_format_on_insert_leave = s: getg (' clang_format#auto_format_on_insert_leave' , 0 )
198
201
let g: clang_format #auto_formatexpr = s: getg (' clang_format#auto_formatexpr' , 0 )
@@ -207,7 +210,11 @@ endfunction
207
210
function ! clang_format#format (line1, line2) abort
208
211
let args = printf (' -lines=%d:%d' , a: line1 , a: line2 )
209
212
if ! (g: clang_format #detect_style_file && s: detect_style_file ())
210
- let args .= printf (' -style=%s ' , s: make_style_options ())
213
+ if g: clang_format #enable_fallback_style
214
+ let args .= ' ' . s: shellescape (printf (' -style=%s' , s: make_style_options ())) . ' '
215
+ else
216
+ let args .= ' -fallback-style=none '
217
+ endif
211
218
else
212
219
let args .= ' -style=file '
213
220
endif
0 commit comments