aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/easytags.vim
blob: 324fa815b6f6b49e32a5ca58913f9b5ff5629b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
" Last Change: June 29, 2014
" URL: http://peterodding.com/code/vim/easytags/
" Requires: Exuberant Ctags (http://ctags.sf.net)

" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3114 1 :AutoInstall: easytags.zip

" Don't source the plug-in when it's already been loaded or &compatible is set.
if &cp || exists('g:loaded_easytags')
  finish
endif

" Make sure vim-misc is installed. {{{1

try
  " The point of this code is to do something completely innocent while making
  " sure the vim-misc plug-in is installed. We specifically don't use Vim's
  " exists() function because it doesn't load auto-load scripts that haven't
  " already been loaded yet (last tested on Vim 7.3).
  call type(g:xolox#misc#version)
catch
  echomsg "Warning: The vim-easytags plug-in requires the vim-misc plug-in which seems not to be installed! For more information please review the installation instructions in the readme (also available on the homepage and on GitHub). The vim-easytags plug-in will now be disabled."
  let g:loaded_easytags = 1
  finish
endtry

" Configuration defaults and initialization. {{{1

if !exists('g:easytags_file')
  if xolox#misc#os#is_win()
    let g:easytags_file = '~\_vimtags'
  else
    let g:easytags_file = '~/.vimtags'
  endif
endif

if !exists('g:easytags_by_filetype')
  let g:easytags_by_filetype = ''
endif

if !exists('g:easytags_events')
  let g:easytags_events = ['BufWritePost']
  if !exists('g:easytags_on_cursorhold') || g:easytags_on_cursorhold
    call extend(g:easytags_events, ['CursorHold', 'CursorHoldI'])
  endif
  if exists('g:easytags_always_enabled') && g:easytags_always_enabled
    call extend(g:easytags_events, ['BufReadPost', 'FocusGained', 'ShellCmdPost', 'ShellFilterPost'])
  endif
endif

if !exists('g:easytags_ignored_filetypes')
  let g:easytags_ignored_filetypes = '^tex$'
endif

if exists('g:easytags_ignored_syntax_groups')
  call xolox#misc#msg#warn("easytags.vim %s: The 'g:easytags_ignored_syntax_groups' option is no longer supported. It has been moved back into the code base for more flexible handling at runtime.", g:xolox#easytags#version)
endif

if !exists('g:easytags_python_script')
  let g:easytags_python_script = expand('<sfile>:p:h') . '/../misc/easytags/highlight.py'
endif

" Make sure Exuberant Ctags >= 5.5 is installed.
if !xolox#easytags#initialize('5.5')
  " Did the user configure the plug-in to suppress the regular warning message?
  if !(exists('g:easytags_suppress_ctags_warning') && g:easytags_suppress_ctags_warning)
    " Explain to the user what went wrong:
    if !exists('g:easytags_ctags_version') || empty(g:easytags_ctags_version)
      " Exuberant Ctags is not installed / could not be found.
      let s:msg = "easytags.vim %s: Plug-in not loaded because Exuberant Ctags isn't installed!"
      if executable('apt-get')
        let s:msg .= " On Ubuntu & Debian you can install Exuberant Ctags by"
        let s:msg .= " installing the package named `exuberant-ctags':"
        let s:msg .= " sudo apt-get install exuberant-ctags"
      else
        let s:msg .= " Please download & install Exuberant Ctags from http://ctags.sf.net"
      endif
      call xolox#misc#msg#warn(s:msg, g:xolox#easytags#version)
    else
      " The installed version is too old.
      let s:msg = "easytags.vim %s: Plug-in not loaded because Exuberant Ctags 5.5"
      let s:msg .= " or newer is required while you have version %s installed!"
      call xolox#misc#msg#warn(s:msg, g:xolox#easytags#version, g:easytags_ctags_version)
    endif
    unlet s:msg
  endif
  " Stop loading the plug-in; don't define the (automatic) commands.
  finish
endif

" 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 &tags is
" reset, we'll try again on the "VimEnter" automatic command event (below).
call xolox#easytags#register(1)

" The :UpdateTags and :HighlightTags commands. {{{1

command! -bar -bang -nargs=* -complete=file UpdateTags call xolox#easytags#update(0, <q-bang> == '!', [<f-args>])
command! -bar HighlightTags call xolox#easytags#highlight()
command! -bang TagsByFileType call xolox#easytags#update#convert_by_filetype(<q-bang> == '!')

" Automatic commands. {{{1

augroup PluginEasyTags
  autocmd!
  " This is the alternative way of registering the global tags file using
  " the automatic command event "VimEnter". Apparently this makes the
  " plug-in behave better when used together with tplugin?
  autocmd VimEnter * call xolox#easytags#register(1)
  " Define the automatic commands to perform updating/highlighting.
  for s:eventname in g:easytags_events
    if s:eventname !~? 'cursorhold'
      execute 'autocmd' s:eventname '* call xolox#easytags#autoload(' string(s:eventname) ')'
    endif
  endfor
  " Define an automatic command to register file type specific tags files?
  if !empty(g:easytags_by_filetype)
    autocmd FileType * call xolox#easytags#register(0)
  endif
  " After reloading a buffer the dynamic syntax highlighting is lost. The
  " following code makes sure the highlighting is refreshed afterwards.
  autocmd BufReadPost * unlet! b:easytags_last_highlighted
  " During :vimgrep each searched buffer triggers an asynchronous tags file
  " update resulting in races for the tags file. To avoid this we temporarily
  " disable automatic tags file updates during :vimgrep.
  autocmd QuickFixCmdPre *vimgrep* call xolox#easytags#disable_automatic_updates()
  autocmd QuickFixCmdPost *vimgrep* call xolox#easytags#restore_automatic_updates()
augroup END

" Use vim-misc to register an event handler for Vim's CursorHold and
" CursorHoldI events which is rate limited so that our event handler is never
" called more than once every interval.
if index(g:easytags_events, 'CursorHold') >= 0
  call xolox#misc#cursorhold#register({'function': 'xolox#easytags#autoload', 'arguments': ['CursorHold'], 'interval': xolox#misc#option#get('easytags_updatetime_min', 4000)/1000})
endif

" }}}1

" Make sure the plug-in is only loaded once.
let g:loaded_easytags = 1

" vim: ts=2 sw=2 et