]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/fixers/clangformat.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 / clangformat.vim
1 scriptencoding utf-8
2 " Author: Peter Renström <renstrom.peter@gmail.com>
3 " Description: Fixing C/C++ files with clang-format.
4
5 call ale#Set('c_clangformat_executable', 'clang-format')
6 call ale#Set('c_clangformat_use_global', get(g:, 'ale_use_global_executables', 0))
7 call ale#Set('c_clangformat_options', '')
8 call ale#Set('c_clangformat_style_option', '')
9 call ale#Set('c_clangformat_use_local_file', 0)
10
11 function! ale#fixers#clangformat#GetExecutable(buffer) abort
12     return ale#path#FindExecutable(a:buffer, 'c_clangformat', [
13     \   'clang-format',
14     \])
15 endfunction
16
17 function! ale#fixers#clangformat#Fix(buffer) abort
18     let l:executable = ale#Escape(ale#fixers#clangformat#GetExecutable(a:buffer))
19     let l:filename = ale#Escape(bufname(a:buffer))
20     let l:options = ale#Var(a:buffer, 'c_clangformat_options')
21     let l:style_option = ale#Var(a:buffer, 'c_clangformat_style_option')
22     let l:use_local_file = ale#Var(a:buffer, 'c_clangformat_use_local_file')
23
24     if l:style_option isnot# ''
25         let l:style_option = '-style=' . "'" . l:style_option . "'"
26     endif
27
28     if l:use_local_file
29         let l:config = ale#path#FindNearestFile(a:buffer, '.clang-format')
30
31         if !empty(l:config)
32             let l:style_option = '-style=file'
33         endif
34     endif
35
36     if l:style_option isnot# ''
37         let l:options .= ' ' . l:style_option
38     endif
39
40     let l:command = l:executable . ' --assume-filename=' . l:filename
41
42     if l:options isnot# ''
43         let l:command .= ' ' . l:options
44     endif
45
46     return {'command': l:command}
47 endfunction