From 0d1c6442d972aff3f7e077889e9280fa7f07012f Mon Sep 17 00:00:00 2001 From: raven42 Date: Tue, 27 Oct 2020 08:37:33 -0500 Subject: [PATCH] Add option to print the tag linenumber in the tagbar window (#684) * Add option to print the tag linenumber in the tagbar window * Update documentation markup * Change variable name to g:tagbar_show_tag_linenumbers to be more consistent with other variables * Fix documentation --- autoload/tagbar.vim | 9 ++++++++- autoload/tagbar/prototypes/normaltag.vim | 9 ++++++++- autoload/tagbar/prototypes/pseudotag.vim | 9 ++++++++- doc/tagbar.txt | 20 ++++++++++++++++++-- plugin/tagbar.vim | 3 ++- 5 files changed, 44 insertions(+), 6 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 4f7b890..1b7a639 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -2193,7 +2193,14 @@ function! s:HighlightTag(openfolds, ...) abort call winline() let foldpat = '[' . g:tagbar#icon_open . g:tagbar#icon_closed . ' ]' - let pattern = '/^\%' . tagline . 'l\s*' . foldpat . '[-+# ]\?\zs[^( ]\+\ze/' + + " If printing the line number of the tag to the left, and the tag is + " visible (I.E. parent isn't folded) + if g:tagbar_show_tag_linenumbers == 2 && tagline == tag.tline + let pattern = '/^\%' . tagline . 'l\s*' . foldpat . '[-+# ]\[line [0-9]*\] \?\zs[^( ]\+\ze/' + else + let pattern = '/^\%' . tagline . 'l\s*' . foldpat . '[-+# ]\?\zs[^( ]\+\ze/' + endif call tagbar#debug#log("Highlight pattern: '" . pattern . "'") if hlexists('TagbarHighlight') " Safeguard in case syntax highlighting is disabled execute 'match TagbarHighlight ' . pattern diff --git a/autoload/tagbar/prototypes/normaltag.vim b/autoload/tagbar/prototypes/normaltag.vim index d759b2f..232e6ab 100644 --- a/autoload/tagbar/prototypes/normaltag.vim +++ b/autoload/tagbar/prototypes/normaltag.vim @@ -34,8 +34,15 @@ function! s:strfmt() abort dict let scope = s:maybe_map_scope(typeinfo.kind2scope[self.fields.kind]) let suffix .= ' : ' . scope endif + let prefix = self._getPrefix() - return self._getPrefix() . self.name . suffix + if g:tagbar_show_tag_linenumbers == 1 + let suffix .= ' [line ' . self.fields.line . ']' + elseif g:tagbar_show_tag_linenumbers == 2 + let prefix .= '[line ' . self.fields.line . '] ' + endif + + return prefix . self.name . suffix endfunction " s:str() {{{1 diff --git a/autoload/tagbar/prototypes/pseudotag.vim b/autoload/tagbar/prototypes/pseudotag.vim index abd3752..e4ce87b 100644 --- a/autoload/tagbar/prototypes/pseudotag.vim +++ b/autoload/tagbar/prototypes/pseudotag.vim @@ -20,8 +20,15 @@ function! s:strfmt() abort dict if has_key(typeinfo.kind2scope, self.fields.kind) let suffix .= ' : ' . typeinfo.kind2scope[self.fields.kind] endif + let prefix = self._getPrefix() - return self._getPrefix() . self.name . '*' . suffix + if g:tagbar_show_tag_linenumbers == 1 + let suffix .= ' [line ' . self.fields.line . ']' + elseif g:tagbar_show_tag_linenumbers == 2 + let prefix .= '[line ' . self.fields.line . '] ' + endif + + return prefix . self.name . '*' . suffix endfunction " s:add_snr() {{{1 diff --git a/doc/tagbar.txt b/doc/tagbar.txt index 31dc9b0..a096eb6 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -670,7 +670,7 @@ name. Example: > let g:tagbar_show_visibility = 0 - +< *g:tagbar_visibility_symbols* g:tagbar_visibility_symbols Default: { 'public' : '+', 'protected' : '#', 'private' : '-' } @@ -685,7 +685,7 @@ Example: \ 'protected' : '#', \ 'private' : '-' \ } - +< *g:tagbar_show_linenumbers* g:tagbar_show_linenumbers~ Default: 0 @@ -702,7 +702,23 @@ Example: > let g:tagbar_show_linenumbers = 2 < + *g:tagbar_show_tag_linenumbers* +g:tagbar_show_tag_linenumbers~ +Default: 0 +This option allows printing the tag line number next to the tag in the tagbar +window. It can be set to the following values: + 0 - The line number will not be printed + 1 - The line number will be printed to the right of the tag > + Example: function1(int i) [line 42] +< + 2 - The line number will be printed to the left of the tag > + Example: [line 42] function1(int i) +< +Example: +> + let g:tagbar_show_tag_linenumbers = 1 +< *g:tagbar_hide_nonpublic* g:tagbar_hide_nonpublic~ Default: 0 diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 964666a..1f48d3b 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -96,13 +96,14 @@ function! s:setup_options() abort \ ['hide_nonpublic', 0], \ ['height', 10], \ ['indent', 2], - \ ['scopestrs', {}], \ ['left', 0], \ ['position', default_pos], \ ['previewwin_pos', previewwin_pos], + \ ['scopestrs', {}], \ ['show_balloon', 1], \ ['show_visibility', 1], \ ['show_linenumbers', 0], + \ ['show_tag_linenumbers', 0], \ ['singleclick', 0], \ ['sort', 1], \ ['systemenc', &encoding],