~gpanders/dotfiles

ref: c8e63bac959db19c138dcc3198a56514f0b444ff dotfiles/.vim/autoload/taglist.vim -rw-r--r-- 1.6 KiB
c8e63bacGreg Anders Manage dotfiles directly in home directory 1 year, 3 months 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
function! s:tagjump()
  let l = getline('.')
  let cmd = matchstr(l, '^[^\t]\+\t\zs.*$')
  wincmd w
  let magic = &magic
  set nomagic
  call cursor(1, 1)
  execute s:escape(cmd)
  let &magic = magic
endfunction

function! s:escape(cmd)
  return substitute(a:cmd, '.\zs/\ze.', '\\/', 'g')
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), 'len(v:val.name)'))
  call map(tags, 'printf("[%s] %s\t%s", v:val.kind, v:val.name, s:unescape(v:val.cmd))')

  " Syntax of current buffer
  let syn = &syntax

  for win in filter(range(1, winnr('$')), 'getwinvar(v:val, "taglist")')
    execute win . 'windo close'
  endfor
  botright 10new
  let w:taglist = 1
  nnoremap <buffer> <silent> <CR> :<C-U>call <SID>tagjump()<CR>
  nnoremap <buffer> q <C-W>c
  silent file Taglist
  call setline(1, tags)
  let &l:tabstop = max([maxtaglen + 10, 40])
  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 nobuflisted buftype=nofile bufhidden=hide noswapfile
  setlocal nomodifiable cursorline conceallevel=2 concealcursor=nc nonumber nowrap
endfunction