@@ -50,21 +50,22 @@ function! s:stringize_options(opts) abort
5050endfunction
5151
5252function ! s: build_extra_options () abort
53- let extra_options = ' '
54-
5553 let opts = copy (g: clang_format #style_options)
5654 if has_key (g: clang_format #filetype_style_options, &ft )
5755 call extend (opts, g: clang_format #filetype_style_options[&ft ])
5856 endif
5957
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
6162
6263 return extra_options
6364endfunction
6465
6566function ! s: make_style_options () abort
6667 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}" ,
6869 \ g: clang_format #code_style,
6970 \ (exists (' *shiftwidth' ) ? shiftwidth () : &l: shiftwidth ),
7071 \ &l: expandtab== 1 ? ' false' : ' true' ,
@@ -193,6 +194,8 @@ let g:clang_format#style_options = s:getg('clang_format#style_options', {})
193194let g: clang_format #filetype_style_options = s: getg (' clang_format#filetype_style_options' , {})
194195
195196let 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+
196199let g: clang_format #auto_format = s: getg (' clang_format#auto_format' , 0 )
197200let g: clang_format #auto_format_on_insert_leave = s: getg (' clang_format#auto_format_on_insert_leave' , 0 )
198201let g: clang_format #auto_formatexpr = s: getg (' clang_format#auto_formatexpr' , 0 )
@@ -207,7 +210,11 @@ endfunction
207210function ! clang_format#format (line1, line2) abort
208211 let args = printf (' -lines=%d:%d' , a: line1 , a: line2 )
209212 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
211218 else
212219 let args .= ' -style=file '
213220 endif
0 commit comments