From 4dd84d7165e40f6014226dca0810562888ee9c48 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 29 Sep 2015 22:35:58 +0900 Subject: [PATCH] [BTags] Try --language-force option the first time --- autoload/fzf/vim.vim | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 5e2c6f8..af78a89 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -379,11 +379,22 @@ endfunction " BTags " ------------------------------------------------------------------ function! s:btags_source() - let lines = map(split(system(printf( - \ 'ctags -f - --sort=no --excmd=number %s', - \ expand('%:S'))), "\n"), 'split(v:val, "\t")') + if !filereadable(expand('%')) + throw 'Save the file first' + endif + + for cmd in [ + \ printf('ctags -f - --sort=no --excmd=number --language-force=%s %s', &filetype, expand('%:S')), + \ printf('ctags -f - --sort=no --excmd=number %s', expand('%:S'))] + let lines = map(split(system(cmd), "\n"), 'split(v:val, "\t")') + if !v:shell_error + break + endif + endfor if v:shell_error - throw 'Failed to extract tags' + throw get(lines, 0, 'Failed to extract tags') + elseif empty(lines) + throw 'No tags found' endif return map(s:align_lists(lines), 'join(v:val, "\t")') endfunction