diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index d210b8c..d948e6b 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1182,29 +1182,34 @@ function! s:ProcessFile(fname, ftype) abort call tagbar#debug#log('typeinfo for file to process: ' . string(typeinfo)) - " Use a temporary files for ctags processing instead of the original one. - " This allows using Tagbar for files accessed with netrw, and also doesn't - " slow down Tagbar for files that sit on slow network drives. - let tempfile = tempname() - let ext = fnamemodify(fileinfo.fpath, ':e') - if ext !=# '' - let tempfile .= '.' . ext - endif + if g:tagbar_use_cache + " Use a temporary files for ctags processing instead of the original one. + " This allows using Tagbar for files accessed with netrw, and also doesn't + " slow down Tagbar for files that sit on slow network drives. + let tempfile = tempname() + let ext = fnamemodify(fileinfo.fpath, ':e') + if ext !=# '' + let tempfile .= '.' . ext + endif - call tagbar#debug#log('Caching file into: ' . tempfile) - let templines = getbufline(fileinfo.bufnr, 1, '$') - let res = writefile(templines, tempfile) + call tagbar#debug#log('Caching file into: ' . tempfile) + let templines = getbufline(fileinfo.bufnr, 1, '$') + let res = writefile(templines, tempfile) - if res != 0 - call tagbar#debug#log('Could not create copy '.tempfile) - return - endif - let fileinfo.mtime = getftime(tempfile) + if res != 0 + call tagbar#debug#log('Could not create copy '.tempfile) + return + endif + let fileinfo.mtime = getftime(tempfile) - let ctags_output = s:ExecuteCtagsOnFile(tempfile, a:fname, typeinfo) + let ctags_output = s:ExecuteCtagsOnFile(tempfile, a:fname, typeinfo) - if !tagbar#debug#enabled() - call delete(tempfile) + if !tagbar#debug#enabled() + call delete(tempfile) + endif + else + call tagbar#debug#log('File caching disabled') + let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:fname, typeinfo) endif if ctags_output == -1 diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 93bb384..29d06c9 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -784,6 +784,24 @@ about the tag is echoed out. Set this option to disable that behavior. Example: > let g:tagbar_silent = 1 + *g:tagbar_use_cache* +g:tagbar_use_cache~ +Default: 1 + +By default the file contents are passed to ctags by writing them to +a temporary file and invoking ctags on that file. This greatly speeds up tag +generation in the event of slow file systems such as network shares and +enables tagbar to run even on netrw virtual files that ctags would otherwise +not be able to find at all. However it does incure the cost of an extra write +operation. Additionally not all sysems are able to let programs share access +to temporary file space (for example Snap packages cannot read from the host +system's temp file space). This setting can disable the cache mechanism +entriely forcing the tags to be generated from the existing copy of the file +on disk rather than the current buffer written to a temporary file. + +Example: +> + let g:tagbar_use_cache = 0 < ------------------------------------------------------------------------------ diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index a1e13e7..bd84d5f 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -77,6 +77,7 @@ function! s:setup_options() abort \ ['width', 40], \ ['zoomwidth', 1], \ ['silent', 0], + \ ['use_cache', 1], \ ] for [opt, val] in options