File: postprocess.vim

package info (click to toggle)
vim-syntastic 3.10.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,844 kB
  • sloc: erlang: 248; python: 30; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 2,443 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
if exists('g:loaded_syntastic_postprocess_autoload') || !exists('g:loaded_syntastic_plugin')
    finish
endif
let g:loaded_syntastic_postprocess_autoload = 1

let s:save_cpo = &cpo
set cpo&vim

" Public functions {{{1

" merge consecutive blanks
function! syntastic#postprocess#compressWhitespace(errors) abort " {{{2
    for e in a:errors
        let e['text'] = substitute(e['text'], "\001", '', 'g')
        let e['text'] = substitute(e['text'], '\n', ' ', 'g')
        let e['text'] = substitute(e['text'], '\m\s\{2,}', ' ', 'g')
        let e['text'] = substitute(e['text'], '\m^\s\+', '', '')
        let e['text'] = substitute(e['text'], '\m\s\+$', '', '')
    endfor

    return a:errors
endfunction " }}}2

" remove spurious CR under Cygwin
function! syntastic#postprocess#cygwinRemoveCR(errors) abort " {{{2
    if has('win32unix')
        for e in a:errors
            let e['text'] = substitute(e['text'], '\r', '', 'g')
        endfor
    endif

    return a:errors
endfunction " }}}2

" decode XML entities
function! syntastic#postprocess#decodeXMLEntities(errors) abort " {{{2
    for e in a:errors
        let e['text'] = syntastic#util#decodeXMLEntities(e['text'])
    endfor

    return a:errors
endfunction " }}}2

" filter out errors referencing other files
function! syntastic#postprocess#filterForeignErrors(errors) abort " {{{2
    return filter(copy(a:errors), 'get(v:val, "bufnr") == ' . bufnr(''))
endfunction " }}}2

" make sure line numbers are not past end of buffers
" XXX: this loads all referenced buffers in memory
function! syntastic#postprocess#guards(errors) abort " {{{2
    let buffers = syntastic#util#unique(map(filter(copy(a:errors), 'v:val["valid"]'), 'str2nr(v:val["bufnr"])'))

    let guards = {}
    for b in buffers
        let guards[b] = len(getbufline(b, 1, '$'))
    endfor

    for e in a:errors
        if e['valid'] && e['lnum'] > guards[e['bufnr']]
            let e['lnum'] = guards[e['bufnr']]
        endif
    endfor

    return a:errors
endfunction " }}}2

" convert error messages from UTF-8 to the current encoding
function! syntastic#postprocess#iconv(errors) abort " {{{2
    if has('iconv') && &encoding !=# '' && &encoding !=# 'utf-8'
        for e in a:errors
            let e['text'] = iconv(e['text'], "utf-8", &encoding)
        endfor
    endif

    return a:errors
endfunction " }}}2

" }}}1

let &cpo = s:save_cpo
unlet s:save_cpo

" vim: set sw=4 sts=4 et fdm=marker: