]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/c/cc.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:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / c / cc.vim
1 " Author: w0rp <devw0rp@gmail.com>
2 " Description: A C compiler linter for C files with gcc/clang, etc.
3
4 call ale#Set('c_cc_executable', '<auto>')
5 call ale#Set('c_cc_options', '-std=c11 -Wall')
6 call ale#Set('c_cc_use_header_lang_flag', -1)
7 call ale#Set('c_cc_header_exts', ['h'])
8
9 function! ale_linters#c#cc#GetExecutable(buffer) abort
10     let l:executable = ale#Var(a:buffer, 'c_cc_executable')
11
12     " Default to either clang or gcc.
13     if l:executable is# '<auto>'
14         if ale#engine#IsExecutable(a:buffer, 'clang')
15             let l:executable = 'clang'
16         else
17             let l:executable = 'gcc'
18         endif
19     endif
20
21     return l:executable
22 endfunction
23
24 function! ale_linters#c#cc#GetCommand(buffer, output) abort
25     let l:cflags = ale#c#GetCFlags(a:buffer, a:output)
26     let l:ale_flags = ale#Var(a:buffer, 'c_cc_options')
27
28     if l:cflags =~# '-std='
29         let l:ale_flags = substitute(
30         \   l:ale_flags,
31         \   '-std=\(c\|gnu\)[0-9]\{2\}',
32         \   '',
33         \   'g')
34     endif
35
36     " Select the correct language flag depending on the executable, options
37     " and file extension
38     let l:executable = ale_linters#c#cc#GetExecutable(a:buffer)
39     let l:use_header_lang_flag = ale#Var(a:buffer, 'c_cc_use_header_lang_flag')
40     let l:header_exts = ale#Var(a:buffer, 'c_cc_header_exts')
41     let l:lang_flag = ale#c#GetLanguageFlag(
42     \   a:buffer,
43     \   l:executable,
44     \   l:use_header_lang_flag,
45     \   l:header_exts,
46     \   'c')
47
48     " -iquote with the directory the file is in makes #include work for
49     "  headers in the same directory.
50     "
51     " `-o /dev/null` or `-o null` is needed to catch all errors,
52     " -fsyntax-only doesn't catch everything.
53     return '%e -S -x ' . l:lang_flag
54     \   . ' -o ' . g:ale#util#nul_file
55     \   . ' -iquote %s:h'
56     \   . ale#Pad(l:cflags)
57     \   . ale#Pad(l:ale_flags) . ' -'
58 endfunction
59
60 call ale#linter#Define('c', {
61 \   'name': 'cc',
62 \   'aliases': ['gcc', 'clang'],
63 \   'output_stream': 'stderr',
64 \   'executable': function('ale_linters#c#cc#GetExecutable'),
65 \   'command': {b -> ale#c#RunMakeCommand(b, function('ale_linters#c#cc#GetCommand'))},
66 \   'callback': 'ale#handlers#gcc#HandleGCCFormatWithIncludes',
67 \})