ADD: Two level sort function
This commit add the first interesting difference from freitass original version. It provides a two level sort function which allow the user to sort the todo by project (or context) then by priority. TODO: Maybe think about three level sort (project, context, priority) in any order.
This commit is contained in:
@@ -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
|
### 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
|
cd todo.txt-vim
|
||||||
cp -R * ~/.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
|
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:
|
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.
|
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
|
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.
|
||||||
|
|
||||||
|
`<leader>-sc` : Sort the file by context (reverse) then by priority
|
||||||
|
`<leader>-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
|
||||||
|
|||||||
22
doc/todo.txt
22
doc/todo.txt
@@ -3,7 +3,11 @@
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
COMMANDS *todo-commands*
|
COMMANDS *todo-commands*
|
||||||
|
|
||||||
`<leader>-s` : Sort the file
|
`<leader>-s` : Sort the file by priority
|
||||||
|
|
||||||
|
`<leader>-sp` : Sort the file by project then by priority
|
||||||
|
|
||||||
|
`<leader>-sc` : Sort the file by context then by priority
|
||||||
|
|
||||||
`<leader>-d` : Insert the current date
|
`<leader>-d` : Insert the current date
|
||||||
|
|
||||||
@@ -16,3 +20,19 @@ COMMANDS *todo-commands*
|
|||||||
`<leader>-D` : Remove completed tasks
|
`<leader>-D` : Remove completed tasks
|
||||||
|
|
||||||
<leader> is \ by default, so <leader>-s means you type \s
|
<leader> is \ by default, so <leader>-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
|
||||||
|
|||||||
78
plugin/todo-txt.vim
Normal file
78
plugin/todo-txt.vim
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
" File: todo.txt.vim
|
||||||
|
" Description: Todo.txt sorting plugin
|
||||||
|
" Author: Leandro Freitas <david@beniamine.net>
|
||||||
|
" 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 <leader>sc :call Todo_txt_TwoLevelsSort('@')<CR>
|
||||||
|
" Sort todo by (first) project
|
||||||
|
noremap <leader>sp :call Todo_txt_TwoLevelsSort('+')<CR>
|
||||||
|
|
||||||
|
" 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\<c-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
|
||||||
Reference in New Issue
Block a user