Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace tag files only after an updated version has been created. #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ The Vim-Tags available variables are:

This command is used for main Ctags generation.

let g:vim_tags_project_tags_command = "{CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"
let g:vim_tags_project_tags_command = "({CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null) \&\& ({PLACE_TAGS})"


* `vim_tags_gems_tags_command`
Expand Down
2 changes: 1 addition & 1 deletion doc/vim-tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Default: "{CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"

This command is used for main Ctags generation. >

let g:vim_tags_project_tags_command = "{CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"
let g:vim_tags_project_tags_command = "({CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null) \&\& ({PLACE_TAGS})"
<

*vim_tags_gems_tags_command*
Expand Down
23 changes: 16 additions & 7 deletions plugin/tags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ endif

" Main tags
if !exists('g:vim_tags_project_tags_command')
let g:vim_tags_project_tags_command = "{CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null"
let g:vim_tags_project_tags_command = "({CTAGS} -R {OPTIONS} {DIRECTORY} 2>/dev/null) \&\& ({PLACE_TAGS})"
endif

" Gemfile tags
Expand Down Expand Up @@ -161,9 +161,11 @@ function! s:generate_options()
endif

" Add main tags file to tags option
call s:add_tags_location(s:tags_directory . '/' . g:vim_tags_main_file)
let main_file = s:tags_directory . '/' . g:vim_tags_main_file

call add(options, '-f ' . s:tags_directory . '/' . g:vim_tags_main_file)
call s:add_tags_location(main_file)

call add(options, '-f ' . main_file . '.tmp')

for f in split(globpath(s:tags_directory, '*' . g:vim_tags_extension, 1), '\n')
let dir_name = f[strlen(s:tags_directory) + 1:-6]
Expand All @@ -176,7 +178,7 @@ function! s:generate_options()
call s:add_tags_location(f)
endfor

return join(options, ' ')
return [ join(options, ' '), main_file ]
endfunction

function! s:find_project_root()
Expand Down Expand Up @@ -231,7 +233,9 @@ fun! s:generate_tags(bang, redraw)
let project_root = s:find_project_root()
silent! exe "cd " . project_root

let options = s:generate_options()
let options_and_file = s:generate_options()
let options = options_and_file[0]
let main_file = options_and_file[1]

"Remove existing tags
if a:bang
Expand Down Expand Up @@ -261,19 +265,24 @@ fun! s:generate_tags(bang, redraw)

if (getftime(file_name) < dir_time) || (getfsize(file_name) == 0)
let custom_tags_command = substitute(g:vim_tags_project_tags_command, '{DIRECTORY}', shellescape(dir_name), '')
let custom_tags_command = substitute(custom_tags_command, '{OPTIONS}', '--tag-relative -f ' . shellescape(file_name), '')
let esc_f = shellescape(file_name)
let custom_tags_command = substitute(custom_tags_command, '{OPTIONS}', '--tag-relative -f ' . esc_f . '.tmp', '')
let custom_tags_command = substitute(custom_tags_command, '{PLACE_TAGS}', 'mv ' . esc_f . '.tmp ' . esc_f, '')
call s:execute_async_command(custom_tags_command)
endif
endfor

"Project tags file
let project_tags_command = substitute(g:vim_tags_project_tags_command, '{OPTIONS}', options, '')
let project_tags_command = substitute(project_tags_command, '{DIRECTORY}', '.', '')
let project_tags_command = substitute(project_tags_command, '{PLACE_TAGS}', 'mv ' . main_file . '.tmp ' . main_file, '')
call s:execute_async_command(project_tags_command)

" Append files from negated patterns
if !empty(s:files_to_include)
let append_command_template = substitute(g:vim_tags_project_tags_command, '{OPTIONS}', '--tag-relative -a -f ' . s:tags_directory . '/' . g:vim_tags_main_file, '')
let main_file = s:tags_directory . '/' . g:vim_tags_main_file
let append_command_template = substitute(g:vim_tags_project_tags_command, '{OPTIONS}', '--tag-relative -a -f ' . main_file, '')
let append_command_template = substitute(g:vim_tags_project_tags_command, '{PLACE_TAGS}', 'mv ' . main_file . '.tmp ' . main_file, '')
for file_to_include in s:files_to_include
call s:execute_async_command(substitute(append_command_template, '{DIRECTORY}', file_to_include, ''))
endfor
Expand Down