# HG changeset patch # User Ludovic Chabant # Date 1522608733 25200 # Node ID 20bfab5b054f782b558212503f9cbe91f51b5f72 # Parent 1ffa9d58c2bb4d26f8e093abea016d4e3403c5ea Status-line improvements. - Fix `statusline` function so it does what the documentation says. - Add new function that takes a callback. diff -r 1ffa9d58c2bb -r 20bfab5b054f autoload/gutentags.vim --- a/autoload/gutentags.vim Sun Apr 01 09:33:23 2018 -0700 +++ b/autoload/gutentags.vim Sun Apr 01 11:52:13 2018 -0700 @@ -596,14 +596,24 @@ endfunction endif +" Returns which modules are currently generating something for the +" current buffer. function! gutentags#inprogress() - echom "gutentags: generations in progress:" - for mod_name in keys(s:maybe_in_progress) - for mib in keys(s:maybe_in_progress[mod_name]) - echom mod_name.": ".mib - endfor - endfor - echom "" + " Does this buffer have gutentags enabled? + if !exists('b:gutentags_files') + return [] + endif + + " Find any module that has a job in progress for any of this buffer's + " tags files. + let l:modules_in_progress = [] + for [module, tags_file] in items(b:gutentags_files) + let l:jobidx = gutentags#find_job_index_by_tags_file(module, tags_file) + if l:jobidx >= 0 + call add(l:modules_in_progress, module) + endif + endfor + return l:modules_in_progress endfunction " }}} @@ -618,36 +628,45 @@ " if any, is going to be produced. " (defaults to empty strings) " - arg 3 is the text to be shown if tags are currently being generated. -" (defaults to 'TAGS') +" (defaults to the name(s) of the modules currently generating). function! gutentags#statusline(...) abort - if !exists('b:gutentags_files') - " This buffer doesn't have gutentags. - return '' + let l:modules_in_progress = gutentags#inprogress() + if empty(l:modules_in_progress) + return '' + endif + + let l:prefix = '' + let l:suffix = '' + if a:0 > 0 + let l:prefix = a:1 + endif + if a:0 > 1 + let l:suffix = a:2 endif - " Find any module that has a job in progress for any of this buffer's - " tags files. - let l:modules_in_progress = [] - for [module, tags_file] in items(b:gutentags_files) - let l:jobidx = gutentags#find_job_index_by_tags_file(module, tags_file) - if l:jobidx >= 0 - call add(l:modules_in_progress, module) - endif - endfor - - " Did we find any module? If not, don't print anything. - if len(l:modules_in_progress) == 0 - return '' + if a:0 > 2 + let l:genmsg = a:3 + else + let l:genmsg = join(l:modules_in_progress, ',') endif - " W00t, stuff is happening! Let's print what. - let l:gen_msg = 'TAGS' - if a:0 > 0 - let l:gen_msg = a:1 + return l:prefix.l:genmsg.l:suffix +endfunction + +" Same as `gutentags#statusline`, but the only parameter is a `Funcref` or +" function name that will get passed the list of modules currently generating +" something. This formatter function should return the string to display in +" the status line. + +function! gutentags#statusline_cb(fmt_cb, ...) abort + let l:modules_in_progress = gutentags#inprogress() + + if (a:0 == 0 || !a:1) && empty(l:modules_in_progress) + return '' endif - let l:gen_msg .= '['.join(l:modules_in_progress, ',').']' - return l:gen_msg + + return call(a:fmt_cb, [l:modules_in_progress]) endfunction " }}} diff -r 1ffa9d58c2bb -r 20bfab5b054f doc/gutentags.txt --- a/doc/gutentags.txt Sun Apr 01 09:33:23 2018 -0700 +++ b/doc/gutentags.txt Sun Apr 01 11:52:13 2018 -0700 @@ -194,10 +194,25 @@ have a heads up if some of the tags aren't recognized yet. *gutentags#statusline()* -You can display and indicator of tag generation progress in your |status-line| +You can display an indicator of tag generation progress in your |status-line| with the following function: > :set statusline+=%{gutentags#statusline()} +The function will, by default, print a list of modules in the status line. So +if the `ctags` module (see |g:gutentags_modules|) is currently generating +a tags file, you will see "ctags" printed in the status line. If nothing is +happening, nothing will be printed in the status line. + +You can pass some parameters to customize this: + +1. A prefix string (defaults to `""`). +2. A suffix string (defaults to `""`). +3. The text to print (defaults to the names of modules currently generating + something). + +So using `gutentags#statusline('[', ']')` would print `"[ctags]"` instead of +`"ctags"`. + Because Gutentags runs the tag generation in the background, the statusline indicator might stay there even after the background process has ended. It would only go away when Vim decides to refresh the statusline. You can force @@ -211,6 +226,31 @@ autocmd User GutentagsUpdated call lightline#update() augroup END + *gutentags#statusline_cb* +As an alternative to the previous function, `gutentags#statusline_cb` takes +a single parameter which should be a |Funcref| or a function name. This +function should take a list of active module names, and return a string. This +lets you completely control what the status line will print. + +For instance: + function! s:get_gutentags_status(mods) abort + let l:msg = '' + if index(a:mods, 'ctags') > 0 + let l:msg .= '♨' + endif + if index(a:mods, 'cscope') > 0 + let l:msg .= '♺' + endif + return l:msg + endfunction + + :set statusline+=%{gutentags#statusline_cb( + \function('get_gutentags_status'))} + +By default, the callback function doesn't get called if no tags generation is +currently happening. You can pass `1` as a second argument so that the +callback function is always called. + ============================================================================= 4. Global Settings *gutentags-settings*