From be67ff7ae7b7be086966aa72fb32f3ec47e3a9fa Mon Sep 17 00:00:00 2001 From: raven42 Date: Mon, 14 Sep 2020 15:15:39 -0500 Subject: [PATCH] Add option to not trigger update on large files --- autoload/tagbar.vim | 24 ++++++++++++++++++++++++ doc/tagbar.txt | 19 +++++++++++++++++++ plugin/tagbar.vim | 1 + 3 files changed, 44 insertions(+) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index ca0fdd0..26c6a9d 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1158,6 +1158,20 @@ function! s:ProcessFile(fname, ftype) abort return endif + " If the file size limit it set, then check the linecount to see if + " this file should be ignored or not. + if g:tagbar_file_size_limit > 0 + let linecount = line('$') + if linecount > g:tagbar_file_size_limit && !exists('b:tagbar_force_update') + call tagbar#debug#log('[ProcessFile] File size too large (' . linecount . ' lines) - limit set to ' . g:tagbar_file_size_limit) + if !exists('b:tagbar_file_exceeds_limit') + echom 'File size too large (' . linecount . ' lines) - Not processing file (see help for g:tagbar_file_size_limit).' + let b:tagbar_file_exceeds_limit = 1 + endif + return + endif + endif + let typeinfo = s:known_types[a:ftype] " If the file has only been updated preserve the fold states, otherwise @@ -3578,6 +3592,16 @@ function! tagbar#Update() abort call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 0) endfunction +" tagbar#ForceUpdate() {{{2 +function! tagbar#ForceUpdate() abort + if !exists('b:tagbar_force_update') + let b:tagbar_force_update = 1 + call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 1) + unlet b:tagbar_force_update + unlet b:tagbar_file_exceeds_limit + endif +endfunction + " tagbar#toggle_pause() {{{2 function! tagbar#toggle_pause() abort let s:paused = !s:paused diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 757c9f3..b4bc11b 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -337,6 +337,10 @@ FUNCTIONS *tagbar-functions* return tag . ' --- ' . lines . ' lines' endfunction < +*tagbar#ForceUpdate()* + Forcefully update a file even if it exceeds the |g:tagbar_file_size_limit| + value. This also clears the internal flags to the file will be re-examined + again. ------------------------------------------------------------------------------ KEY MAPPINGS *tagbar-keys* @@ -882,6 +886,21 @@ Example: > let g:tagbar_use_cache = 0 < + *g:tagbar_file_size_limit* +g:tagbar_file_size_limit~ +Default: 0 + +By default, all files are processed by tagbar. Setting this value to non-zero +will disable processing for any file with a line count greater than +|g:tagbar_file_size_limit|. A message will be displayed once for a given buffer +if the limit is exceeded. The file can be forcefully updated with the +|tagbar#ForceUpdate()| function. If the value is set to 0, then the file will +always be processed. + +Example: +> + let g:tagbar_file_size_limit = 10000 +< ------------------------------------------------------------------------------ HIGHLIGHT COLOURS *tagbar-highlight* diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 7fb69a3..40b66db 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -91,6 +91,7 @@ function! s:setup_options() abort \ ['case_insensitive', 0], \ ['compact', 0], \ ['expand', 0], + \ ['file_size_limit', 0], \ ['foldlevel', 99], \ ['hide_nonpublic', 0], \ ['height', 10],