FIX hierarchical sort stability bug

This commit is contained in:
David Beniamine
2015-07-06 14:55:02 +02:00
parent 68a32427ab
commit 53ad73ebda

View File

@@ -32,7 +32,7 @@ if !hasmapto("<localleader>sp",'n')
noremap <localleader>sp :call Todo_txt_HierarchicalSort('+', '',1)<CR> noremap <localleader>sp :call Todo_txt_HierarchicalSort('+', '',1)<CR>
endif endif
if !hasmapto("<localleader>spc",'n') if !hasmapto("<localleader>spc",'n')
noremap <localleader>spc :call Todo_txt_HierarchicalSort('+', '@',0)<CR> noremap <localleader>spc :call Todo_txt_HierarchicalSort('+', '@',1)<CR>
endif endif
" This is a Hierarchical sort designed for todo.txt todo lists, however it " This is a Hierarchical sort designed for todo.txt todo lists, however it
@@ -63,42 +63,39 @@ function! Todo_txt_HierarchicalSort(symbol, symbolsub, dolastsort)
let l:linecount=str2nr(split(v:statusmsg)[7]) let l:linecount=str2nr(split(v:statusmsg)[7])
" Get all the groups names " Get all the groups names
let l:groups=GetGroups(a:symbol,0,l:linecount) let l:groups=GetGroups(a:symbol,1,l:linecount)
" Sort by groups " Sort by groups
execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/' execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
for l:g in l:groups for l:g in l:groups
let l:pat=a:symbol.l:g.'.*$'
normal gg
" Find the beginning of the group " Find the beginning of the group
execute '/'.a:symbol.l:g.'.*$' let l:groupBegin=search(l:pat,'c')
let l:groupBegin=getpos(".")[1]
" Find the end of the group " Find the end of the group
silent normal N let l:groupEnd=search(l:pat,'b')
let l:groupEnd=getpos(".")[1]
" I'm too lazy to sort one groups of one line " I'm too lazy to sort groups of one line
if(l:groupEnd==l:groupBegin) if(l:groupEnd==l:groupBegin)
continue continue
endif endif
if( a:symbolsub!='') if a:dolastsort
" Sort by subgroups if( a:symbolsub!='')
let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd) " Sort by subgroups
" Go before the first line of the group let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd)
" Sort the group using the second symbol " Go before the first line of the group
for l:sg in l:subgroups " Sort the group using the second symbol
" Find the beginning of the subgroup for l:sg in l:subgroups
execute '/'.a:symbol.l:g.'.*'.a:symbolsub.l:sg.'.*$\|'.a:symbolsub.l:sg.'.*'.a:symbol.l:g.'.*$' normal gg
let l:subgroupBegin=getpos(".")[1] let l:pat=a:symbol.l:g.'.*'.a:symbolsub.l:sg.'.*$\|'.a:symbolsub.l:sg.'.*'.a:symbol.l:g.'.*$'
" Find the end of the subgroup " Find the beginning of the subgroup
silent normal N let l:subgroupBegin=search(l:pat,'c')
let l:subgroupEnd=getpos(".")[1] " Find the end of the subgroup
" Sort by priority let l:subgroupEnd=search(l:pat,'b')
if a:dolastsort " Sort by priority
execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal
endif endfor
endfor else
else " Sort by priority
" Sort by priority
if a:dolastsort
execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
endif endif
endif endif