Skip to content
This repository
Browse code

Enable deferring tags file registration (VimEnter)

By default the plug-in initializes the &tags option as soon as possible
so that the global tags file is available when using "vim -t some_tag".
If you don't use "vim -t" and want to defer registering the global tags
file until the interface has been initialized you can now set the global
variable g:easytags_register_late = 1.

This commit is based on a pull request from Daniel Hahler, I added the
option to enable either mode of initialization (I guess Daniel doesn't
use "vim -t some_tag", but I certainly do :-). Here's the original
commit message:

    Move calling RegisterTagsFile to `au VimEnter`.

    Calling RegisterTagsFile on VimEnter instead of when including the
    plugin appears to make it behave better when (re)setting 'tags' in
    vimrc.

    I do not remember if this is related to using tplugin only.
  • Loading branch information...
commit 3466f613e926645ac6fd6474cf0404adc416477b 1 parent fffde42
Daniel Hahler authored April 04, 2011 xolox committed April 11, 2011

Showing 1 changed file with 19 additions and 4 deletions. Show diff stats Hide diff stats

  1. 23  plugin/easytags.vim
23  plugin/easytags.vim
... ...
@@ -1,10 +1,10 @@
1 1
 " Vim plug-in
2 2
 " Author: Peter Odding <peter@peterodding.com>
3  
-" Last Change: March 19, 2011
  3
+" Last Change: April 11, 2011
4 4
 " URL: http://peterodding.com/code/vim/easytags/
5 5
 " Requires: Exuberant Ctags (http://ctags.sf.net)
6 6
 " License: MIT
7  
-" Version: 2.2.2
  7
+" Version: 2.2.3
8 8
 
9 9
 " Support for automatic update using the GLVS plug-in.
10 10
 " GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip
@@ -50,6 +50,10 @@ if !exists('g:easytags_include_members')
50 50
   let g:easytags_include_members = 0
51 51
 endif
52 52
 
  53
+if !exists('g:easytags_register_late')
  54
+  let g:easytags_register_late = 0
  55
+endif
  56
+
53 57
 function! s:InitEasyTags(version)
54 58
   " Check that the location of Exuberant Ctags has been configured or that the
55 59
   " correct version of the program exists in one of its default locations.
@@ -152,8 +156,13 @@ function! s:RegisterTagsFile()
152 156
   endif
153 157
 endfunction
154 158
 
155  
-" Let Vim know about the global tags file created by this plug-in.
156  
-call s:RegisterTagsFile()
  159
+" By default this plug-in initializes the &tags option as soon as possible so
  160
+" that the global tags file is available when using "vim -t some_tag". If you
  161
+" don't use "vim -t" and want to defer registering the global tags file until
  162
+" the interface has been initialized you can set g:easytags_register_late=1.
  163
+if !g:easytags_register_late
  164
+  call s:RegisterTagsFile()
  165
+endif
157 166
 
158 167
 " The :UpdateTags and :HighlightTags commands. {{{1
159 168
 
@@ -164,6 +173,12 @@ command! -bar HighlightTags call xolox#easytags#highlight()
164 173
 
165 174
 augroup PluginEasyTags
166 175
   autocmd!
  176
+  if g:easytags_register_late
  177
+    " This is the alternative way of registering the global tags file using
  178
+    " the automatic command event "VimEnter". Apparently this makes the
  179
+    " easytags plug-in behave better when used together with tplugin?
  180
+    autocmd VimEnter * call s:RegisterTagsFile()
  181
+  endif
167 182
   if g:easytags_always_enabled
168 183
     " TODO Also on FocusGained because tags files might be updated externally?
169 184
     autocmd BufReadPost,BufWritePost * call xolox#easytags#autoload()

3 notes on commit 3466f61

Daniel Hahler

Thanks for pulling it.

I was not aware that "-t" would stop working this way (at least would not be fully setup).

Is it possible to do both and remove the option for this? Like calling it on load and when entering Vim?
This way it would be setup for "-t", then vimrc might reset it, and then it gets re-fixed when entering Vim.

Is there something like "do this after any config" maybe?
I could imagine shipping this code in "after/plugin/easytags.vim"..

Peter Odding
Owner

Is it possible to do both and remove the option for this? Like calling it on load and when entering Vim?
This way it would be setup for "-t", then vimrc might reset it, and then it gets re-fixed when entering Vim.

Yes this seems like a better approach, I always like keeping the list of options as short as possible :-). I should have realized yesterday that I could just call s:RegisterTagsFile() twice because it's idempotent anyway...

Is there something like "do this after any config" maybe?

Not that I'm aware of. However, I was always under the impression that vimrc scripts are loaded before any plug-ins, otherwise it would be impossible to disable plug-ins by setting e.g. g:loaded_easytags = 1 in a vimrc script. Take this with a grain of salt though; I've never used tplugin and it might interact with Vim's plug-in loading in funky ways.

Peter Odding
Owner

I just committed c1635d6 which changes the tags file registration as you've suggested. Thanks for your input!

Please sign in to comment.
Something went wrong with that request. Please try again.