Opening a file without tags causes errors? #77

Closed
jhogendorn opened this Issue Jun 2, 2012 · 25 comments

Comments

Projects
None yet
7 participants

When i open a file and i dont have a tags file specified, i get this:

Error detected while processing /Volumes/Storage/Users/joshua/Library/Config/Vim/.vim/bundle/TagBar/autoload/tagbar.vim:
line 75:
E121: Undefined variable: g:tagbar_iconchars
E15: Invalid expression: g:tagbar_iconchars[0]
line 76:
E121: Undefined variable: g:tagbar_iconchars
E15: Invalid expression: g:tagbar_iconchars[1]
Error detected while processing function 25_postSourceActions..7..25_echo..tagbar#currenttag..26_Init..26_CheckForExCtags..26_EscapeCtagsCmd:
line 29:
E121: Undefined variable: g:tagbar_systemenc
E15: Invalid expression: g:tagbar_systemenc != &encoding
Error detected while processing function 25_postSourceActions..7..25_echo..tagbar#currenttag..26_Init..26_GetSupportedFiletypes..26_EscapeCtagsCmd:
line 29:
E121: Undefined variable: g:tagbar_systemenc
E15: Invalid expression: g:tagbar_systemenc != &encoding
Error detected while processing function 25_postSourceActions..7..25_echo:
line 1:
".vimrc" 396L, 10514C
Error detected while processing function 26_AutoUpdate..26_ProcessFile..26_ExecuteCtagsOnFile..26_EscapeCtagsCmd:
line 29:
E121: Undefined variable: g:tagbar_systemenc
E15: Invalid expression: g:tagbar_systemenc != &encoding
Error detected while processing function 26_AutoUpdate..26_ProcessFile..193:
line 28:
E121: Undefined variable: g:tagbar_foldlevel
E15: Invalid expression: g:tagbar_foldlevel == 0 ? 1 : kind.fold
E121: Undefined variable: g:tagbar_foldlevel
E15: Invalid expression: g:tagbar_foldlevel == 0 ? 1 : kind.fold
E121: Undefined variable: g:tagbar_foldlevel
E15: Invalid expression: g:tagbar_foldlevel == 0 ? 1 : kind.fold
E121: Undefined variable: g:tagbar_foldlevel
E15: Invalid expression: g:tagbar_foldlevel == 0 ? 1 : kind.fold
E121: Undefined variable: g:tagbar_foldlevel
E15: Invalid expression: g:tagbar_foldlevel == 0 ? 1 : kind.fold
line 40:
E121: Undefined variable: g:tagbar_foldlevel
E15: Invalid expression: g:tagbar_foldlevel
Error detected while processing function 26_AutoUpdate..26_ProcessFile..26_ParseTagline:
line 62:
Your ctags and Tagbar configurations are out of sync! Please read ':help tagbar-extend'.
Error detected while processing function 26_AutoUpdate..26_ProcessFile:
line 46:
E171: Missing :endif
Error detected while processing function 26_AutoUpdate:
line 37:
E171: Missing :endif
Error detected while processing function 4_StarSetf:
line 2:
E171: Missing :endif

any ideas?

Owner

majutsushi commented Jun 3, 2012

Tagbar doesn't use tags files, so that can't have anything to do with it. I tried reproducing the error with your configuration setup (on Linux), but it works fine for me there. Could you give an example of how exactly you could reproduce the error? It almost looks like Vim is trying to load autoload/tagbar.vim before plugins/tagbar.vim, but I have no idea how that could happen. And that NERDTree error message there in the middle looks suspicious, too.

Owner

majutsushi commented Jun 10, 2012

Are you still having this problem? I would like to release a new stable version soon and want to be reasonably sure not to have left any bugs in. Thanks!

im finding it... erratic. i wouldnt hold up on my account, i'm trying to debug it when i get chances in between everything else. im more inclined to say its a problem in my config at this stage.

Owner

majutsushi commented Jun 10, 2012

With regard to my earlier comment about the order of files being loaded maybe the :scriptnames command could be useful to determine whether the plugin files are really loaded in the wrong order. If yes then there really must be something strange going on.

im only seeing one tagbar item being loaded from scriptnames

  1: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/vimrc
  2: ~/.vimrc
  3: ~/Library/Config/Vim/.vim/autoload/pathogen.vim
  4: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/filetype.vim
  5: ~/Library/Config/Vim/.vim/bundle/CoffeeScript/ftdetect/coffee.vim
  6: ~/Library/Config/Vim/.vim/bundle/CoffeeScript/ftdetect/eco.vim
  7: ~/Library/Config/Vim/.vim/bundle/Less/ftdetect/less.vim
  8: ~/Library/Config/Vim/.vim/bundle/Markdown/ftdetect/markdown.vim
  9: ~/Library/Config/Vim/.vim/bundle/Twig/ftdetect/twig.vim
 10: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/ftplugin.vim
 11: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/indent.vim
 12: ~/Library/Config/Vim/.vim/colors/molokai.vim
 13: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/syntax/syntax.vim
 14: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/syntax/synload.vim
 15: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/syntax/syncolor.vim
 17: ~/Library/Config/Vim/.vim/bundle/ColorChart/plugin/colorchart.vim
 18: ~/Library/Config/Vim/.vim/bundle/CtrlP/plugin/ctrlp.vim
 19: ~/Library/Config/Vim/.vim/bundle/CtrlP/autoload/ctrlp/mrufiles.vim
 20: ~/Library/Config/Vim/.vim/bundle/Fugitive/plugin/fugitive.vim
 21: ~/Library/Config/Vim/.vim/bundle/Gist/plugin/gist.vim
 22: ~/Library/Config/Vim/.vim/bundle/Gundo/plugin/gundo.vim
 23: ~/Library/Config/Vim/.vim/bundle/IndentGuides/plugin/indent_guides.vim
 24: ~/Library/Config/Vim/.vim/bundle/IndentGuides/autoload/indent_guides.vim
 25: ~/Library/Config/Vim/.vim/bundle/NERDCommenter/plugin/NERD_commenter.vim
 26: ~/Library/Config/Vim/.vim/bundle/NERDTree/plugin/NERD_tree.vim
 27: ~/Library/Config/Vim/.vim/bundle/NERDTree/nerdtree_plugin/exec_menuitem.vim
 28: ~/Library/Config/Vim/.vim/bundle/NERDTree/nerdtree_plugin/fs_menu.vim
 29: ~/Library/Config/Vim/.vim/bundle/Octopress/plugin/octopress.vim
 30: ~/Library/Config/Vim/.vim/bundle/Powerline/plugin/Powerline.vim
 31: ~/Library/Config/Vim/.vim/bundle/Scratch/plugin/scratch.vim
 32: ~/Library/Config/Vim/.vim/bundle/Sessionman/plugin/sessionman.vim
 33: ~/Library/Config/Vim/.vim/bundle/Snipmate/plugin/snipMate.vim
 34: ~/Library/Config/Vim/.vim/bundle/SuperTab/plugin/supertab.vim
 35: ~/Library/Config/Vim/.vim/bundle/Surround/plugin/surround.vim
 36: ~/Library/Config/Vim/.vim/bundle/Syntastic/plugin/syntastic.vim
 37: ~/Library/Config/Vim/.vim/bundle/TagBar/plugin/tagbar.vim
 38: ~/Library/Config/Vim/.vim/bundle/YankStack/plugin/yankstack.vim
 39: ~/Library/Config/Vim/.vim/bundle/YankStack/autoload/yankstack.vim
 40: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/getscriptPlugin.vim
 41: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/gzip.vim
 42: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/matchparen.vim
 43: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/netrwPlugin.vim
 44: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/rrhelper.vim
 45: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/spellfile.vim
 46: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/tarPlugin.vim
 47: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/tohtml.vim
 48: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/vimballPlugin.vim
 49: /usr/local/Cellar/macvim/7.3-64/MacVim.app/Contents/Resources/vim/runtime/plugin/zipPlugin.vim
 50: ~/Library/Config/Vim/.vim/bundle/Snipmate/after/plugin/snipMate.vim
 51: ~/Library/Config/Vim/.vim/bundle/Powerline/autoload/Pl.vim
 52: ~/Library/Config/Vim/.vim/bundle/Powerline/Powerline_default_default_fancy.cache
 53: ~/Library/Config/Vim/.vim/bundle/Powerline/autoload/Pl/Match.vim
 54: ~/Library/Config/Vim/.vim/bundle/Powerline/autoload/Powerline/Functions.vim
 55: ~/Library/Config/Vim/.vim/bundle/Powerline/autoload/Powerline/Functions/fugitive.vim
 56: ~/Library/Config/Vim/.vim/bundle/Powerline/autoload/Powerline/Functions/syntastic.vim

having said that, when i started vim to get scriptnames just now, no error. so yeah. hrm

Might have something to do with powerline, as per default it executes the tagbar#currenttag on any file buffer (and/or empty buffer if for ex you have set laststatus=2 in your vimrc).

especially this issue : https://github.com/Lokaltog/vim-powerline/issues/139

Another thought : maybe it's due to the order in which Pathogen (when used) loads modules, which as far as I can tell is the order in which the submodules are registered in .gitconfig, and as this is highly usercase dependant,... I happen to have that bug (another plugin not playing nice with tagbar) popup sometimes, and just do a reordering of .gitconfigand "bug" goes away. Mightbe interesting to know if this happens with vundle or vim-addon-manager (as latest includes npm/composer-like dependancy management, it might be on the safe side)

And by the way : tagbar is so f##$ng awesome !**

Owner

majutsushi commented Jun 19, 2012

Ah, that seems to be the problem. Apparently some plugins may call autoloaded Tagbar functions like tagbar#currenttag() from their plugin/ files, and if those plugins got loaded before Tagbar then the autoload/tagbar.vim file gets loaded before the plugin/tagbar.vim file which will result in the above error message. I have just committed a change that explicitly loads the plugin file in such a case, so I think that should fix it. Could anyone affected please test whether that indeed fixes the error?

By the way, I don't think the submodule order should matter -- pathogen just looks at the directory in alphabetic order, not at the git internals. But maybe there was something else going on that confused the issue a bit.

Thanks!

You're right, nothing to do with pathogen (only just checked, sorry).

Alas, patch does not fix the problem on a fresh install with latest commits of all bundles. And vim-powerline + tagbar is the culprit (tried with and without powerline on fresh installs).
IMO, problem lies with powerline doing its stuff prematurely. It should be fixed in powerline by making a habbit of triggering plugin-dependant function calls only on special "events" (buffenter, buffchange,...)

instead of doing (for ex)
(code is not from vim-powerline but my own)

" display current git branch
set statusline+=%5*
set statusline+=%{fugitive#statusline()}
set statusline+=%*

one should do

" display current git branch
set statusline+=%5*
set statusline+=%{CleverInsertFugitivStuff()}
set statusline+=%*

(as scrooloose (Martin Grenfell) taught me to do back in the day)

where CleverInsertFugitivStuff() does the checking, binding to special events (buffchange,...), deferring (defer until first Buffenter,...), ... . That's what I do in my personnal statusbar plugin.

Or use variables like

let g:myAwesomeStatuslinePlugin_buffNameToAvoid ='__Tag_List__\|COMMIT_EDITMSG'

and make an autocommand modify that GLOB afterward (or whatever). Main reason why I never publicized my own statusline plugin as keeping up with other plugins' dev when API is not stable, and my own API is crappy, is a nightmare ! (and I never had any issue with yours)

submitted following issue : Lokaltog/vim-powerline/issues/157

NB: sorry for the many edits, but as there's no previewing in comments...
NB2 : powerline being the highest candy-tasting statusline plugin since vi was born, we might excpect to see it get wide adoption soooon.

As mentioned this could be related to Lokaltog/vim-powerline#152 or Lokaltog/vim-powerline#157. Do you have any suggestions to how we can use tagbar#currenttag() in the statusline?

I've tried to create a wrapper function that checks if tagbar is loaded, but neither of these solutions work:

let ret = ''
if exists('*tagbar#currenttag')
    let ret = tagbar#currenttag('%s', '')
endif

let ret = ''
if exists('g:loaded_tagbar') && g:loaded_tagbar == 1
    let ret = tagbar#currenttag('%s', '')
endif

try
    let ret = tagbar#currenttag('%s', '')
catch /.*/
    let ret = ''
endtry

The first two methods work, but only after opening Tagbar. Is it possible for tagbar#currenttag() to load all dependencies the first time it's run?

@Lokaltog Lokaltog added a commit to Lokaltog/vim-powerline that referenced this issue Jun 22, 2012

@Lokaltog Lokaltog Create temporary fix for Tagbar segment
This update adds a wrapper function that checks if Tagbar is loaded
before trying to call `tagbar#currenttag()`. Unfortunately this only
works *after* Tagbar has been opened, so the Tagbar/current tag segment
will be empty until Tagbar has been opened for the first time.

Refs #152.
Refs majutsushi/tagbar#77.
5948dd5
Owner

majutsushi commented Jun 22, 2012

As far as I can see the situation is this: If you use the bundle approach to Vim plugins, then Powerline will be loaded before Tagbar (since p comes before t), so it will be impossible to test for any Tagbar variables/functions etc, no matter whether they're autoloaded ones or not.

So there are two ways to address this problem that I can see:

  • Use a deferred technique for configuring the statusline like @peterhost is suggesting above. This is probably the cleanest approach, but requires some restructuring work.
  • Try to load Tagbar explicitly with :runtime plugin/tagbar.vim and then check for it with exists(':Tagbar') > 0 (since :runtime doesn't report loading failures without :verbose). I think that should work, but I haven't tested it.

verbose answer

The way I used to do it :

autoload

somewhere, i just SET this var :

let b:statusline_tartifyGIT="anything"

plugin

Second statusline()

function!  tartify#GITPS1#statusline(item, ...)

  if match(expand("%f"), g:tartify_buffNameToAvoid) >= 0 | return "" | endif

  " CACHING
  " as the pr0n master once said, "we gawts to cache"
  if !exists("b:statusline_tartifyGIT")
    "
    " we simply call the "tartify" shell script with the "v" option
    "
    "     tartify v
    "
    " from wherever we might be (working dir), split the result, and
    " process it


      let b:statusline_tartifyGIT = {}

    (do stuff...)

end function

Then setstatusline()

" -------- STATUSLINE -----------------{{{1
function tartify#GITPS1#setstatusline()
  set statusline+=%1*
  set statusline+=%{tartify#GITPS1#statusline('repository')}

  " here I wished to reproduct the colored approach to showing the
  " 'extras' (unstaged files, uncommited changes,...) in a colored
  " way, as is done in the bashps1 shell script, instead of using
  " the usual *+%^ symbols usual in GIT_PS1, as I never can
  " remember which is which.
  " So this too will be "**Tartified**"
  "
  set statusline+=%7*
  "set statusline+=%#DiffAdd#
  set statusline+=%{tartify#GITPS1#statusline('branch','unstaged')}
  set statusline+=%{tartify#GITPS1#statusline('branch','unstagedWithUntracked')}
  set statusline+=%{tartify#GITPS1#statusline('branch','uncommited')}
  set statusline+=%{tartify#GITPS1#statusline('branch','TOTOLESALAUD')}
  set statusline+=%{tartify#GITPS1#statusline('branch','uncommitedWithUntracked')}
  set statusline+=%{tartify#GITPS1#statusline('branch','unpushed')}
  set statusline+=%{tartify#GITPS1#statusline('branch','unpushedWithUntracked')}
  set statusline+=%{tartify#GITPS1#statusline('branch','ok')}
  set statusline+=%{tartify#GITPS1#statusline('branch','okWithUntracked')}
  set statusline+=%{tartify#GITPS1#statusline('branch','insideGitDir')}

  set statusline+=%3*
  set statusline+=%{tartify#GITPS1#statusline('remote')}

  set statusline+=%4*
  set statusline+=%{tartify#GITPS1#statusline('stash')}

  set statusline+=%5*
  set statusline+=%{tartify#GITPS1#statusline('time')}

  set statusline+=%*

          "        > this will return a "M" symbol which will be prepended
          "          to the branchname
          "
          "         "unmerged"


endfunction

then autocommands

" -------- CACHING Autocmd ------------{{{1

"recalculate the Gitps1 when idle, and after saving
autocmd cursorhold,CursorHoldI,bufwritepost * unlet! b:statusline_tartifyGIT

"next one too slow for my taste :
"recalculate Gitps1 when idle, after saving, on window change
"autocmd cursorhold,CursorHoldI,bufwritepost,InsertLeave,WinEnter,WinLeave * unlet! b:statusline_tartifyGIT


"  1}}}

Dunno if it can help

Owner

majutsushi commented Jun 22, 2012

One simple approach that could work: Don't install all the Powerline autocommands immediately when the plugin is loaded, but instead put them into a function and then install a VimEnter autocommand that calls that function.

Thanks, I'll see if that could solve this problem.

@Lokaltog Lokaltog added a commit to Lokaltog/vim-powerline that referenced this issue Jun 25, 2012

@Lokaltog Lokaltog Defer autocmd creation until all plugins are loaded
This update ensures that Powerline's autocmds aren't created until vim
has loaded all plugins and settings, to avoid errors with plugins that
are loaded after Powerline. The VimEnter event is used to accomplish
this.

Closes #152.
Refs majutsushi/tagbar#77.
7f53b5c

This commit seems to solve the issue for me. Thanks for the help!

Owner

majutsushi commented Jun 25, 2012

Great! I guess I can close this bug too, then.

majutsushi closed this Jun 25, 2012

This seems to have made everything ok. I had to update both tagbar and powerline to latest before the dust settled. Thanks guys!

same on my side. Good job :)

Owner

majutsushi commented Jun 28, 2012

That's good to know :)

tipu commented Sep 13, 2012

getting something similar:

121: Undefined variable: g:tagbar_iconchars
E15: Invalid expression: g:tagbar_iconchars[0]
line 15:
E121: Undefined variable: s:ic
E15: Invalid expression: s:ic =~ '[]^-]'
line 18:
E121: Undefined variable: g:tagbar_iconchars
E15: Invalid expression: g:tagbar_iconchars[1]
line 19:
E121: Undefined variable: s:io
E15: Invalid expression: s:io =~ '[]^-]'
line 23:
E121: Undefined variable: s:ic
E15: Invalid expression: '([' . s:ic . s:io . '] )@<=[^-+: ]+[^:]+$'
line 24:
E121: Undefined variable: s:pattern
E15: Invalid expression: "syntax match TagbarKind '" . s:pattern . "'"
line 26:
E121: Undefined variable: s:ic
E15: Invalid expression: '([' . s:ic . s:io . '][-+# ])@<=[^_]+(_?(([^)]+))? :)@='
line 27:
E121: Undefined variable: s:pattern
E15: Invalid expression: "syntax match TagbarScope '" . s:pattern . "'"
line 29:
E121: Undefined variable: s:ic
E15: Invalid expression: '[' . s:ic . s:io . ']([-+# ])@='
line 30:
E121: Undefined variable: s:pattern
E15: Invalid expression: "syntax match TagbarFoldIcon '" . s:pattern . "'"
line 32:
E121: Undefined variable: s:ic
E15: Invalid expression: '([' . s:ic . s:io . ' ])@<=+([^-+# ])@='
line 33:
E121: Undefined variable: s:pattern
E15: Invalid expression: "syntax match TagbarAccessPublic '" . s:pattern . "'"
line 34:
E121: Undefined variable: s:ic
E15: Invalid expression: '([' . s:ic . s:io . ' ])@<=#([^-+# ])@='
line 35:
E121: Undefined variable: s:pattern
E15: Invalid expression: "syntax match TagbarAccessProtected '" . s:pattern . "'"
line 36:
E121: Undefined variable: s:ic
E15: Invalid expression: '([' . s:ic . s:io . ' ])@<=-([^-+# ])@='
line 37:
E121: Undefined variable: s:pattern
E15: Invalid expression: "syntax match TagbarAccessPrivate '" . s:pattern . "'"
line 39:
E108: No such variable: "s:pattern"

Owner

majutsushi commented Sep 15, 2012

Are you sure you're using the latest github versions of Tagbar and PowerLine? This should have been fixed long ago.

@mhinton mhinton added a commit to mhinton/vim-powerline that referenced this issue Dec 10, 2012

@Lokaltog @mhinton Lokaltog + mhinton Create temporary fix for Tagbar segment
This update adds a wrapper function that checks if Tagbar is loaded
before trying to call `tagbar#currenttag()`. Unfortunately this only
works *after* Tagbar has been opened, so the Tagbar/current tag segment
will be empty until Tagbar has been opened for the first time.

Refs #152.
Refs majutsushi/tagbar#77.
0889787

@mhinton mhinton added a commit to mhinton/vim-powerline that referenced this issue Dec 10, 2012

@Lokaltog @mhinton Lokaltog + mhinton Create temporary fix for Tagbar segment
This update adds a wrapper function that checks if Tagbar is loaded
before trying to call `tagbar#currenttag()`. Unfortunately this only
works *after* Tagbar has been opened, so the Tagbar/current tag segment
will be empty until Tagbar has been opened for the first time.

Refs #152.
Refs majutsushi/tagbar#77.
99ffaf0

@mhinton mhinton added a commit to mhinton/vim-powerline that referenced this issue Dec 10, 2012

@Lokaltog @mhinton Lokaltog + mhinton Create temporary fix for Tagbar segment
This update adds a wrapper function that checks if Tagbar is loaded
before trying to call `tagbar#currenttag()`. Unfortunately this only
works *after* Tagbar has been opened, so the Tagbar/current tag segment
will be empty until Tagbar has been opened for the first time.

Refs #152.
Refs majutsushi/tagbar#77.
133137d

The same error. I use only file-line plugin.
Error detected while processing /home/me/git/configs/vim-plugins/tagbar/autoload/tagbar.vim:
line 43:
E121: Undefined variable: g:tagbar_iconchars
E15: Invalid expression: g:tagbar_iconchars[0]
line 44:
E121: Undefined variable: g:tagbar_iconchars
E15: Invalid expression: g:tagbar_iconchars[1]

Owner

majutsushi commented Apr 5, 2015

You don't have your runtimepath set correctly. You can't put full plugin installations into the ~/.vim/plugin directory, you have to add them to your runtimepath. Check out plugin managers like the simple pathogen or the more full-featured Vundle, NeoBundle or vim-plug that do that automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment