Consolidate sorting

This commit is contained in:
Jan Larres 2011-01-19 17:36:10 +13:00
parent 3fab2ae0dd
commit 7ac78715b2

View File

@ -324,10 +324,6 @@ function! s:ProcessFile(fname, ftype)
endif
endfor
" Script-local variable needed since compare functions can't
" take extra arguments
let s:compare_typeinfo = typeinfo
if has_key(typeinfo, 'scopes') && !empty(typeinfo.scopes)
" Extract top-level scopes, removing them from the tag list
let scopedtags = filter(copy(fileinfo.tags),
@ -346,15 +342,31 @@ function! s:ProcessFile(fname, ftype)
call extend(fileinfo.tags, scopedtags)
endif
if g:tagbar_sort
call sort(fileinfo.tags, 's:CompareByKind')
else
call sort(fileinfo.tags, 's:CompareByLine')
endif
" Script-local variable needed since compare functions can't
" take extra arguments
let s:compare_typeinfo = typeinfo
for tag in fileinfo.tags
if g:tagbar_sort
call s:SortTags(fileinfo.tags, 's:CompareByKind')
else
call s:SortTags(fileinfo.tags, 's:CompareByLine')
endif
endfor
let s:known_files[a:fname] = fileinfo
endfunction
function! s:SortTags(tags, comparemethod)
call sort(a:tags, a:comparemethod)
for tag in a:tags
if has_key(tag, 'children')
call s:SortTags(tag.children, a:comparemethod)
endif
endfor
endfunction
" name<TAB>file<TAB>expattern;"fields
" fields: <TAB>name:value
" fields that are always present: kind, line
@ -384,14 +396,6 @@ function! s:AddPseudoTags(tags, typeinfo)
for scope in a:typeinfo.scopes
call s:AddPseudoChildren(a:tags, pseudotags, '', scope, 1, a:typeinfo)
for tag in pseudotags
if g:tagbar_sort
call sort(tag.children, 's:CompareByKind')
else
call sort(tag.children, 's:CompareByLine')
endif
endfor
endfor
call extend(a:tags, pseudotags)
@ -453,12 +457,6 @@ function! s:AddPseudoChildren(tags, pseudotags, pcomplpath,
continue
endif
if g:tagbar_sort
call sort(tag.children, 's:CompareByKind')
else
call sort(tag.children, 's:CompareByLine')
endif
if empty(a:pcomplpath)
let complpath = tag.name
else
@ -606,16 +604,6 @@ function! s:GetChildTags(tags, pscopetype, pscope, pname, typeinfo)
let childtags = filter(copy(a:tags), is_child)
call filter(a:tags, '!(' . is_child . ')')
" Script-local variable needed since compare functions can't
" take extra arguments
let s:compare_typeinfo = a:typeinfo
if g:tagbar_sort
call sort(childtags, 's:CompareByKind')
else
call sort(childtags, 's:CompareByLine')
endif
" Recursively add children
for tag in childtags
if has_key(a:typeinfo.kind2scope, tag.fields.kind)