[Tags] Support multiple tags files
We also apply --nth 1..2 by default to limit the search scope. Close #106 Related #5, #329
This commit is contained in:
parent
e4f79f6e98
commit
06a8b870c0
2 changed files with 37 additions and 19 deletions
|
@ -29,8 +29,10 @@ set cpo&vim
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
|
|
||||||
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
||||||
let s:which_bin = executable('ruby') ? '/bin/preview.rb' : '/bin/preview.sh'
|
let s:bin_dir = expand('<sfile>:h:h:h').'/bin/'
|
||||||
let s:bin = { 'preview': expand('<sfile>:h:h:h') . s:which_bin }
|
let s:bin = {
|
||||||
|
\ 'preview': s:bin_dir.executable('ruby') ? 'preview.rb' : 'preview.sh',
|
||||||
|
\ 'tags': s:bin_dir.'tags.pl' }
|
||||||
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type('')}
|
let s:TYPE = {'dict': type({}), 'funcref': type(function('call')), 'string': type('')}
|
||||||
|
|
||||||
" [[options to wrap], preview window expression, [toggle-preview keys...]]
|
" [[options to wrap], preview window expression, [toggle-preview keys...]]
|
||||||
|
@ -727,9 +729,12 @@ function! s:tags_sink(lines)
|
||||||
let [magic, &magic, wrapscan, &wrapscan, acd, &acd] = [&magic, 0, &wrapscan, 1, &acd, 0]
|
let [magic, &magic, wrapscan, &wrapscan, acd, &acd] = [&magic, 0, &wrapscan, 1, &acd, 0]
|
||||||
for line in a:lines[1:]
|
for line in a:lines[1:]
|
||||||
try
|
try
|
||||||
let parts = split(line, '\t\zs')
|
let parts = split(line, '\t\zs')
|
||||||
let excmd = matchstr(join(parts[2:], ''), '^.*\ze;"\t')
|
let excmd = matchstr(join(parts[2:-2], '')[:-2], '^.*\ze;"\t')
|
||||||
call s:open(cmd, parts[1][:-2])
|
let base = fnamemodify(parts[-1], ':h')
|
||||||
|
let relpath = parts[1][:-2]
|
||||||
|
let abspath = relpath =~ '^/' ? relpath : join([base, relpath], '/')
|
||||||
|
call s:open(cmd, abspath)
|
||||||
execute excmd
|
execute excmd
|
||||||
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
|
call add(qfl, {'filename': expand('%'), 'lnum': line('.'), 'text': getline('.')})
|
||||||
catch /^Vim:Interrupt$/
|
catch /^Vim:Interrupt$/
|
||||||
|
@ -769,22 +774,20 @@ function! fzf#vim#tags(query, ...)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let tagfile = tagfiles()[0]
|
let tagfiles = tagfiles()
|
||||||
" We don't want to apply --ansi option when tags file is large as it makes
|
let v2_limit = 1024 * 1024 * 200
|
||||||
" processing much slower.
|
for tagfile in tagfiles
|
||||||
let tagsize = getfsize(tagfile)
|
let v2_limit -= getfsize(tagfile)
|
||||||
if tagsize > 1024 * 1024 * 20
|
if v2_limit < 0
|
||||||
let proc = 'grep -av ''^\!'' '
|
break
|
||||||
let copt = tagsize > 1024 * 1024 * 200 ? '--algo=v1 ' : ''
|
endif
|
||||||
else
|
endfor
|
||||||
let proc = 'perl -ne ''unless (/^\!/) { s/^(.*?)\t(.*?)\t/'.s:yellow('\1', 'Function').'\t'.s:blue('\2', 'String').'\t/; print }'' '
|
let opts = v2_limit < 0 ? '--algo=v1 ' : ''
|
||||||
let copt = '--ansi '
|
|
||||||
endif
|
|
||||||
return s:fzf('tags', {
|
return s:fzf('tags', {
|
||||||
\ 'source': proc.shellescape(fnamemodify(tagfile, ':t')),
|
\ 'source': shellescape(s:bin.tags).' '.join(map(tagfiles, 'shellescape(fnamemodify(v:val, ":p"))')),
|
||||||
\ 'sink*': s:function('s:tags_sink'),
|
\ 'sink*': s:function('s:tags_sink'),
|
||||||
\ 'dir': fnamemodify(tagfile, ':h'),
|
\ 'options': opts.'--nth 1..2 --with-nth ..-2 -m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}, a:000)
|
||||||
\ 'options': copt.'-m --tiebreak=begin --prompt "Tags> "'.s:q(a:query)}, a:000)
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" ------------------------------------------------------------------
|
" ------------------------------------------------------------------
|
||||||
|
|
15
bin/tags.pl
Executable file
15
bin/tags.pl
Executable file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
|
||||||
|
foreach my $file (@ARGV) {
|
||||||
|
open my $lines, $file;
|
||||||
|
while (<$lines>) {
|
||||||
|
unless (/^\!/) {
|
||||||
|
s/^[^\t]*/sprintf("%-24s", $&)/e;
|
||||||
|
s/$/\t$file/;
|
||||||
|
print;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $lines;
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue