All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 " Author: James Kim <jhlink@users.noreply.github.com>
2 " Description: Fix C/C++ files with astyle.
4 function! s:set_variables() abort
5 for l:ft in ['c', 'cpp']
6 call ale#Set(l:ft . '_astyle_executable', 'astyle')
7 call ale#Set(l:ft . '_astyle_project_options', '')
11 call s:set_variables()
14 function! ale#fixers#astyle#Var(buffer, name) abort
15 let l:ft = getbufvar(str2nr(a:buffer), '&filetype')
16 let l:ft = l:ft =~# 'cpp' ? 'cpp' : 'c'
18 return ale#Var(a:buffer, l:ft . '_astyle_' . a:name)
21 " Try to find a project options file.
22 function! ale#fixers#astyle#FindProjectOptions(buffer) abort
23 let l:proj_options = ale#fixers#astyle#Var(a:buffer, 'project_options')
25 " If user has set project options variable then use it and skip any searching.
26 " This would allow users to use project files named differently than .astylerc.
27 if !empty(l:proj_options)
31 " Try to find nearest .astylerc file.
32 let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '.astylerc'), ':t')
34 if !empty(l:proj_options)
38 " Try to find nearest _astylerc file.
39 let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '_astylerc'), ':t')
41 if !empty(l:proj_options)
45 " If no project options file is found return an empty string.
49 function! ale#fixers#astyle#Fix(buffer) abort
50 let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable')
51 let l:proj_options = ale#fixers#astyle#FindProjectOptions(a:buffer)
52 let l:command = ' --stdin=' . ale#Escape(expand('#' . a:buffer))
55 \ 'command': ale#Escape(l:executable)
56 \ . (empty(l:proj_options) ? '' : ' --project=' . l:proj_options)