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

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / ale_linters / tex / chktex.vim
1 " Author: Andrew Balmos - <andrew@balmos.org>
2 " Description: chktex for LaTeX files
3
4 call ale#Set('tex_chktex_executable', 'chktex')
5 call ale#Set('tex_chktex_options', '-I')
6
7 function! ale_linters#tex#chktex#GetExecutable(buffer) abort
8     return ale#Var(a:buffer, 'tex_chktex_executable')
9 endfunction
10
11 function! ale_linters#tex#chktex#GetCommand(buffer, version) abort
12     let l:options = ''
13
14     " Avoid bug when used without -p (last warning has gibberish for a filename)
15     let l:options .= ' -v0 -p stdin -q'
16
17     " Avoid bug of reporting wrong column when using tabs (issue #723)
18     if ale#semver#GTE(a:version, [1, 7, 7])
19         let l:options .= ' -S TabSize=1'
20     endif
21
22     " Check for optional .chktexrc
23     let l:chktex_config = ale#path#FindNearestFile(a:buffer, '.chktexrc')
24
25     if !empty(l:chktex_config)
26         let l:options .= ' -l ' . ale#Escape(l:chktex_config)
27     endif
28
29     let l:options .= ' ' . ale#Var(a:buffer, 'tex_chktex_options')
30
31     return '%e' . l:options
32 endfunction
33
34 function! ale_linters#tex#chktex#Handle(buffer, lines) abort
35     " Mattes lines like:
36     "
37     " stdin:499:2:24:Delete this space to maintain correct pagereferences.
38     " stdin:507:81:3:You should enclose the previous parenthesis with `{}'.
39     let l:pattern = '^stdin:\(\d\+\):\(\d\+\):\(\d\+\):\(.\+\)$'
40     let l:output = []
41
42     for l:match in ale#util#GetMatches(a:lines, l:pattern)
43         call add(l:output, {
44         \   'lnum': l:match[1] + 0,
45         \   'col': l:match[2] + 0,
46         \   'text': l:match[4] . ' (' . (l:match[3]+0) . ')',
47         \   'type': 'W',
48         \})
49     endfor
50
51     return l:output
52 endfunction
53
54 call ale#linter#Define('tex', {
55 \   'name': 'chktex',
56 \   'executable': function('ale_linters#tex#chktex#GetExecutable'),
57 \   'command': {buffer -> ale#semver#RunWithVersionCheck(
58 \       buffer,
59 \       ale_linters#tex#chktex#GetExecutable(buffer),
60 \       '%e --version',
61 \       function('ale_linters#tex#chktex#GetCommand'),
62 \   )},
63 \   'callback': 'ale_linters#tex#chktex#Handle'
64 \})