2018-12-17 06:33:49 -05:00
|
|
|
" Author: Horacio Sanson - https://github.com/hsanson
|
|
|
|
" Description: Support for bibclean linter for BibTeX files.
|
|
|
|
|
|
|
|
call ale#Set('bib_bibclean_executable', 'bibclean')
|
|
|
|
|
|
|
|
function! ale_linters#bib#bibclean#GetCommand(buffer) abort
|
|
|
|
let l:executable = ale#Var(a:buffer, 'bib_bibclean_executable')
|
|
|
|
|
|
|
|
return ale#Escape(l:executable) . ' -file-position '
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#bib#bibclean#get_type(str) abort
|
|
|
|
if a:str is# '??'
|
2019-03-08 06:04:56 -05:00
|
|
|
return 'E'
|
2018-12-17 06:33:49 -05:00
|
|
|
else
|
2019-03-08 06:04:56 -05:00
|
|
|
return 'W'
|
2018-12-17 06:33:49 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#bib#bibclean#match_msg(line) abort
|
2020-12-04 16:15:32 -05:00
|
|
|
" Legacy message pattern works for bibclean <= v2.11.4. If empty, try
|
|
|
|
" the new message pattern for bibtex > v2.11.4
|
|
|
|
let l:matches_legacy = matchlist(a:line, '^\(.*\) "stdin", line \(\d\+\): \(.*\)$')
|
|
|
|
|
|
|
|
return ! empty(l:matches_legacy) ? l:matches_legacy
|
|
|
|
\ : matchlist(a:line, '^\(.*\) stdin:\(\d\+\):\(.*\)$')
|
2018-12-17 06:33:49 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#bib#bibclean#match_entry(line) abort
|
|
|
|
return matchlist(a:line, 'Entry input byte=.* line=\(.*\) column=\(.*\) output .*$')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#bib#bibclean#match_value(line) abort
|
|
|
|
return matchlist(a:line, 'Value input byte=.* line=\(.*\) column=\(.*\) output .*$')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ale_linters#bib#bibclean#Handle(buffer, lines) abort
|
|
|
|
let l:output = []
|
|
|
|
|
|
|
|
let l:type = 'E'
|
|
|
|
let l:msg = ''
|
|
|
|
|
|
|
|
for l:line in a:lines
|
2019-03-08 06:04:56 -05:00
|
|
|
if empty(l:msg)
|
|
|
|
let l:mlist = ale_linters#bib#bibclean#match_msg(l:line)
|
2018-12-17 06:33:49 -05:00
|
|
|
|
2019-03-08 06:04:56 -05:00
|
|
|
if !empty(l:mlist)
|
|
|
|
let l:msg = l:mlist[3]
|
|
|
|
let l:type = ale_linters#bib#bibclean#get_type(l:mlist[1])
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
if l:type is# 'E'
|
|
|
|
let l:mlist = ale_linters#bib#bibclean#match_entry(l:line)
|
|
|
|
else
|
|
|
|
let l:mlist = ale_linters#bib#bibclean#match_value(l:line)
|
|
|
|
endif
|
2018-12-17 06:33:49 -05:00
|
|
|
|
2019-03-08 06:04:56 -05:00
|
|
|
if !empty(l:mlist)
|
|
|
|
call add(l:output, {
|
|
|
|
\ 'lnum': l:mlist[1],
|
|
|
|
\ 'col': l:mlist[2],
|
|
|
|
\ 'text': l:msg,
|
|
|
|
\ 'type': l:type
|
|
|
|
\})
|
|
|
|
|
|
|
|
let l:msg = ''
|
|
|
|
endif
|
|
|
|
endif
|
2018-12-17 06:33:49 -05:00
|
|
|
endfor
|
|
|
|
|
|
|
|
return l:output
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('bib', {
|
|
|
|
\ 'name': 'bibclean',
|
2019-03-08 06:04:56 -05:00
|
|
|
\ 'executable': {b -> ale#Var(b, 'bib_bibclean_executable')},
|
|
|
|
\ 'command': function('ale_linters#bib#bibclean#GetCommand'),
|
2018-12-17 06:33:49 -05:00
|
|
|
\ 'output_stream': 'stderr',
|
|
|
|
\ 'callback': 'ale_linters#bib#bibclean#Handle',
|
|
|
|
\})
|