]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/ale_linters/bib/bibclean.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 / bib / bibclean.vim
1 " Author: Horacio Sanson - https://github.com/hsanson
2 " Description: Support for bibclean linter for BibTeX files.
3
4 call ale#Set('bib_bibclean_executable', 'bibclean')
5
6 function! ale_linters#bib#bibclean#GetCommand(buffer) abort
7     let l:executable = ale#Var(a:buffer, 'bib_bibclean_executable')
8
9     return ale#Escape(l:executable) . ' -file-position '
10 endfunction
11
12 function! ale_linters#bib#bibclean#get_type(str) abort
13     if a:str is# '??'
14         return 'E'
15     else
16         return 'W'
17     endif
18 endfunction
19
20 function! ale_linters#bib#bibclean#match_msg(line) abort
21     " Legacy message pattern works for bibclean <= v2.11.4. If empty, try
22     " the new message pattern for bibtex > v2.11.4
23     let l:matches_legacy = matchlist(a:line, '^\(.*\) "stdin", line \(\d\+\): \(.*\)$')
24
25     return ! empty(l:matches_legacy) ? l:matches_legacy
26     \ : matchlist(a:line, '^\(.*\) stdin:\(\d\+\):\(.*\)$')
27 endfunction
28
29 function! ale_linters#bib#bibclean#match_entry(line) abort
30     return matchlist(a:line, 'Entry   input byte=.* line=\(.*\) column=\(.*\) output .*$')
31 endfunction
32
33 function! ale_linters#bib#bibclean#match_value(line) abort
34     return matchlist(a:line, 'Value   input byte=.* line=\(.*\) column=\(.*\) output .*$')
35 endfunction
36
37 function! ale_linters#bib#bibclean#Handle(buffer, lines) abort
38     let l:output = []
39
40     let l:type = 'E'
41     let l:msg  = ''
42
43     for l:line in a:lines
44         if empty(l:msg)
45             let l:mlist = ale_linters#bib#bibclean#match_msg(l:line)
46
47             if !empty(l:mlist)
48                 let l:msg = l:mlist[3]
49                 let l:type = ale_linters#bib#bibclean#get_type(l:mlist[1])
50             endif
51         else
52             if l:type is# 'E'
53                 let l:mlist = ale_linters#bib#bibclean#match_entry(l:line)
54             else
55                 let l:mlist = ale_linters#bib#bibclean#match_value(l:line)
56             endif
57
58             if !empty(l:mlist)
59                 call add(l:output, {
60                 \ 'lnum': l:mlist[1],
61                 \ 'col': l:mlist[2],
62                 \ 'text': l:msg,
63                 \ 'type': l:type
64                 \})
65
66                 let l:msg = ''
67             endif
68         endif
69     endfor
70
71     return l:output
72 endfunction
73
74 call ale#linter#Define('bib', {
75 \   'name': 'bibclean',
76 \   'executable': {b -> ale#Var(b, 'bib_bibclean_executable')},
77 \   'command': function('ale_linters#bib#bibclean#GetCommand'),
78 \   'output_stream': 'stderr',
79 \   'callback': 'ale_linters#bib#bibclean#Handle',
80 \})