1
1
" Vim script
2
2
" Author: Peter Odding <peter@peterodding.com>
3
- " Last Change: November 21, 2014
3
+ " Last Change: March 15, 2015
4
4
" URL: http://peterodding.com/code/vim/easytags/
5
5
6
- let g: xolox #easytags#version = ' 3.9.1 '
6
+ let g: xolox #easytags#version = ' 3.10 '
7
7
let g: xolox #easytags#default_pattern_prefix = ' \C\<'
8
8
let g: xolox #easytags#default_pattern_suffix = ' \>'
9
9
@@ -104,7 +104,7 @@ function! xolox#easytags#register(global) " {{{2
104
104
let tagfiles = xolox#misc#option#split_tags (&tags )
105
105
let expanded = map (copy (tagfiles ), ' resolve(expand(v:val))' )
106
106
" Add the filename to the &tags option when the user hasn't done so already.
107
- let tagsfile = a: global ? g: easytags_file : xolox#easytags#get_tagsfile ()
107
+ let tagsfile = a: global ? g: easytags_file : xolox#easytags#get_file_type_specific_tagsfile ()
108
108
if index (expanded, xolox#misc#path#absolute (tagsfile)) == -1
109
109
" This is a real mess because of bugs in Vim?! :let &tags = '...' doesn't
110
110
" work on UNIX and Windows, :set tags=... doesn't work on Windows. What I
@@ -170,8 +170,7 @@ function! xolox#easytags#update(silent, filter_tags, filenames) " {{{2
170
170
let have_args = ! empty (a: filenames )
171
171
let starttime = xolox#misc#timer#start ()
172
172
let cfile = s: check_cfile (a: silent , a: filter_tags , have_args)
173
- let tagsfile = xolox#easytags#get_tagsfile ()
174
- let command_line = s: prep_cmdline (cfile , tagsfile, a: filenames )
173
+ let command_line = s: prep_cmdline (cfile , a: filenames )
175
174
if empty (command_line)
176
175
return 0
177
176
endif
@@ -183,11 +182,14 @@ function! xolox#easytags#update(silent, filter_tags, filenames) " {{{2
183
182
let params[' default_filetype' ] = xolox#easytags#filetypes#canonicalize (&filetype )
184
183
let params[' filter_tags' ] = a: filter_tags || async
185
184
let params[' have_args' ] = have_args
186
- if ! empty (g: easytags_by_filetype )
185
+ let dynamic_tagsfile = xolox#easytags#get_dynamic_tagsfile ()
186
+ if ! empty (dynamic_tagsfile)
187
+ let params[' tagsfile' ] = dynamic_tagsfile
188
+ elseif ! empty (g: easytags_by_filetype )
187
189
let params[' directory' ] = xolox#misc#path#absolute (g: easytags_by_filetype )
188
190
let params[' filetypes' ] = g: xolox #easytags#filetypes#ctags_to_vim
189
191
else
190
- let params[' tagsfile' ] = tagsfile
192
+ let params[' tagsfile' ] = xolox#easytags#get_global_tagsfile ()
191
193
endif
192
194
if async
193
195
call xolox#misc#async#call ({' function' : ' xolox#easytags#update#with_vim' , ' arguments' : [params], ' callback' : ' xolox#easytags#async_callback' })
@@ -234,7 +236,7 @@ function! s:check_cfile(silent, filter_tags, have_args) " {{{3
234
236
return cfile
235
237
endfunction
236
238
237
- function ! s: prep_cmdline (cfile , tagsfile, arguments) " {{{3
239
+ function ! s: prep_cmdline (cfile , arguments) " {{{3
238
240
let vim_file_type = xolox#easytags#filetypes#canonicalize (&filetype )
239
241
let custom_languages = xolox#misc#option#get (' easytags_languages' , {})
240
242
let language = get (custom_languages, vim_file_type, {})
@@ -252,7 +254,7 @@ function! s:prep_cmdline(cfile, tagsfile, arguments) " {{{3
252
254
let program = get (language , ' cmd' , xolox#easytags#ctags_command ())
253
255
if empty (program)
254
256
call xolox#misc#msg#warn (" easytags.vim %s: No 'cmd' defined for language '%s', and also no global default!" , g: xolox #easytags#version , vim_file_type)
255
- return
257
+ return ' '
256
258
endif
257
259
let cmdline = [program] + get (language , ' args' , [])
258
260
call add (cmdline, xolox#misc#escape#shell (get (language , ' stdout_opt' , ' -f-' )))
@@ -448,6 +450,36 @@ function! xolox#easytags#ctags_command() " {{{2
448
450
endfunction
449
451
450
452
function ! xolox#easytags#get_tagsfile () " {{{2
453
+ " Get the absolute pathname of the tags file to use. This function
454
+ " automatically selects the best choice from the following options (in
455
+ " descending order of preference):
456
+ "
457
+ " 1. Dynamic tags files (see `xolox#easytags#get_dynamic_tagsfile()`).
458
+ " 2. File type specific tags files (see `xolox#easytags#get_file_type_specific_tagsfile()`).
459
+ " 3. The global tags file (see `xolox#easytags#get_global_tagsfile()`).
460
+ "
461
+ " Returns the absolute pathname of the selected tags file.
462
+ "
463
+ " This function is no longer used by the vim-easytags plug-in itself because
464
+ " the vim-easytags plug-in needs to differentiate between the different
465
+ " types of tags files in every place where it deals with tags files. Because
466
+ " this is an externally callable function it is unclear to me if other code
467
+ " depends on it, this is the reason why I haven't removed it yet.
468
+ let tagsfile = xolox#easytags#get_dynamic_tagsfile ()
469
+ if empty (tagsfile)
470
+ let tagsfile = xolox#easytags#get_file_type_specific_tagsfile ()
471
+ endif
472
+ if empty (tagsfile)
473
+ let tagsfile = xolox#easytags#get_global_tagsfile ()
474
+ endif
475
+ return tagsfile
476
+ endfunction
477
+
478
+ function ! xolox#easytags#get_dynamic_tagsfile () " {{{2
479
+ " Get the pathname of the dynamic tags file to use. If the user configured
480
+ " dynamic tags files this function returns the pathname of the applicable
481
+ " dynamic tags file (which may not exist yet), otherwise it returns an empty
482
+ " string.
451
483
let tagsfile = ' '
452
484
" Look for a suitable project specific tags file?
453
485
let dynamic_files = xolox#misc#option#get (' easytags_dynamic_files' , 0 )
@@ -458,36 +490,51 @@ function! xolox#easytags#get_tagsfile() " {{{2
458
490
let directory = fnamemodify (tagsfile, ' :h' )
459
491
if filewritable (directory ) != 2
460
492
" If the directory of the dynamic tags file is not writable, we fall
461
- " back to a file type specific tags file or the global tags file.
493
+ " back to another type of tags file.
462
494
call xolox#misc#msg#warn (" easytags.vim %s: Dynamic tags files enabled but %s not writable so falling back." , g: xolox #easytags#version , directory )
463
495
let tagsfile = ' '
464
496
endif
465
497
endif
466
498
if ! empty (tagsfile)
467
- call xolox#misc#msg#debug ( " easytags.vim %s: Selected dynamic tags file %s. " , g: xolox #easytags# version , tagsfile )
499
+ return s: select_tags_file (tagsfile, ' dynamic ' )
468
500
endif
469
- " Check if a file type specific tags file is useful?
501
+ return ' '
502
+ endfunction
503
+
504
+ function ! xolox#easytags#get_file_type_specific_tagsfile () " {{{2
505
+ " Get the pathname of the file type specific tags file to use. If the user
506
+ " configured file type specific tags files this function returns the
507
+ " pathname of the applicable file type specific tags file (which may not
508
+ " exist yet), otherwise it returns an empty string.
470
509
let vim_file_type = xolox#easytags#filetypes#canonicalize (&filetype )
471
- if empty (tagsfile) && ! empty (g: easytags_by_filetype ) && ! empty (vim_file_type)
510
+ if ! empty (g: easytags_by_filetype ) && ! empty (vim_file_type)
472
511
let directory = xolox#misc#path#absolute (g: easytags_by_filetype )
473
512
let tagsfile = xolox#misc#path#merge (directory , vim_file_type)
474
513
if ! empty (tagsfile)
475
- call xolox#misc#msg#debug (" easytags.vim %s: Selected file type specific tags file %s." , g: xolox #easytags#version , tagsfile)
476
- endif
477
- endif
478
- " Default to the global tags file?
479
- if empty (tagsfile)
480
- let tagsfile = expand (xolox#misc#option#get (' easytags_file' ))
481
- if ! empty (tagsfile)
482
- call xolox#misc#msg#debug (" easytags.vim %s: Selected global tags file %s." , g: xolox #easytags#version , tagsfile)
514
+ return s: select_tags_file (tagsfile, ' file type specific' )
483
515
endif
484
516
endif
485
- " If the tags file exists, make sure it is writable!
486
- if filereadable (tagsfile) && filewritable (tagsfile) != 1
487
- let message = " The tags file %s isn't writable!"
488
- throw printf (message, fnamemodify (tagsfile, ' :~' ))
517
+ return ' '
518
+ endfunction
519
+
520
+ function ! xolox#easytags#get_global_tagsfile () " {{{2
521
+ " Get the pathname of the global tags file. Returns the absolute pathname of
522
+ " the global tags file.
523
+ let tagsfile = xolox#misc#option#get (' easytags_file' )
524
+ return s: select_tags_file (expand (tagsfile), ' global' )
525
+ endfunction
526
+
527
+ function ! s: select_tags_file (tagsfile, kind) " {{{2
528
+ " If the selected tags file exists, make sure its writable. Also provide the
529
+ " user with feedback about the tags file selection process.
530
+ if filereadable (a: tagsfile ) && filewritable (a: tagsfile ) != 1
531
+ let message = " The %s tags file %s isn't writable!"
532
+ throw printf (message, a: kind , fnamemodify (a: tagsfile , ' :~' ))
489
533
endif
490
- return xolox#misc#path#absolute (tagsfile)
534
+ " Provide the user with feedback about the tags file selection process.
535
+ call xolox#misc#msg#debug (" easytags.vim %s: Selected %s tags file %s." , g: xolox #easytags#version , a: kind , a: tagsfile )
536
+ " Canonicalize the tags file's pathname.
537
+ return xolox#misc#path#absolute (a: tagsfile )
491
538
endfunction
492
539
493
540
function ! xolox#easytags#syntax_groups_to_ignore () " {{{2
0 commit comments