]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/fixers/astyle.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / fixers / astyle.vim
1 " Author: James Kim <jhlink@users.noreply.github.com>
2 " Description: Fix C/C++ files with astyle.
3
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', '')
8     endfor
9 endfunction
10
11 call s:set_variables()
12
13
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'
17
18     return ale#Var(a:buffer, l:ft . '_astyle_' . a:name)
19 endfunction
20
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')
24
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)
28         return l:proj_options
29     endif
30
31     " Try to find nearest .astylerc file.
32     let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '.astylerc'), ':t')
33
34     if !empty(l:proj_options)
35         return l:proj_options
36     endif
37
38     " Try to find nearest _astylerc file.
39     let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '_astylerc'), ':t')
40
41     if !empty(l:proj_options)
42         return l:proj_options
43     endif
44
45     " If no project options file is found return an empty string.
46     return ''
47 endfunction
48
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))
53
54     return {
55     \   'command': ale#Escape(l:executable)
56     \     . (empty(l:proj_options) ? '' : ' --project=' . l:proj_options)
57     \     . l:command
58     \}
59 endfunction