1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-18 03:50:26 +01:00

Allow the full hierarchy to be displayed in currenttag()

This commit is contained in:
Jan Larres
2012-04-15 23:10:34 +12:00
parent eab0e67d1b
commit bbe5579c89
2 changed files with 53 additions and 27 deletions

View File

@@ -113,6 +113,7 @@ function! s:Init()
if !s:autocommands_done
call s:CreateAutocommands()
doautocmd CursorHold
endif
return 1
@@ -1117,6 +1118,7 @@ function! s:BaseTag._init(name) dict
let self.parent = {}
let self.tline = -1
let self.fileinfo = {}
let self.typeinfo = {}
endfunction
" s:BaseTag.isNormalTag() {{{3
@@ -1258,10 +1260,10 @@ function! s:NormalTag.isNormalTag() dict
return 1
endfunction
" s:NormalTag.str() {{{3
function! s:NormalTag.str() dict
" s:NormalTag.strfmt() {{{3
function! s:NormalTag.strfmt() dict
let fileinfo = self.fileinfo
let typeinfo = s:known_types[fileinfo.ftype]
let typeinfo = self.typeinfo
let suffix = get(self.fields, 'signature', '')
if has_key(self.fields, 'type')
@@ -1274,9 +1276,13 @@ function! s:NormalTag.str() dict
return self._getPrefix() . self.name . suffix . "\n"
endfunction
" s:NormalTag.strshort() {{{3
function! s:NormalTag.strshort(longsig) dict
let str = self.name
" s:NormalTag.str() {{{3
function! s:NormalTag.str(longsig, full) dict
if a:full && self.path != ''
let str = self.path . self.typeinfo.sro . self.name
else
let str = self.name
endif
if has_key(self.fields, 'signature')
if a:longsig
@@ -1302,10 +1308,10 @@ function! s:PseudoTag.isPseudoTag() dict
return 1
endfunction
" s:PseudoTag.str() {{{3
function! s:PseudoTag.str() dict
" s:PseudoTag.strfmt() {{{3
function! s:PseudoTag.strfmt() dict
let fileinfo = self.fileinfo
let typeinfo = s:known_types[fileinfo.ftype]
let typeinfo = self.typeinfo
let suffix = get(self.fields, 'signature', '')
if has_key(typeinfo.kind2scope, self.fields.kind)
@@ -1408,6 +1414,7 @@ function! s:FileInfo.New(fname, ftype) dict
" Dictionary of the folding state of 'kind's, indexed by short name
let newobj.kindfolds = {}
let typeinfo = s:known_types[a:ftype]
let newobj.typeinfo = typeinfo
" copy the default fold state from the type info
for kind in typeinfo.kinds
let newobj.kindfolds[kind.short] =
@@ -1786,7 +1793,7 @@ function! s:ProcessFile(fname, ftype)
let fileinfo = s:FileInfo.New(a:fname, a:ftype)
endif
let typeinfo = s:known_types[a:ftype]
let typeinfo = fileinfo.typeinfo
" Parse the ctags output lines
call s:LogDebugMessage('Parsing ctags output')
@@ -1990,6 +1997,7 @@ function! s:ParseTagline(part1, part2, typeinfo, fileinfo)
endif
let taginfo.fileinfo = a:fileinfo
let taginfo.typeinfo = a:typeinfo
" Needed for folding
try
@@ -2176,6 +2184,7 @@ function! s:CreatePseudoTag(name, parent, scope, typeinfo, fileinfo)
let pseudotag.parent = a:parent
let pseudotag.fileinfo = a:fileinfo
let pseudotag.typeinfo = a:typeinfo
call pseudotag.initFoldState()
@@ -2304,7 +2313,7 @@ function! s:RenderContent(...)
call s:PrintHelp()
let typeinfo = s:known_types[fileinfo.ftype]
let typeinfo = fileinfo.typeinfo
" Print tags
call s:PrintKinds(typeinfo, fileinfo)
@@ -2369,9 +2378,9 @@ function! s:PrintKinds(typeinfo, fileinfo)
" Scoped tags
for tag in curtags
if g:tagbar_compact && first_tag && s:short_help
silent 0put =tag.str()
silent 0put =tag.strfmt()
else
silent put =tag.str()
silent put =tag.strfmt()
endif
" Save the current tagbar line in the tag for easy
@@ -2434,7 +2443,7 @@ function! s:PrintKinds(typeinfo, fileinfo)
if !kindtag.isFolded()
for tag in curtags
let str = tag.str()
let str = tag.strfmt()
silent put =' ' . str
" Save the current tagbar line in the tag for easy
@@ -2458,7 +2467,7 @@ endfunction
" s:PrintTag() {{{2
function! s:PrintTag(tag, depth, fileinfo, typeinfo)
" Print tag indented according to depth
silent put =repeat(' ', a:depth * 2) . a:tag.str()
silent put =repeat(' ', a:depth * 2) . a:tag.strfmt()
" Save the current tagbar line in the tag for easy
" highlighting access
@@ -2838,7 +2847,7 @@ function! s:SetFoldLevel(level, force)
call s:SetFoldLevelRecursive(fileinfo, fileinfo.tags, a:level)
let typeinfo = s:known_types[fileinfo.ftype]
let typeinfo = fileinfo.typeinfo
" Apply foldlevel to 'kind's
if a:level == 0
@@ -3085,10 +3094,10 @@ endfunction
function! s:GetNearbyTag(all)
let fileinfo = s:known_files.getCurrent()
if empty(fileinfo)
return
return {}
endif
let typeinfo = s:known_types[fileinfo.ftype]
let typeinfo = fileinfo.typeinfo
let curline = line('.')
let tag = {}
@@ -3099,8 +3108,9 @@ function! s:GetNearbyTag(all)
" highlighting isn't /that/ important ignore it for now.
for line in range(curline, 1, -1)
if has_key(fileinfo.fline, line)
let tag = fileinfo.fline[line]
if a:all || typeinfo.getKind(tag.fields.kind).stl
let curtag = fileinfo.fline[line]
if a:all || typeinfo.getKind(curtag.fields.kind).stl
let tag = curtag
break
endif
endif
@@ -3263,6 +3273,8 @@ function! s:LogDebugMessage(msg)
endfunction
" Autoload functions {{{1
" Wrappers {{{2
function! tagbar#ToggleWindow()
call s:ToggleWindow()
endfunction
@@ -3296,6 +3308,7 @@ endfunction
function! tagbar#RestoreSession()
call s:RestoreSession()
endfunction
" }}}2
" tagbar#getusertypes() {{{2
function! tagbar#getusertypes()
@@ -3316,6 +3329,7 @@ function! tagbar#getusertypes()
return defdict
endfunction
" tagbar#autoopen() {{{2
" Automatically open Tagbar if one of the open buffers contains a supported
" file
function! tagbar#autoopen(...)
@@ -3340,8 +3354,16 @@ function! tagbar#autoopen(...)
\ 'without finding valid file')
endfunction
" tagbar#currenttag() {{{2
function! tagbar#currenttag(fmt, default, ...)
let longsig = a:0 > 0 ? a:1 : 0
if a:0 > 0
" also test for non-zero value for backwards compatibility
let longsig = a:1 =~# 's' || (type(a:1) == type(0) && a:1 != 0)
let fullpath = a:1 =~# 'f'
else
let longsig = 0
let fullpath = 0
endif
if !s:Init()
return ''
@@ -3350,7 +3372,7 @@ function! tagbar#currenttag(fmt, default, ...)
let tag = s:GetNearbyTag(0)
if !empty(tag)
return printf(a:fmt, tag.strshort(longsig))
return printf(a:fmt, tag.str(longsig, fullpath))
else
return a:default
endif