Skip to content

Commit b5e0b6b

Browse files
committed
Tolerate corrupt tags files and ctags output (issue #13)
1 parent d727ac0 commit b5e0b6b

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

autoload/xolox/easytags.vim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,23 +389,33 @@ function! xolox#easytags#read_tagsfile(tagsfile) " {{{2
389389
" otherwise Vim might complain with "E432: Tags file not sorted".
390390
let headers = []
391391
let entries = []
392+
let num_invalid = 0
392393
for line in readfile(a:tagsfile)
393394
if line =~# '^!_TAG_'
394395
call add(headers, line)
395396
else
396-
call add(entries, xolox#easytags#parse_entry(line))
397+
let entry = xolox#easytags#parse_entry(line)
398+
if !empty(entry)
399+
call add(entries, entry)
400+
else
401+
let num_invalid += 1
402+
endif
397403
endif
398404
endfor
405+
if num_invalid > 0
406+
call xolox#misc#msg#warn("easytags.vim %s: Ignored %i invalid line(s) in %s!", g:easytags_version, num_invalid, a:tagsfile)
407+
endif
399408
return [headers, entries]
400409
endfunction
401410

402411
function! xolox#easytags#parse_entry(line) " {{{2
403-
return matchlist(a:line, '^\([^\t]\+\)\t\([^\t]\+\)\t\(.\+\)$')[1:3]
412+
let fields = split(a:line, '\t')
413+
return len(fields) >= 3 ? fields : []
404414
endfunction
405415

406416
function! xolox#easytags#parse_entries(lines) " {{{2
407417
call map(a:lines, 'xolox#easytags#parse_entry(v:val)')
408-
return a:lines
418+
return filter(a:lines, '!empty(v:val)')
409419
endfunction
410420

411421
function! xolox#easytags#write_tagsfile(tagsfile, headers, entries) " {{{2

plugin/easytags.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if &cp || exists('g:loaded_easytags')
1212
finish
1313
endif
1414

15-
let g:easytags_version = '2.4.4'
15+
let g:easytags_version = '2.4.5'
1616

1717
" Configuration defaults and initialization. {{{1
1818

0 commit comments

Comments
 (0)