aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/tlib_vim/autoload/tlib/signs.vim
blob: 16646807a5e55829909e54c56e26bb531f64af80 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
" @Author:      Tom Link (mailto:micathom AT gmail com?subject=[vim])
" @Website:     http://www.vim.org/account/profile.php?user_id=4037
" @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created:     2009-03-12.
" @Last Change: 2011-03-10.
" @Revision:    0.0.45

let s:save_cpo = &cpo
set cpo&vim


let s:base = 2327
let s:register = {}


" Clear all signs with name SIGN.
function! tlib#signs#ClearAll(sign) "{{{3
    " TLog a:sign
    for bn in keys(s:register)
        let idxs = keys(s:register)
        call filter(idxs, 's:register[v:val].sign == a:sign')
        " TLogVAR bns
        for idx in idxs
            exec 'sign unplace '. idx .' buffer='. s:register[idx].bn
            call remove(s:register, idx)
        endfor
    endfor
endf


" Clear all signs with name SIGN in buffer BUFNR.
function! tlib#signs#ClearBuffer(sign, bufnr) "{{{3
    for bn in keys(s:register)
        let idxs = keys(s:register)
        call filter(idxs, 's:register[v:val].sign == a:sign && s:register[v:val].bn == a:bufnr')
        " TLogVAR bns
        for idx in idxs
            exec 'sign unplace '. idx .' buffer='. s:register[idx].bn
            call remove(s:register, idx)
        endfor
    endfor
endf


" function! tlib#signs#Clear(sign, list) "{{{3
"     " TLogVAR a:sign
"     let done = []
"     for item in a:list
"         let bn = get(item, 'bufnr', -1)
"         if index(done, bn) == -1
"             let idxs = keys(s:register)
"             call filter(idxs, 's:register[v:val].sign == a:sign && s:register[v:val].bn == bn')
"             for idx in idxs
"                 exec 'sign unplace '. idx .' buffer='. s:register[idx].bn
"                 call remove(s:register, idx)
"             endfor
"             call add(done, bn)
"         endif
"     endfor
" endf


" Add signs for all locations in LIST. LIST must adhere with the 
" quickfix list format (see |getqflist()|; only the fields lnum and 
" bufnr are required).
"
" list:: a quickfix or location list
" sign:: a sign defined with |:sign-define|
function! tlib#signs#Mark(sign, list) "{{{3
    " TLogVAR a:sign
    for item in a:list
        let idx = s:SignId(item)
        if idx >= 0
            let lnum = get(item, 'lnum', 0)
            if lnum > 0
                let bn = get(item, 'bufnr')
                exec ':sign place '. idx .' line='. lnum .' name='. a:sign .' buffer='. bn
                let s:register[idx] = {'sign': a:sign, 'bn': bn}
            endif
        endif
    endfor
endf


function! s:SignId(item) "{{{3
    " TLogVAR a:item
    " let bn  = bufnr('%')
    let bn = get(a:item, 'bufnr', -1)
    if bn == -1
        return -1
    else
        let idx = s:base + bn * 500
        while has_key(s:register, idx)
            let idx += 1
        endwh
        return idx
    endif
endf



let &cpo = s:save_cpo
unlet s:save_cpo