From 7ac78715b231977c5dbeb8cd905cb4a58c6ac7ce Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Wed, 19 Jan 2011 17:36:10 +1300 Subject: [PATCH] Consolidate sorting --- plugin/tagbar.vim | 54 ++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 33 deletions(-) diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 038ea26..97a785b 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -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 + " namefileexpattern;"fields " fields: 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)