~gpanders/dotfiles

ref: 8bbb6b42ada8c7e573ffba9c35b376dd6bec1d15 dotfiles/vim/.vim/autoload/taglist.vim -rw-r--r-- 1.9 KiB
8bbb6b42Greg Anders Move weechat config directory to .config/weechat 2 years ago
                                                                                
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
function! s:tagjump()
  let l = getline('.')
  let cmd = matchstr(l, '^[^\t]\+\t\zs[^\t]\+\ze;\?')
  wincmd w
  let magic = &magic
  set nomagic
  call execute(cmd)
  let &magic = magic
endfunction

function! s:unescape(cmd)
  return substitute(a:cmd, '[^\\]\zs\\/', '/', 'g')
endfunction

function! taglist#open(...)
  let abspath = expand('%:p')
  let relpath = fnamemodify(abspath, ':.')
  if a:0
    let pattern = a:1
  else
    let pattern = '.'
  endif

  let tags = filter(taglist(pattern, abspath),
        \ { _, val -> val.filename ==# relpath })

  let maxtaglen = max(map(copy(tags), { _, val -> len(val.name) }))
  let text = map(tags, { _, val ->
        \ '[' . val.kind . '] ' . val.name . "\t" . s:unescape(val.cmd) })

  " Syntax of current buffer
  let syn = &syntax

  let bufinfo = getbufinfo('Taglist')
  if !empty(bufinfo)
    " Buffer already exists
    let bufinfo = bufinfo[0]
    if !bufinfo.hidden && !empty(bufinfo.windows)
      let winnum = win_id2win(bufinfo.windows[0])
      execute winnum . 'wincmd w'
    else
      execute 'botright sb ' . bufinfo.bufnr . ' | resize 10'
    endif
    setlocal modifiable
    %delete_
  else
    botright new
    setlocal nobuflisted
    setlocal buftype=nofile
    setlocal bufhidden=hide
    setlocal noswapfile
    nnoremap <buffer> <silent> <CR> :<C-U>call <SID>tagjump()<CR>
    nnoremap <buffer> q <C-W>c
    10wincmd_
    execute 'silent file Taglist'
  endif
  let &l:tabstop = max([maxtaglen + 10, 40])
  put =tags
  0delete_
  let &l:syntax = syn
  " concealing patterns with matchadd must have priority 0 to avoid conflicts
  " with hlsearch. This seems to be a bug, see:
  " https://github.com/vim/vim/issues/2185
  call matchadd('Conceal', '\t\zs/^\s*', 0)
  call matchadd('Conceal', '$/$', 0)
  call matchadd('Comment', '^\[\w]')
  setlocal nomodifiable
  setlocal cursorline
  setlocal conceallevel=2
  setlocal concealcursor=nc
  setlocal nonumber
  setlocal nowrap
endfunction