From fae8ddd3b6cdf823113ed2a911daa7d319885f7a Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Mon, 5 Sep 2011 20:32:33 +0200 Subject: Improve easytags_dynamic_files implementation (best of both worlds?) Some users want the plug-in to use existing project specific tags files but fall back to the global tags file or a file type specific tags file if a project specific tags file does not exist. Other users want the plug-in to automatically create project specific tags files. Both are reasonable options to have. I hope with this change we can all be happy :-) (see also issue #15 and issue #16 on GitHub). --- README.md | 11 +++++------ autoload/xolox/easytags.vim | 7 +++++-- doc/easytags.txt | 30 ++++++++++++++++++------------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 07d2903..1a9cc98 100644 --- a/README.md +++ b/README.md @@ -64,17 +64,16 @@ A leading `~` in the `g:easytags_file` variable is expanded to your current home ### The `g:easytags_dynamic_files` option -By default `:UpdateTags` only writes to the global tags file. If you use the following setting to enable project specific tags files: +By default `:UpdateTags` only writes to the global tags file, but it can be configured to look for project specific tags files by adding the following lines to your [vimrc script] [vimrc]: :set tags=./tags; - -You can enable this option so that the project specific tags files are written instead of the global tags file: - :let g:easytags_dynamic_files = 1 -When you enable this option, the easytags plug-in will expand the ['tags' option] [tags_opt] and use the first filename (whether the file exists or not). The tags option is reevaluated each time the plug-in runs, so the results can differ depending on the location of the current buffer or working directory. +You can change the name of the tags file, the important thing is that it's relative to your working directory or the buffer (using a leading `./`). When `g:easytags_dynamic_files` is set to 1 the easytags plug-in will write to the first existing tags file seen by Vim (based on the ['tags' option] [tags_opt]). In other words: If a project specific tags file is found it will be used, otherwise the plug-in falls back to the global tags file (or a file type specific tags file). + +If you set `g:easytags_dynamic_files` to 2 the easytags plug-in will automatically create project specific tags based on the first name in the 'tags' option. This disables the global tags file and file type specific tags files. -Note that this option takes precedence over `g:easytags_by_filetype`. +The ['tags' option] [tags_opt] is reevaluated each time the plug-in runs, so which tags file is selected can differ depending on the buffer and working directory. ### The `g:easytags_by_filetype` option diff --git a/autoload/xolox/easytags.vim b/autoload/xolox/easytags.vim index 5c5334e..39102e2 100644 --- a/autoload/xolox/easytags.vim +++ b/autoload/xolox/easytags.vim @@ -3,7 +3,7 @@ " Last Change: September 5, 2011 " URL: http://peterodding.com/code/vim/easytags/ -let g:xolox#easytags#version = '2.5.6' +let g:xolox#easytags#version = '2.5.7' " Public interface through (automatic) commands. {{{1 @@ -530,7 +530,10 @@ endfunction function! xolox#easytags#get_tagsfile() " {{{2 let tagsfile = '' " Look for a suitable project specific tags file? - if xolox#misc#option#get('easytags_dynamic_files', 0) + let dynamic_files = xolox#misc#option#get('easytags_dynamic_files', 0) + if dynamic_files == 1 + let tagsfile = get(tagfiles(), 0, '') + elseif dynamic_files == 2 let tagsfile = xolox#misc#option#eval_tags(&tags, 1) endif " Check if a file type specific tags file is useful? diff --git a/doc/easytags.txt b/doc/easytags.txt index 40e06f4..0ffb508 100644 --- a/doc/easytags.txt +++ b/doc/easytags.txt @@ -139,22 +139,28 @@ home directory ('$HOME' on UNIX, '%USERPROFILE%' on Windows). ------------------------------------------------------------------------------- The *g:easytags_dynamic_files* option -By default |:UpdateTags| only writes to the global tags file. If you use the -following setting to enable project specific tags files: +By default |:UpdateTags| only writes to the global tags file, but it can be +configured to look for project specific tags files by adding the following +lines to your |vimrc| script: > :set tags=./tags; - -You can enable this option so that the project specific tags files are written -instead of the global tags file: -> :let g:easytags_dynamic_files = 1 -When you enable this option, the easytags plug-in will expand the |'tags'| -option and use the first filename (whether the file exists or not). The tags -option is reevaluated each time the plug-in runs, so the results can differ -depending on the location of the current buffer or working directory. - -Note that this option takes precedence over |g:easytags_by_filetype|. +You can change the name of the tags file, the important thing is that it's +relative to your working directory or the buffer (using a leading './'). When +|g:easytags_dynamic_files| is set to 1 the easytags plug-in will write to the +first existing tags file seen by Vim (based on the |'tags'| option). In other +words: If a project specific tags file is found it will be used, otherwise the +plug-in falls back to the global tags file (or a file type specific tags +file). + +If you set |g:easytags_dynamic_files| to 2 the easytags plug-in will +automatically create project specific tags based on the first name in the +'tags' option. This disables the global tags file and file type specific tags +files. + +The |'tags'| option is reevaluated each time the plug-in runs, so which tags +file is selected can differ depending on the buffer and working directory. ------------------------------------------------------------------------------- The *g:easytags_by_filetype* option -- cgit v1.2.3