From ac315a019ea96302d3ac7166d7f5febb34ee38ca Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Thu, 10 Jun 2010 21:41:15 +0200 Subject: Scan files not contained in tags file on 1st :edit --- autoload.vim | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/autoload.vim b/autoload.vim index 8ed840e..21f8bf2 100644 --- a/autoload.vim +++ b/autoload.vim @@ -1,13 +1,15 @@ " Vim script " Maintainer: Peter Odding -" Last Change: June 9, 2010 +" Last Change: June 10, 2010 " URL: http://peterodding.com/code/vim/easytags function! easytags#autoload() " {{{1 try " Update the entries for the current file in the global tags file? let start = xolox#timer#start() - if getftime(expand('%')) > getftime(easytags#get_tagsfile()) + let pathname = expand('%') + let tags_outdated = getftime(pathname) > getftime(easytags#get_tagsfile()) + if tags_outdated || !easytags#file_has_tags(pathname) UpdateTags call xolox#timer#stop(start, "easytags.vim: Automatically updated tags in %s second(s)") endif @@ -48,6 +50,7 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{1 call add(command, '-a') let start_filter = xolox#timer#start() let lines = readfile(tagsfile) + call s:update_tagged_files(lines) let filters = [] if ft_supported && !ft_ignored let filename_pattern = '\s' . xolox#escape#pattern(filename) . '\s' @@ -72,6 +75,7 @@ function! easytags#update_cmd(filter_invalid_tags) " {{{1 if v:shell_error throw "Failed to update tags file! (Ctags output: `" . listing . "')" endif + call easytags#add_tagged_file(filename) endif call xolox#timer#stop(start, "easytags.vim: Updated tags in %s second(s)") return 1 @@ -190,6 +194,48 @@ function! easytags#to_ctags_ft(vim_ft) " {{{1 return index >= 0 ? s:ctags_filetypes[index] : type endfunction +" Miscellaneous script-local functions. {{{1 + +function! s:resolve(pathname) " {{{2 + if g:easytags_resolve_links + return resolve(a:pathname) + else + return a:pathname + endif +endfunction + +function! s:cache_tagged_files() " {{{2 + if !exists('s:tagged_files') + let tagsfile = easytags#get_tagsfile() + call s:update_tagged_files(readfile(tagsfile)) + endif +endfunction + +function! easytags#file_has_tags(pathname) " {{{2 + call s:cache_tagged_files() + return has_key(s:tagged_files, s:resolve(a:pathname)) +endfunction + +function! easytags#add_tagged_file(pathname) " {{{2 + call s:cache_tagged_files() + let pathname = s:resolve(a:pathname) + let s:tagged_files[pathname] = 1 +endfunction + +function! s:update_tagged_files(lines) " {{{2 + " Update the dictionary of + let s:tagged_files = {} + for line in a:lines + if line !~ '^!_TAG_' + let pathname = matchstr(line, '^[^\t]\+\t\zs[^\t]\+') + if pathname != '' + let pathname = s:resolve(pathname) + let s:tagged_files[pathname] = 1 + endif + endif + endfor +endfunction + " Built-in file type & tag kind definitions. {{{1 if !exists('s:tagkinds') -- cgit v1.2.3