Why not find .astylerc file recursively?
SilverRainZ opened this issue · comments
Shengyu Zhang commented
As I see, vim-autoformat only find .astylerc under PWD and HOME, but most project put their .astylerc file under project root.
Neither PWD nor HOME. Is there any reason to do so?
Shengyu Zhang commented
I wrote the following snippet, can recursively find astylerc:
function! FindAstylerc()
let l:astylerc = '.astylerc'
let l:cur = '%:p:h'
let l:home = expand('~/' . astylerc)
let l:root = '/' . astylerc
let l:found = 0
while 1
let f = expand(cur) . '/' . astylerc
if filereadable(f)
let found = 1
break
endif
if (f == home) || (f == root)
break
endif
let cur = cur . ':h' " To upper directory
endwhile
if !found
return ''
else
return f
endif
endfunction
let astylerc = FindAstylerc()
if filereadable(astylerc)
let g:formatdef_my_astyle_c = '"astyle --mode=c --options=' . astylerc . '"'
let g:formatters_c = ['my_astyle_c']
let g:formatters_h = ['my_astyle_c']
let g:formatters_cpp = ['my_astyle_c']
endif
chtenb commented
Is there any reason to do so?
The reason is that the person that introduced this limited his contribution to the current functionality. If you that it needs improvement, feel free to provide a PR.