Skip to content

Commit 67d82cf

Browse files
committed
Merge pull request #111: Give precedence to dynamic files over storage by filetype
I rewrote quite a bit of code in this pull request but I didn't change the behavior introduced by @cornerman (at least it was not my intention to do so). The main reason for rewriting was that the name xolox#easytags#get_global_tagsfile() "was a lie" because it could select either a file type specific tags files or the global tags file. I like functions whose name captures what they do so had to change things around in order to merge pull request 111 without having that name bother me :-). See also pull request 111 on GitHub: #111 Which came forth from issue 102: #102
2 parents f711ff6 + a60b1cf commit 67d82cf

File tree

3 files changed

+76
-29
lines changed

3 files changed

+76
-29
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ If you have questions, bug reports, suggestions, etc. the author can be contacte
351351

352352
## License
353353

354-
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
355-
© 2014 Peter Odding &lt;<peter@peterodding.com>&gt; and Ingo Karkat.
354+
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
355+
© 2015 Peter Odding &lt;<peter@peterodding.com>&gt; and Ingo Karkat.
356356

357357
Thanks go out to everyone who has helped to improve the vim-easytags plug-in (whether through pull requests, bug reports or personal e-mails).
358358

autoload/xolox/easytags.vim

Lines changed: 73 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" Vim script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: November 21, 2014
3+
" Last Change: March 15, 2015
44
" URL: http://peterodding.com/code/vim/easytags/
55

6-
let g:xolox#easytags#version = '3.9.1'
6+
let g:xolox#easytags#version = '3.10'
77
let g:xolox#easytags#default_pattern_prefix = '\C\<'
88
let g:xolox#easytags#default_pattern_suffix = '\>'
99

@@ -104,7 +104,7 @@ function! xolox#easytags#register(global) " {{{2
104104
let tagfiles = xolox#misc#option#split_tags(&tags)
105105
let expanded = map(copy(tagfiles), 'resolve(expand(v:val))')
106106
" 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()
108108
if index(expanded, xolox#misc#path#absolute(tagsfile)) == -1
109109
" This is a real mess because of bugs in Vim?! :let &tags = '...' doesn't
110110
" 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
170170
let have_args = !empty(a:filenames)
171171
let starttime = xolox#misc#timer#start()
172172
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)
175174
if empty(command_line)
176175
return 0
177176
endif
@@ -183,11 +182,14 @@ function! xolox#easytags#update(silent, filter_tags, filenames) " {{{2
183182
let params['default_filetype'] = xolox#easytags#filetypes#canonicalize(&filetype)
184183
let params['filter_tags'] = a:filter_tags || async
185184
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)
187189
let params['directory'] = xolox#misc#path#absolute(g:easytags_by_filetype)
188190
let params['filetypes'] = g:xolox#easytags#filetypes#ctags_to_vim
189191
else
190-
let params['tagsfile'] = tagsfile
192+
let params['tagsfile'] = xolox#easytags#get_global_tagsfile()
191193
endif
192194
if async
193195
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
234236
return cfile
235237
endfunction
236238

237-
function! s:prep_cmdline(cfile, tagsfile, arguments) " {{{3
239+
function! s:prep_cmdline(cfile, arguments) " {{{3
238240
let vim_file_type = xolox#easytags#filetypes#canonicalize(&filetype)
239241
let custom_languages = xolox#misc#option#get('easytags_languages', {})
240242
let language = get(custom_languages, vim_file_type, {})
@@ -252,7 +254,7 @@ function! s:prep_cmdline(cfile, tagsfile, arguments) " {{{3
252254
let program = get(language, 'cmd', xolox#easytags#ctags_command())
253255
if empty(program)
254256
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 ''
256258
endif
257259
let cmdline = [program] + get(language, 'args', [])
258260
call add(cmdline, xolox#misc#escape#shell(get(language, 'stdout_opt', '-f-')))
@@ -448,6 +450,36 @@ function! xolox#easytags#ctags_command() " {{{2
448450
endfunction
449451

450452
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.
451483
let tagsfile = ''
452484
" Look for a suitable project specific tags file?
453485
let dynamic_files = xolox#misc#option#get('easytags_dynamic_files', 0)
@@ -458,36 +490,51 @@ function! xolox#easytags#get_tagsfile() " {{{2
458490
let directory = fnamemodify(tagsfile, ':h')
459491
if filewritable(directory) != 2
460492
" 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.
462494
call xolox#misc#msg#warn("easytags.vim %s: Dynamic tags files enabled but %s not writable so falling back.", g:xolox#easytags#version, directory)
463495
let tagsfile = ''
464496
endif
465497
endif
466498
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')
468500
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.
470509
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)
472511
let directory = xolox#misc#path#absolute(g:easytags_by_filetype)
473512
let tagsfile = xolox#misc#path#merge(directory, vim_file_type)
474513
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')
483515
endif
484516
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, ':~'))
489533
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)
491538
endfunction
492539

493540
function! xolox#easytags#syntax_groups_to_ignore() " {{{2

doc/easytags.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ easytags. If you like this plug-in please vote for it on Vim Online [22].
717717
*easytags-license*
718718
License ~
719719

720-
This software is licensed under the MIT license [23]. Š 2014 Peter Odding
720+
This software is licensed under the MIT license [23]. © 2015 Peter Odding
721721
<peter@peterodding.com> and Ingo Karkat.
722722

723723
Thanks go out to everyone who has helped to improve the vim-easytags plug-in

0 commit comments

Comments
 (0)