1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-17 11:30:28 +01:00

Allow hiding non-public tags, closes #186

This commit is contained in:
Jan Larres
2014-02-05 18:08:04 +13:00
parent 13d4cfcc2c
commit 368d37ed45
2 changed files with 41 additions and 22 deletions

View File

@@ -924,12 +924,13 @@ function! s:MapKeys() abort
\ <LeftRelease><C-o>:call <SID>CheckMouseClick()<CR>
let maps = [
\ ['jump', 'JumpToTag(0)'],
\ ['preview', 'JumpToTag(1)'],
\ ['previewwin', 'ShowInPreviewWin()'],
\ ['nexttag', 'GotoNextToplevelTag(1)'],
\ ['prevtag', 'GotoNextToplevelTag(-1)'],
\ ['showproto', 'ShowPrototype(0)'],
\ ['jump', 'JumpToTag(0)'],
\ ['preview', 'JumpToTag(1)'],
\ ['previewwin', 'ShowInPreviewWin()'],
\ ['nexttag', 'GotoNextToplevelTag(1)'],
\ ['prevtag', 'GotoNextToplevelTag(-1)'],
\ ['showproto', 'ShowPrototype(0)'],
\ ['hidenonpublic', 'ToggleHideNonPublicTags()'],
\
\ ['openfold', 'OpenFold()'],
\ ['closefold', 'CloseFold()'],
@@ -2728,15 +2729,21 @@ endfunction
" s:PrintTag() {{{2
function! s:PrintTag(tag, depth, is_first, fileinfo, typeinfo) abort
" Print tag indented according to depth
if a:is_first && g:tagbar_compact && s:short_help
silent 0put =repeat(' ', a:depth * g:tagbar_indent) . a:tag.strfmt()
else
silent put =repeat(' ', a:depth * g:tagbar_indent) . a:tag.strfmt()
if g:tagbar_hide_nonpublic &&
\ get(a:tag.fields, 'access', 'public') !=# 'public'
let a:tag.tline = -1
return
endif
" Save the current tagbar line in the tag for easy
" highlighting access
" Print tag indented according to depth
let tagstr = repeat(' ', a:depth * g:tagbar_indent) . a:tag.strfmt()
if a:is_first && g:tagbar_compact && s:short_help
silent 0put =tagstr
else
silent put =tagstr
endif
" Save the current tagbar line in the tag for easy highlighting access
let curline = line('.')
let a:tag.tline = curline
let a:fileinfo.tline[curline] = a:tag
@@ -2744,8 +2751,12 @@ function! s:PrintTag(tag, depth, is_first, fileinfo, typeinfo) abort
" Recursively print children
if a:tag.isFoldable() && !a:tag.isFolded()
for ckind in a:typeinfo.kinds
let childtags = filter(copy(a:tag.children),
\ 'v:val.fields.kind ==# ckind.short')
let childfilter = 'v:val.fields.kind ==# ckind.short'
if g:tagbar_hide_nonpublic
let childfilter .=
\ ' && get(v:val.fields, "access", "public") ==# "public"'
endif
let childtags = filter(copy(a:tag.children), childfilter)
if len(childtags) > 0
" Print 'kind' header of following children, but only if they
" are not scope-defining tags (since those already have an
@@ -2887,7 +2898,7 @@ function! s:HighlightTag(openfolds, ...) abort
let tagline = tag.getClosedParentTline()
" Parent tag line number is invalid, better don't do anything
if tagline == 0
if tagline <= 0
call s:goto_win(prevwinnr)
redraw
return
@@ -3639,6 +3650,12 @@ function! s:GotoFileWindow(fileinfo, ...) abort
call s:goto_win('p', noauto)
endfunction
" s:ToggleHideNonPublicTags() {{{2
function! s:ToggleHideNonPublicTags() abort
let g:tagbar_hide_nonpublic = !g:tagbar_hide_nonpublic
call s:RenderKeepView()
endfunction
" s:IsValidFile() {{{2
function! s:IsValidFile(fname, ftype) abort
call s:LogDebugMessage('Checking if file is valid [' . a:fname . ']')

View File

@@ -56,6 +56,7 @@ let s:options = [
\ ['compact', 0],
\ ['expand', 0],
\ ['foldlevel', 99],
\ ['hide_nonpublic', 0],
\ ['indent', 2],
\ ['left', 0],
\ ['previewwin_pos', 'topleft'],
@@ -83,12 +84,13 @@ if !exists('g:tagbar_iconchars')
endif
let s:keymaps = [
\ ['jump', '<CR>'],
\ ['preview', 'p'],
\ ['previewwin', 'P'],
\ ['nexttag', '<C-N>'],
\ ['prevtag', '<C-P>'],
\ ['showproto', '<Space>'],
\ ['jump', '<CR>'],
\ ['preview', 'p'],
\ ['previewwin', 'P'],
\ ['nexttag', '<C-N>'],
\ ['prevtag', '<C-P>'],
\ ['showproto', '<Space>'],
\ ['hidenonpublic', 'h'],
\
\ ['openfold', ['+', '<kPlus>', 'zo']],
\ ['closefold', ['-', '<kMinus>', 'zc']],