comparison autoload/gutentags.vim @ 207:20bfab5b054f

Status-line improvements. - Fix `statusline` function so it does what the documentation says. - Add new function that takes a callback.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 01 Apr 2018 11:52:13 -0700
parents 485a347152fe
children 7371d8750c46
comparison
equal deleted inserted replaced
206:1ffa9d58c2bb 207:20bfab5b054f
594 function! gutentags#start_job(cmd, opts) abort 594 function! gutentags#start_job(cmd, opts) abort
595 return job_start(a:cmd, a:opts) 595 return job_start(a:cmd, a:opts)
596 endfunction 596 endfunction
597 endif 597 endif
598 598
599 " Returns which modules are currently generating something for the
600 " current buffer.
599 function! gutentags#inprogress() 601 function! gutentags#inprogress()
600 echom "gutentags: generations in progress:" 602 " Does this buffer have gutentags enabled?
601 for mod_name in keys(s:maybe_in_progress) 603 if !exists('b:gutentags_files')
602 for mib in keys(s:maybe_in_progress[mod_name]) 604 return []
603 echom mod_name.": ".mib 605 endif
604 endfor 606
605 endfor 607 " Find any module that has a job in progress for any of this buffer's
606 echom "" 608 " tags files.
609 let l:modules_in_progress = []
610 for [module, tags_file] in items(b:gutentags_files)
611 let l:jobidx = gutentags#find_job_index_by_tags_file(module, tags_file)
612 if l:jobidx >= 0
613 call add(l:modules_in_progress, module)
614 endif
615 endfor
616 return l:modules_in_progress
607 endfunction 617 endfunction
608 618
609 " }}} 619 " }}}
610 620
611 " Statusline Functions {{{ 621 " Statusline Functions {{{
616 " Arguments can be passed: 626 " Arguments can be passed:
617 " - args 1 and 2 are the prefix and suffix, respectively, of whatever output, 627 " - args 1 and 2 are the prefix and suffix, respectively, of whatever output,
618 " if any, is going to be produced. 628 " if any, is going to be produced.
619 " (defaults to empty strings) 629 " (defaults to empty strings)
620 " - arg 3 is the text to be shown if tags are currently being generated. 630 " - arg 3 is the text to be shown if tags are currently being generated.
621 " (defaults to 'TAGS') 631 " (defaults to the name(s) of the modules currently generating).
622 632
623 function! gutentags#statusline(...) abort 633 function! gutentags#statusline(...) abort
624 if !exists('b:gutentags_files') 634 let l:modules_in_progress = gutentags#inprogress()
625 " This buffer doesn't have gutentags. 635 if empty(l:modules_in_progress)
626 return '' 636 return ''
627 endif 637 endif
628 638
629 " Find any module that has a job in progress for any of this buffer's 639 let l:prefix = ''
630 " tags files. 640 let l:suffix = ''
631 let l:modules_in_progress = []
632 for [module, tags_file] in items(b:gutentags_files)
633 let l:jobidx = gutentags#find_job_index_by_tags_file(module, tags_file)
634 if l:jobidx >= 0
635 call add(l:modules_in_progress, module)
636 endif
637 endfor
638
639 " Did we find any module? If not, don't print anything.
640 if len(l:modules_in_progress) == 0
641 return ''
642 endif
643
644 " W00t, stuff is happening! Let's print what.
645 let l:gen_msg = 'TAGS'
646 if a:0 > 0 641 if a:0 > 0
647 let l:gen_msg = a:1 642 let l:prefix = a:1
648 endif 643 endif
649 let l:gen_msg .= '['.join(l:modules_in_progress, ',').']' 644 if a:0 > 1
650 return l:gen_msg 645 let l:suffix = a:2
646 endif
647
648 if a:0 > 2
649 let l:genmsg = a:3
650 else
651 let l:genmsg = join(l:modules_in_progress, ',')
652 endif
653
654 return l:prefix.l:genmsg.l:suffix
655 endfunction
656
657 " Same as `gutentags#statusline`, but the only parameter is a `Funcref` or
658 " function name that will get passed the list of modules currently generating
659 " something. This formatter function should return the string to display in
660 " the status line.
661
662 function! gutentags#statusline_cb(fmt_cb, ...) abort
663 let l:modules_in_progress = gutentags#inprogress()
664
665 if (a:0 == 0 || !a:1) && empty(l:modules_in_progress)
666 return ''
667 endif
668
669 return call(a:fmt_cb, [l:modules_in_progress])
651 endfunction 670 endfunction
652 671
653 " }}} 672 " }}}
654 673