From 77a318b10edda30c98fe678d3926dd1781e56dcf Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Sat, 23 Mar 2013 19:46:14 +1300 Subject: [PATCH] Don't disrupt the statusline if ctags fails --- autoload/tagbar.vim | 15 +++++++++++++-- doc/tagbar.txt | 14 +++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 7e055fb..7f1d332 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1714,6 +1714,14 @@ function! s:OpenWindow(flags) abort call s:InitWindow(autoclose) + " If the current file exists, but is empty, it means that it had a + " processing error before opening the window, most likely due to a call to + " currenttag() in the statusline. Remove the entry so an error message + " will be shown if the processing still fails. + if empty(s:known_files.get(curfile)) + call s:known_files.rm(curfile) + endif + call s:AutoUpdate(curfile, 0) call s:HighlightTag(1, 1, curline) @@ -2062,8 +2070,11 @@ function! s:ExecuteCtagsOnFile(fname, realfname, ftype) abort let ctags_output = s:ExecuteCtags(ctags_cmd) if v:shell_error || ctags_output =~ 'Warning: cannot open source file' - if !s:known_files.has(a:realfname) || - \ !empty(s:known_files.get(a:realfname)) + " Only display an error message if the Tagbar window is open and we + " haven't seen the error before. + if bufwinnr("__Tagbar__") != -1 && + \ (!s:known_files.has(a:realfname) || + \ !empty(s:known_files.get(a:realfname))) echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!' echomsg 'Executed command: "' . ctags_cmd . '"' if !empty(ctags_output) diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 184b9bc..3ca98a7 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -635,7 +635,8 @@ you want to, by calling the tagbar#currenttag() function. The current tag is exactly the same as would be highlighted in the Tagbar window if it is open. It is defined as the nearest tag upwards in the file starting from the cursor position. This means that for example in a function it should usually be the -name of the function. +name of the function. You can define which tags will be shown in this manner, +read |tagbar-extend| (especially the "kinds" entry) on how to do that. The function has the following signature: @@ -658,6 +659,10 @@ tagbar#currenttag({format}, {default} [, {flags}]) %{tagbar#currenttag('[%s] ','')} < then the function "myfunc" will be shown as "[myfunc()] ". +Note that if there is an error when processing the current file no error +message will be shown in order to not disrupt the statusline. If the function +doesn't seem to work right open the Tagbar window to see any error messages. + ============================================================================== 6. Extending Tagbar *tagbar-extend* @@ -687,10 +692,9 @@ support package for the language. Some tips on how to write such a program are given at the end of this section. Before writing your own extension have a look at the wiki -(https://github.com/majutsushi/tagbar/wiki/Support-for-additional-filetypes) -or try googling for existing ones. If you do end up creating your own -extension please consider adding it to the wiki so that others will be able to -use it, too. +(https://github.com/majutsushi/tagbar/wiki) or try googling for existing ones. +If you do end up creating your own extension please consider adding it to the +wiki so that others can benefit from it, too. Every type definition in Tagbar is a dictionary with the following keys: