Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 0 additions & 167 deletions ftplugin/vo_base.vim
Original file line number Diff line number Diff line change
Expand Up @@ -98,168 +98,6 @@ setlocal iskeyword=@,39,45,48-57,_,129-255
if !exists("loaded_vimoutliner_functions")
let loaded_vimoutliner_functions=1

" Sorting {{{2
" IsParent(line) {{{3
" Return 1 if this line is a parent
function! IsParent(line)
return (Ind(a:line)+1) == Ind(a:line+1)
endfunction
"}}}3
" FindParent(line) {{{3
" Return line if parent, parent line if not
function! FindParent(line)
if IsParent(a:line)
return a:line
else
let l:parentindent = Ind(a:line)-1
let l:searchline = a:line
while (Ind(l:searchline) != l:parentindent) && (l:searchline > 0)
let l:searchline = l:searchline-1
endwhile
return l:searchline
endif
endfunction
"}}}3
" FindLastChild(line) {{{3
" Return the line number of the last decendent of parent line
function! FindLastChild(line)
let l:parentindent = Ind(a:line)
let l:searchline = a:line+1
while Ind(l:searchline) > l:parentindent
let l:searchline = l:searchline+1
endwhile
return l:searchline-1
endfunction
"}}}3
" MoveDown() {{{3
" Move a heading down by one
" Used for sorts and reordering of headings
function! MoveDown()
call cursor(line("."),0)
del x
put x
endfunction
"}}}3
" DelHead() {{{3
" Delete a heading
" Used for sorts and reordering of headings
function! DelHead(line)
let l:fstart = foldclosed(a:line)
if l:fstart == -1
let l:execstr = a:line . "del x"
else
let l:fend = foldclosedend(a:line)
let l:execstr = l:fstart . "," . l:fend . "del x"
endif
exec l:execstr
endfunction
" PutHead() {{{3
" Put a heading
" Used for sorts and reordering of headings
function! PutHead(line)
let l:fstart = foldclosed(a:line)
if l:fstart == -1
let l:execstr = a:line . "put x"
exec l:execstr
else
let l:fend = foldclosedend(a:line)
let l:execstr = l:fend . "put x"
exec l:execstr
endif
endfunction
"}}}3
" NextHead(line) {{{3
" Return line of next heanding
" Used for sorts and reordering of headings
function! NextHead(line)
let l:fend = foldclosedend(a:line)
if l:fend == -1
return a:line+1
else
return l:fend+1
endif
endfunction
"}}}3
" CompHead(line) {{{3
" Compare this heading and the next
" Return 1: next is greater, 0 next is same, -1 next is less
function! CompHead(line)
let l:thisline=getline(a:line)
let l:nextline=getline(NextHead(a:line))
if l:thisline <# l:nextline
return 1
elseif l:thisline ># l:nextline
return -1
else
return 0
endif
endfunction
"}}}3
" Sort1Line(line) {{{3
" Compare this heading and the next and swap if out of order
" Dir is 0 for forward, 1 for reverse
" Return a 1 if a change was made
function! Sort1Line(line,dir)
if (CompHead(a:line) == -1) && (a:dir == 0)
call DelHead(a:line)
call PutHead(a:line)
return 1
elseif (CompHead(a:line) == 1) && (a:dir == 1)
call DelHead(a:line)
call PutHead(a:line)
return 1
else
return 0
endif
endfunction
"}}}3
" Sort1Pass(start,end,dir) {{{3
" Compare this heading and the next and swap if out of order
" Dir is 0 for forward, 1 for reverse
" Return a 0 if no change was made, other wise return the change count
function! Sort1Pass(fstart,fend,dir)
let l:i = a:fstart
let l:changed = 0
while l:i < a:fend
let l:changed = l:changed + Sort1Line(l:i,a:dir)
let l:i = NextHead(l:i)
endwhile
return l:changed
endfunction
"}}}3
" Sort(start,end,dir) {{{3
" Sort this range of headings
" dir: 0 = ascending, 1 = decending
function! SortRange(fstart,fend,dir)
let l:changed = 1
while l:changed != 0
let l:changed = Sort1Pass(a:fstart,a:fend,a:dir)
endwhile
endfunction
"}}}3
" SortChildren(dir) {{{3
" Sort the children of a parent
" dir: 0 = ascending, 1 = decending
function! SortChildren(dir)
let l:oldcursor = line(".")
let l:fstart = FindParent(line("."))
let l:fend = FindLastChild(l:fstart)
let l:fstart = l:fstart
if l:fend <= l:fstart + 1
return
endif
call append(line("$"),"Temporary last line for sorting")
mkview
let l:execstr = "set foldlevel=" . foldlevel(l:fstart)
exec l:execstr
call SortRange(l:fstart + 1,l:fend,a:dir)
call cursor(line("$"),0)
del x
loadview
call cursor(l:oldcursor,0)
endfunction
"}}}3
"}}}2
" MakeChars() {{{2
" Make a string of characters
" Used for strings of repeated characters
Expand Down Expand Up @@ -559,11 +397,6 @@ nmap <buffer> <localleader>t $:call InsertSpaceTime()<cr>
imap <buffer> <localleader>t ~<esc>x:call InsertTime(0)<cr>a
nmap <buffer> <localleader>T ^:call InsertTime(1)<cr>a <esc>

" sort a list naturally
map <buffer> <localleader>s :call SortChildren(0)<cr>
" sort a list, but you supply the options
map <buffer> <localleader>S :call SortChildren(1)<cr>

" invoke the file explorer
map <buffer> <localleader>f :e .<cr>
imap <buffer> <localleader>f :e .<cr>
Expand Down
44 changes: 44 additions & 0 deletions vimoutliner/plugin/vo_sort.otl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
documentation
what ?
the goal of this plugin is to let you have s simple way to sort the outlines at the same level
within one keystropke. Children of these siblings are moved with their aprents and not alterned in any ways.
This pkugin is also interesting as a tempate plugin for people who would want to implement custom sort functions
with respect of the outlines.
how ?
you place on one of the siblings you want sorted, and hit ',,s' or ',,S' and there you are, they sorted
keys
,,s sort alphanumerically (ascending)
,,S sort alphanumerically (descending)
checkboxes
at the moment of this writing, checkboxes are taken as literal text when sorting,
I need to change that.
sort status
[X] sorting ascending
[X] sorting descending
[X] jostein patch
[_] sorting checkbox
[_] sorting ascending
[_] X is <# _
[_] sorting descending
[_] as a plugin
[X] in my vo_base
[_] with official one
test
ruth
b
plaf
a
plop
plip
c
plop
e
plouf
ruth2
[X] b
[X] plaf
[_] a
[_] plop
[_] plip
[_] c
[_] plouf
Loading