diff --git a/README.markdown b/README.markdown index f330803..2c9ecf5 100644 --- a/README.markdown +++ b/README.markdown @@ -1,9 +1,24 @@ +# Readme + +## What is this plugin ? + +This plugin is a fork of freitass todo.txt (see section 1.3) vim plugin adding +a nice two level sorting function designed for todo.txt files (see section +1.4). + +## Install + ### Quick install - git clone git://github.com/freitass/todo.txt-vim.git + git clone git://github.com/dbeniamine/todo.txt-vim.git cd todo.txt-vim cp -R * ~/.vim +### Pathogen install + + git clone git://github.com/dbeniamine/todo.txt-vim.git ~/.vim/bundle/todo.txt-vim + +## Features included in Freitass version This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. It also defines a few mappings, to help with edition of these files: @@ -22,3 +37,21 @@ mappings, to help with edition of these files: If you want the help installed run ":helptags ~/.vim/doc" inside vim after having copied the files. Then you will be able to get the commands help with: :h todo.txt + +## New features + +This fork provides a two level sorting function designed to do by project or +by context sorts, with a priority sort. + +`-sc` : Sort the file by context (reverse) then by priority +`-sp` : Sort the file by project (reverse) then by priority + +The user can give argument for the two call to vim sort function by changing +the following variables in its vimrc: +see :help sort + let g:Todo_txt_first_level_sort_mode="! i" + let g:Todo_txt_second_level_sort_mode="i" + +## Todo + +Complete documentation diff --git a/doc/todo.txt b/doc/todo.txt index 961bc4a..614531d 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -3,7 +3,11 @@ ============================================================================== COMMANDS *todo-commands* -`-s` : Sort the file +`-s` : Sort the file by priority + +`-sp` : Sort the file by project then by priority + +`-sc` : Sort the file by context then by priority `-d` : Insert the current date @@ -16,3 +20,19 @@ COMMANDS *todo-commands* `-D` : Remove completed tasks is \ by default, so -s means you type \s + +=============================================================================== +CONFIGURATION *todo-configuration* + +The user can give argument for the two calls to vim sort function by changing +the following variables: + +g:Todo_txt_first_level_sort_mode +g:Todo_txt_second_level_sort_mode + +Defaults values are: + +g:Todo_txt_first_level_sort_mode="i" +g:Todo_txt_second_level_sort_mode="i" + +For more information on the available flags see help :sort diff --git a/plugin/todo-txt.vim b/plugin/todo-txt.vim new file mode 100644 index 0000000..b5fd74e --- /dev/null +++ b/plugin/todo-txt.vim @@ -0,0 +1,78 @@ +" File: todo.txt.vim +" Description: Todo.txt sorting plugin +" Author: Leandro Freitas +" Licence: Vim licence +" Website: http://github.com/dbeniamine/todo.txt.vim +" Version: 0.3 + +" These two variables are parameters for the first and second call to the vim +" sort function +" '' means no flags +" '! i' means reverse and ignore case +" for more information on flags, see :help sort +if (! exists("g:Todo_txt_first_level_sort_mode")) + let g:Todo_txt_first_level_sort_mode="i" +endif +if (! exists("g:Todo_txt_second_level_sort_mode")) + let g:Todo_txt_second_level_sort_mode="i" +endif + +" Sort todo by (first) context +noremap sc :call Todo_txt_TwoLevelsSort('@') +" Sort todo by (first) project +noremap sp :call Todo_txt_TwoLevelsSort('+') + +" This is a two level sort designed for todo.txt todo lists +" At the first level, lines are sorted by the word right after the first +" occurence of a:symbol, there must be no space between the symbol and the +" word. Therefore, according to todo.txt syntaxt, if +" a:symbol is a '+' it sort by the first project +" a:symbol is an '@' it sort by the first context +" The second level of sort is done direcetly on the line, so according to +" todo.txt syntax, it means sort by priority +function! Todo_txt_TwoLevelsSort(symbol) + "if the sort modes doesn't start by '!' it must start with a space + let l:sortmode=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_first_level_sort_mode) + let l:sortmode2=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_second_level_sort_mode) + + " Count the number of lines + let l:position= getpos(".") + execute "silent normal g\" + if v:statusmsg =~ '--No lines in buffer--' + "Empty buffer do nothing + return + endif + let l:linecount=str2nr(split(v:statusmsg)[7]) + + " Get all the groups names + let l:curline=0 + let l:groups=[] + while l:curline <= l:linecount + let l:curproj=strpart(matchstr(getline(l:curline),a:symbol.'\a*'),1) + if l:curproj != "" && index(l:groups,l:curproj) == -1 + let l:groups=add(l:groups , l:curproj) + endif + let l:curline += 1 + endwhile + + " Sort by groups + execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/' + for l:p in l:groups + execute '/^.\{-}'.a:symbol.l:p.'.*$' + normal ma + normal G + execute '?^.\{-}'.a:symbol.l:p.'.*$' + normal mb + execute "'a,'b sort".l:sortmode2 + endfor + " Restore the cursor position + call setpos('.', position) +endfunction + +function! Todo_txt_InsertSpaceIfNeeded(str) + let l:c=strpart(a:str,1,1) + if( l:c != '!' && l:c !=' ') + return " ".a:str + endif + retur a:str +endfunction