Skip to content

Commit 94da2a1

Browse files
committed
enable to use v:true/v:false in config
1 parent 9319ebf commit 94da2a1

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

autoload/clang_format.vim

+12-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ let s:save_cpo = &cpo
22
set cpo&vim
33

44
let s:on_windows = has('win32') || has('win64')
5+
let s:dict_t = type({})
6+
if exists('v:true')
7+
let s:bool_t = type(v:true)
8+
else
9+
let s:bool_t = -1
10+
endif
511

612
" helper functions {{{
713
function! s:has_vimproc() abort
@@ -36,15 +42,18 @@ function! s:system(str, ...) abort
3642
endfunction
3743

3844
function! s:create_keyvals(key, val) abort
39-
if type(a:val) == type({})
45+
if type(a:val) == s:dict_t
4046
return a:key . ': {' . s:stringize_options(a:val) . '}'
4147
else
42-
return a:key . ': ' . a:val
48+
if type(a:val) == s:bool_t
49+
return a:key . (a:val == v:true ? ': true' : ': false')
50+
else
51+
return a:key . ': ' . a:val
52+
endif
4353
endif
4454
endfunction
4555

4656
function! s:stringize_options(opts) abort
47-
let dict_type = type({})
4857
let keyvals = map(items(a:opts), 's:create_keyvals(v:val[0], v:val[1])')
4958
return join(keyvals, ',')
5059
endfunction

t/clang_format_spec.vim

+31-14
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,6 @@ describe 'clang_format#format()'
165165
Expect pos == getpos('.')
166166
end
167167

168-
it 'formats following g:clang_format#style_options'
169-
let saved = [g:clang_format#style_options, &expandtab, &shiftwidth]
170-
try
171-
set expandtab
172-
set shiftwidth=4
173-
let g:clang_format#style_options = {'UseTab' : 'false', 'IndentWidth' : 4}
174-
call s:expect_the_same_output(1, line('$'))
175-
finally
176-
let g:clang_format#style_options = saved[0]
177-
let &expandtab = saved[1]
178-
let &shiftwidth = saved[2]
179-
endtry
180-
end
181-
182168
it 'ensures to fix issue #38'
183169
let saved = g:clang_format#style_options
184170
try
@@ -362,6 +348,37 @@ describe ':ClangFormat'
362348
end
363349
" }}}
364350

351+
" test for customizing formatting {{{
352+
describe 'g:clang_format#style_options'
353+
before
354+
let g:clang_format#detect_style_file = 0
355+
new
356+
execute 'silent' 'edit!' './'.s:root_dir.'t/test.cpp'
357+
358+
let s:saved_styles = [g:clang_format#style_options, &expandtab, &shiftwidth]
359+
set expandtab
360+
set shiftwidth=4
361+
end
362+
363+
after
364+
close!
365+
let [g:clang_format#style_options, &expandtab, &shiftwidth] = s:saved_styles
366+
end
367+
368+
it 'customizes code styles'
369+
let g:clang_format#style_options = {'UseTab' : 'false', 'IndentWidth' : 4}
370+
call s:expect_the_same_output(1, line('$'))
371+
end
372+
373+
it 'can contain v:true/v:false'
374+
if exists('v:false')
375+
let g:clang_format#style_options = {'UseTab' : v:false, 'IndentWidth' : 4}
376+
call s:expect_the_same_output(1, line('$'))
377+
endif
378+
end
379+
end
380+
" }}}
381+
365382
" test for auto formatting {{{
366383
describe 'g:clang_format#auto_format'
367384

0 commit comments

Comments
 (0)