Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cdb39032f | ||
|
|
f3c5e7b892 | ||
|
|
a21fd1198c | ||
|
|
7515fde8ae | ||
|
|
2e2d39daee | ||
|
|
a03d01e58e | ||
|
|
81c2772905 | ||
|
|
b6d5dc6bb9 | ||
|
|
f9a007ac58 | ||
|
|
45bfb325ae | ||
|
|
081d9d2e3a | ||
|
|
4d819f888b | ||
|
|
41a75a8f50 | ||
|
|
cc281c47eb | ||
|
|
f3a3bdbefb | ||
|
|
3089527c71 | ||
|
|
7fdf0427a8 | ||
|
|
644b6d6628 | ||
|
|
d3b011b718 | ||
|
|
f9715af4a4 | ||
|
|
ab4ecf5220 | ||
|
|
dc4bb8e856 | ||
|
|
6a103f1429 | ||
|
|
9f87eec204 | ||
|
|
53ad73ebda | ||
|
|
68a32427ab |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
*.swp
|
*.swp
|
||||||
doc/tags
|
doc/tags
|
||||||
|
*.pyc
|
||||||
|
|||||||
0
.gitmodules
vendored
Normal file
0
.gitmodules
vendored
Normal file
277
README.markdown
277
README.markdown
@@ -1,88 +1,148 @@
|
|||||||
# Readme
|
# Todo.txt-vim
|
||||||
|
|
||||||
## What is this plugin ?
|
##### # #
|
||||||
|
# #### ##### #### ##### # # ##### # # # # #
|
||||||
|
# # # # # # # # # # # # # # ## ##
|
||||||
|
# # # # # # # # ## # ### # # # # ## #
|
||||||
|
# # # # # # # # ## # # # # # #
|
||||||
|
# # # # # # # ## # # # # # # # # #
|
||||||
|
# #### ##### #### ## # # # # # # # #
|
||||||
|
|
||||||
|
Efficient Todo.txt management in vim
|
||||||
|
|
||||||
|
## Table of Contents
|
||||||
|
|
||||||
|
1. [Release notes](#release-notes)
|
||||||
|
2. [Introduction](#introduction)
|
||||||
|
1. [Todo.txt rules](#todo.txt-rules)
|
||||||
|
2. [Why this Fork ?](#Why-this-fork)
|
||||||
|
3. [Installation](#installation)
|
||||||
|
3. [TodoTxt Files](#todotxt-files)
|
||||||
|
4. [Completion](#completion)
|
||||||
|
5. [Hierarchical Sort](#hierarchical-sort)
|
||||||
|
6. [Mappings](#mappings)
|
||||||
|
1. [Sort](#sort)
|
||||||
|
2. [Priorities](#priorities)
|
||||||
|
3. [Dates](#dates)
|
||||||
|
4. [Done](#done)
|
||||||
|
|
||||||
|
## Release notes
|
||||||
|
|
||||||
|
v0.7.4 includes the overduedate support from Guilherme Victal (see pull
|
||||||
|
[request #45 on freitass version](https://github.com/freitass/todo.txt-vim/pull/45)),
|
||||||
|
it highlight dates in overdue tasks as an Error. It depends on a
|
||||||
|
Python library, however, and as such will only be able to work if your version
|
||||||
|
of Vim was compiled with the `+python` option (as most common versions do).
|
||||||
|
|
||||||
|
If your Vim installation does **not** have Python support, this plugin **will work just fine** but this feature will be disabled.
|
||||||
|
|
||||||
|
|
||||||
|
Since v0.7.3, `TodoComplete` is replaced by `todo#Complete`, you might need to
|
||||||
|
update your vimrc (see [completion](#completion)).
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
|
||||||
|
Todo.txt-vim is a plugin to manage todo.txt files it was initially designed by
|
||||||
|
[Freitass](https://github.com/freitass/todo.txt-vim) then forked and improved
|
||||||
|
by David Beniamine.
|
||||||
|
|
||||||
|
### Todo.txt rules
|
||||||
|
|
||||||
|
Todo.txt is a standard human readable todo notes file defined [here](http://todotxt.com):
|
||||||
|
|
||||||
|
"The todo.txt format is a simple set of
|
||||||
|
[rules](https://github.com/ginatrapani/todo.txt-cli/wiki/The-Todo.txt-Format)
|
||||||
|
that make todo.txt both human and machine-readable. The format supports
|
||||||
|
priorities, creation and completion dates, projects and contexts. That's
|
||||||
|
all you need to be productive. See an example Todo.txt file":
|
||||||
|
|
||||||
|
(A) Call Mom @Phone +Family
|
||||||
|
(A) Schedule annual checkup +Health
|
||||||
|
(B) Outline chapter 5 +FamilyNovel @Computer
|
||||||
|
(C) Add cover sheets @ComputerOffice +FamilyTPSReports
|
||||||
|
Plan backyard herb garden @ComputerHome
|
||||||
|
Pick up milk @ComputerGroceryStore
|
||||||
|
Research self-publishing services +FamilyNovel @ComputerComputer
|
||||||
|
x Download Todo.txt mobile app @ComputerPhone
|
||||||
|
|
||||||
|
### Why this fork ?
|
||||||
|
|
||||||
This plugin is a fork of [freitass
|
This plugin is a fork of [freitass
|
||||||
todo.txt](https://github.com/freitass/todo.txt-vim). It add severals functionalities including a [hierarchical sort](#sort), a
|
todo.txt-vim](https://github.com/freitass/todo.txt-vim). It add severals cool
|
||||||
[complete](#completion) function, some stuff to handle [due dates](#due-dates)
|
functionalities including:
|
||||||
and others stuff see [new features](#new-features).
|
|
||||||
|
|
||||||
Freitass announced on october 30th 2014 that he is not going to merge his version.
|
+ [Hierarchical sort](##hierarchical-sort)
|
||||||
|
+ [A completion function](#completion)
|
||||||
|
+ [A proper handling of due dates](#dates)
|
||||||
|
+ [A Flexible file naming](#todotxt-files).
|
||||||
|
+ Syntax Highlight for couples key:value.
|
||||||
|
+ `<LocalLeader>x` is a toggle which allow you to unmark a task as done.
|
||||||
|
+ `<LocalLeader>C` Toggle Mark a task cancelled
|
||||||
|
+ If the current buffer is a done.txt file, the basic sort sorts on
|
||||||
|
completion date.
|
||||||
|
+ ...
|
||||||
|
|
||||||
## Install
|
### Installation
|
||||||
|
|
||||||
### Quick install
|
#### Vizardry
|
||||||
|
|
||||||
git clone https://github.com/dbeniamine/todo.txt-vim.git
|
If you have [Vizardry](https://github.com/dbeniamine/vizardry) installed,
|
||||||
cd todo.txt-vim
|
you can run from vim:
|
||||||
cp -r ./* ~/.vim
|
|
||||||
|
:Invoke -u dbeniamine todo.txt-vim
|
||||||
|
|
||||||
|
#### Pathogen install
|
||||||
|
|
||||||
|
git clone https://github.com/dbeniamine/todo.txt-vim.git ~/.vim/bundle/todo.txt-vim
|
||||||
|
|
||||||
|
Then from vim: `:Helptags` to update the doc
|
||||||
|
|
||||||
|
#### Quick install
|
||||||
|
|
||||||
|
git clone https://github.com/dbeniamine/todo.txt-vim.git
|
||||||
|
cd todo.txt-vim
|
||||||
|
cp -r ./* ~/.vim
|
||||||
|
|
||||||
|
|
||||||
If you want the help installed, run `:helptags ~/.vim/doc` inside vim after
|
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:
|
having copied the files. Then you will be able to get the commands help with:
|
||||||
`:h todo.txt`
|
`:h todo.txt`
|
||||||
|
|
||||||
### Pathogen install
|
## TodoTxt Files
|
||||||
|
|
||||||
git clone https://github.com/dbeniamine/todo.txt-vim.git ~/.vim/bundle/todo.txt-vim
|
This plugin provides a Flexible file naming for todo.txt, all the following
|
||||||
|
names are recognized as todo:
|
||||||
|
|
||||||
Then from vim: `:Helptags` to update the doc
|
YYYY-MM-[Tt]odo.txt
|
||||||
|
YYYY-MM-DD[Tt]odo.txt
|
||||||
|
[Tt]odo-YYYY-MM.txt
|
||||||
|
[Tt]odo-YYYY-MM-DD.txt
|
||||||
|
[Tt]odo.txt
|
||||||
|
[Tt]oday.txt
|
||||||
|
|
||||||
## Features included in Freitass version
|
And obviously the same are recognize as done:
|
||||||
|
|
||||||
This plugin gives syntax highlighting to [todo.txt](http://todotxt.com/) files. It also defines a few mappings, to help with editing these files:
|
YYYY-MM-[Dd]one.txt
|
||||||
|
YYYY-MM-DD[Dd]one.txt
|
||||||
|
[Dd]one-YYYY-MM.txt
|
||||||
|
[Dd]one-YYYY-MM-DD.txt
|
||||||
|
[Dd]one.txt
|
||||||
|
[Dd]one-[Tt]oday.txt
|
||||||
|
|
||||||
`<LocalLeader>s` : Sort the file
|
Moreover, `<LocalLeader>D` moves the task under the cursor to the done.txt
|
||||||
|
file corresponding to the current todo.txt, aka if you are editing
|
||||||
|
2015-07-07-todo.txt, the done file while be 2015-07-07-done.txt. If you don't
|
||||||
|
like this behavior, you can set the default done.txt name:
|
||||||
|
|
||||||
`<LocalLeader>s+` : Sort the file on +Projects
|
let g:TodoTxtForceDoneName='done.txt'
|
||||||
|
|
||||||
`<LocalLeader>s@` : Sort the file on @Contexts
|
## Completion
|
||||||
|
|
||||||
`<LocalLeader>j` : Lower the priority of the current line
|
This plugin provides a nice complete function for project and context, to use
|
||||||
|
it add the following lines to your vimrc:
|
||||||
|
|
||||||
`<LocalLeader>k` : Increase the priority of the current line
|
" Use todo#Complete as the omni complete function for todo files
|
||||||
|
au filetype todo setlocal omnifunc=todo#Complete
|
||||||
`<LocalLeader>a` : Add the priority (A) to the current line
|
|
||||||
|
|
||||||
`<LocalLeader>b` : Add the priority (B) to the current line
|
|
||||||
|
|
||||||
`<LocalLeader>c` : Add the priority (C) to the current line
|
|
||||||
|
|
||||||
`<LocalLeader>d` : Insert the current date
|
|
||||||
|
|
||||||
`date<tab>` : (Insert mode) Insert the current date
|
|
||||||
|
|
||||||
`<LocalLeader>x` : Toggle mark task as done (inserts current date as completion date)
|
|
||||||
|
|
||||||
`<LocalLeader>X` : Mark all tasks as completed
|
|
||||||
|
|
||||||
`<leader>-D` : Move completed tasks to done.txt
|
|
||||||
|
|
||||||
## New features
|
|
||||||
|
|
||||||
### Sort
|
|
||||||
|
|
||||||
This fork provides a hierarchical sorting function designed to do by project
|
|
||||||
and/or by context sorts and a priority sort.
|
|
||||||
|
|
||||||
`<LocalLeader>sc` : Sort the file by context then by priority
|
|
||||||
`<LocalLeader>scp` : Sort the file by context, project then by priority
|
|
||||||
`<LocalLeader>sp` : Sort the file by project then by priority
|
|
||||||
`<LocalLeader>spc` : Sort the file by project, context 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"
|
|
||||||
|
|
||||||
### Completion
|
|
||||||
|
|
||||||
We also provide a nice complete function for project and context, to use it
|
|
||||||
add the following lines to your vimrc:
|
|
||||||
|
|
||||||
" Use TodoComplete as the omni complete function for todo files
|
|
||||||
au filetype todo setlocal omnifunc=TodoComplete
|
|
||||||
|
|
||||||
You can also start automatically the completion when entering '+' or '@' by
|
You can also start automatically the completion when entering '+' or '@' by
|
||||||
adding the next lines to your vimrc:
|
adding the next lines to your vimrc:
|
||||||
@@ -93,38 +153,87 @@ adding the next lines to your vimrc:
|
|||||||
" Auto complete contexts
|
" Auto complete contexts
|
||||||
au filetype todo imap <buffer> @ @<C-X><C-O>
|
au filetype todo imap <buffer> @ @<C-X><C-O>
|
||||||
|
|
||||||
The TodoComplete function is designed to complete projects (starting by '+')
|
|
||||||
and context (starting by '@'). If you use it on a regular word, it will do a
|
The `todo#Complete` function is designed to complete projects (starting by `+`)
|
||||||
|
and context (starting by `@`). If you use it on a regular word, it will do a
|
||||||
normal keyword completion (on all buffers).
|
normal keyword completion (on all buffers).
|
||||||
|
|
||||||
If you try to complete a project, it will propose all projects in all open
|
If you try to complete a project, it will propose all projects in all open
|
||||||
buffers and for each of them, it will show their context and the name of the
|
buffers and for each of them, it will show their context and the name of the
|
||||||
buffers in which they appears in the preview window.
|
buffers in which they appears in the preview window. It does the same thing
|
||||||
TodoCompelte does the same thing for context except that it gives in the
|
for context except that it gives in the preview the list of projects existing
|
||||||
preview the list of projects existing in each existing contexts.
|
in each existing contexts.
|
||||||
|
|
||||||
### Due dates
|
## Hierarchical sort
|
||||||
|
|
||||||
I've integrated the [work from
|
This fork provides a hierarchical sorting function designed to do by project
|
||||||
durcheinandr](https://github.com/durcheinandr/todo.txt-vim/) concerning due
|
and/or by context sorts and a priority sort.
|
||||||
dates + some little improvements:
|
|
||||||
|
|
||||||
Accorrding to the todo.txt rules, one can define due dates using `due:date` or
|
`<LocalLeader>sc` : Sort the file by context then by priority
|
||||||
`DUE:date` or any other `key:value` combination. This plugins handle dates at
|
`<LocalLeader>scp` : Sort the file by context, project then by priority
|
||||||
the format `YYYY-MM-DD` and the key `due` can be spell using any combination
|
`<LocalLeader>sp` : Sort the file by project then by priority
|
||||||
of lower and upper case letters. The following mappings are provided:
|
`<LocalLeader>spc` : Sort the file by project, context then by priority
|
||||||
|
|
||||||
`<leader>-sd` : Sort the file by due-date. Entries with a due date appears
|
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`
|
||||||
|
|
||||||
|
## Mappings
|
||||||
|
|
||||||
|
By default todo-txt.vim set all the mappings secribed in this section. To
|
||||||
|
prevent this behavior, add the following line to your vimrc
|
||||||
|
|
||||||
|
let g:Todo_txt_do_not_map=1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
`<LocalLeader>` is \ by default, so ̀`<LocaLeader>-s` means you type \s
|
||||||
|
|
||||||
|
### Sort
|
||||||
|
|
||||||
|
+ `<LocalLeader>s` : Sort the file by priority
|
||||||
|
+ `<LocalLeader>s+` : Sort the file on `+Projects`
|
||||||
|
+ `<LocalLeader>s@` : Sort the file on `@Contexts`
|
||||||
|
+ `<LocalLeader>sd` : Sort the file on due dates
|
||||||
|
+ `<LocalLeader>sc` : Sort the file by context then by priority
|
||||||
|
+ `<LocalLeader>scp` : Sort the file by context, project then by priority
|
||||||
|
+ `<LocalLeader>sp` : Sort the file by project then by priority
|
||||||
|
+ `<LocalLeader>spc` : Sort the file by project, context then by priority
|
||||||
|
+ `<leader>-sd` : Sort the file by due-date. Entries with a due date appears
|
||||||
sorted by at the beginning of the file, the rest of the file is not modified.
|
sorted by at the beginning of the file, the rest of the file is not modified.
|
||||||
|
|
||||||
`due:` : (Insert mode) Insert `due:` followed by the current date
|
### Priorities
|
||||||
|
|
||||||
`DUE:` : (Insert mode) Insert `DUE:` followed by the current date
|
+ `<LocalLeader>j` : Lower the priority of the current line
|
||||||
|
+ `<LocalLeader>k` : Increase the priority of the current line
|
||||||
|
+ `<LocalLeader>a` : Add the priority (A) to the current line
|
||||||
|
+ `<LocalLeader>b` : Add the priority (B) to the current line
|
||||||
|
+ `<LocalLeader>c` : Add the priority (C) to the current line
|
||||||
|
|
||||||
### Others
|
### Dates
|
||||||
|
|
||||||
`<LocalLeader>x` is a toggle which allow you to unmark a task as done.
|
+ `<LocalLeader>d` : Insert the current date
|
||||||
|
+ `date<tab>` : (Insert mode) Insert the current date
|
||||||
|
+ `due:` : (Insert mode) Insert `due:` followed by the current date
|
||||||
|
+ `DUE:` : (Insert mode) Insert `DUE:` followed by the current date
|
||||||
|
|
||||||
Syntax highlighting for couples key:value
|
### Done
|
||||||
|
|
||||||
If the current buffer is a done.txt file, the basic sort sorts on completion
|
|
||||||
date.
|
+ `<LocalLeader>x` : Toggle mark task as done (inserts or remove current
|
||||||
|
+ date as completion date)
|
||||||
|
+ `<LocalLeader>C` : Toggle mark task cancelled
|
||||||
|
+ `<LocalLeader>X` : Mark all tasks as completed
|
||||||
|
+ `<LocalLeader>D` : Move completed tasks to done file, see [TodoTxt
|
||||||
|
Files](#todotxt-files)
|
||||||
|
|||||||
372
autoload/todo.vim
Normal file
372
autoload/todo.vim
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
" File: autoload/todo.vim
|
||||||
|
" Description: Todo.txt sorting plugin
|
||||||
|
" Author: David Beniamine <david@beniamine.net>
|
||||||
|
" Licence: Vim licence
|
||||||
|
" Website: http://github.com/dbeniamine/todo.txt.vim
|
||||||
|
" vim: ts=4 sw=4 :help tw=78 cc=80
|
||||||
|
|
||||||
|
" These two variables are parameters for the successive calls the vim sort
|
||||||
|
" '' 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
|
||||||
|
if (! exists("g:Todo_txt_third_level_sort_mode"))
|
||||||
|
let g:Todo_txt_third_level_sort_mode='i'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
" Functions {{{1
|
||||||
|
|
||||||
|
|
||||||
|
function! todo#GetCurpos()
|
||||||
|
if exists("*getcurpos")
|
||||||
|
return getcurpos()
|
||||||
|
endif
|
||||||
|
return getpos('.')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Increment and Decrement The Priority
|
||||||
|
:set nf=octal,hex,alpha
|
||||||
|
|
||||||
|
function! todo#PrioritizeIncrease()
|
||||||
|
normal! 0f)h
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#PrioritizeDecrease()
|
||||||
|
normal! 0f)h
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#PrioritizeAdd (priority)
|
||||||
|
let oldpos=todo#GetCurpos()
|
||||||
|
let line=getline('.')
|
||||||
|
if line !~ '^([A-F])'
|
||||||
|
:call todo#PrioritizeAddAction(a:priority)
|
||||||
|
let oldpos[2]+=4
|
||||||
|
else
|
||||||
|
exec ':s/^([A-F])/('.a:priority.')/'
|
||||||
|
endif
|
||||||
|
call setpos('.',oldpos)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#PrioritizeAddAction (priority)
|
||||||
|
execute "normal! mq0i(".a:priority.") \<esc>`q"
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#RemovePriority()
|
||||||
|
:s/^(\w)\s\+//ge
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#PrependDate()
|
||||||
|
normal! 0"=strftime("%Y-%m-%d ")
|
||||||
|
P
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#ToggleMarkAsDone(status)
|
||||||
|
if (getline(".") =~ 'x\s*\d\{4\}')
|
||||||
|
:call todo#UnMarkAsDone(a:status)
|
||||||
|
else
|
||||||
|
:call todo#MarkAsDone(a:status)
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#UnMarkAsDone(status)
|
||||||
|
if a:status==''
|
||||||
|
let pat=''
|
||||||
|
else
|
||||||
|
let pat=' '.a:status
|
||||||
|
endif
|
||||||
|
exec ':s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}'.pat.'\s*//g'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#MarkAsDone(status)
|
||||||
|
if a:status!=''
|
||||||
|
exec 'normal! I'.a:status.' '
|
||||||
|
endif
|
||||||
|
call todo#PrependDate()
|
||||||
|
normal! Ix
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#MarkAllAsDone()
|
||||||
|
:g!/^x /:call todo#MarkAsDone('')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:AppendToFile(file, lines)
|
||||||
|
let l:lines = []
|
||||||
|
|
||||||
|
" Place existing tasks in done.txt at the beggining of the list.
|
||||||
|
if filereadable(a:file)
|
||||||
|
call extend(l:lines, readfile(a:file))
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Append new completed tasks to the list.
|
||||||
|
call extend(l:lines, a:lines)
|
||||||
|
|
||||||
|
" Write to file.
|
||||||
|
call writefile(l:lines, a:file)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#RemoveCompleted()
|
||||||
|
" Check if we can write to done.txt before proceeding.
|
||||||
|
let l:target_dir = expand('%:p:h')
|
||||||
|
if exists("g:TodoTxtForceDoneName")
|
||||||
|
let l:done=g:TodoTxtForceDoneName
|
||||||
|
else
|
||||||
|
let l:done=substitute(substitute(expand('%:t'),'todo','done',''),'Todo','Done','')
|
||||||
|
endif
|
||||||
|
let l:done_file = l:target_dir.'/'.l:done
|
||||||
|
echo "Writing to ".l:done_file
|
||||||
|
if !filewritable(l:done_file) && !filewritable(l:target_dir)
|
||||||
|
echoerr "Can't write to file '".l:done_file."'"
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:completed = []
|
||||||
|
:g/^x /call add(l:completed, getline(line(".")))|d
|
||||||
|
call s:AppendToFile(l:done_file, l:completed)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#Sort()
|
||||||
|
" vim :sort is usually stable
|
||||||
|
" we sort first on contexts, then on projects and then on priority
|
||||||
|
if expand('%')=~'[Dd]one.*.txt'
|
||||||
|
silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
|
||||||
|
sort n /^x\s*/
|
||||||
|
silent! %s/\(x\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g
|
||||||
|
else
|
||||||
|
sort /@[a-zA-Z]*/ r
|
||||||
|
sort /+[a-zA-Z]*/ r
|
||||||
|
sort /\v\([A-Z]\)/ r
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#SortDue()
|
||||||
|
silent! %s/\([dD][uU][eE]:\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
|
||||||
|
" Sort adding entries with due dates add the beginning
|
||||||
|
sort n /[dD][uU][eE]:/
|
||||||
|
" Count the number of lines
|
||||||
|
silent normal gg
|
||||||
|
execute "/[dD][uU][eE]:"
|
||||||
|
let l:first=getpos(".")[1]
|
||||||
|
silent normal N
|
||||||
|
let l:last=getpos(".")[1]
|
||||||
|
let l:diff=l:last-l:first+1
|
||||||
|
" Put the sorted lines at the beginning of the file
|
||||||
|
execute ':'.l:first
|
||||||
|
execute ':d'.l:diff
|
||||||
|
silent normal gg
|
||||||
|
silent normal P
|
||||||
|
silent! %s/\([dD][uU][eE]:\d\{4}\)\(\d\{2}\)/\1-\2-/g
|
||||||
|
" TODO: add time sorting (YYYY-MM-DD HH:MM)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" This is a Hierarchical sort designed for todo.txt todo lists, however it
|
||||||
|
" might be used for other files types
|
||||||
|
" 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. At the second level, the same kind of sort is done based on
|
||||||
|
" a:symbolsub, is a:symbol==' ', the second sort doesn't occurs
|
||||||
|
" 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 last level of sort is done directly on the line, so according to
|
||||||
|
" todo.txt syntax, it means by priority. This sort is done if and only if the
|
||||||
|
" las argument is not 0
|
||||||
|
function! todo#HierarchicalSort(symbol, symbolsub, dolastsort)
|
||||||
|
if v:statusmsg =~ '--No lines in buffer--'
|
||||||
|
"Empty buffer do nothing
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
"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:sortmodesub=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_second_level_sort_mode)
|
||||||
|
let l:sortmodefinal=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_third_level_sort_mode)
|
||||||
|
|
||||||
|
" Count the number of lines
|
||||||
|
let l:position= todo#GetCurpos()
|
||||||
|
execute "silent normal G"
|
||||||
|
let l:linecount=getpos(".")[1]
|
||||||
|
if(exists("g:Todo_txt_debug"))
|
||||||
|
echo "Linescount: ".l:linecount
|
||||||
|
endif
|
||||||
|
execute "silent normal gg"
|
||||||
|
|
||||||
|
" Get all the groups names
|
||||||
|
let l:groups=GetGroups(a:symbol,1,l:linecount)
|
||||||
|
if(exists("g:Todo_txt_debug"))
|
||||||
|
echo "Groups: "
|
||||||
|
echo l:groups
|
||||||
|
echo 'execute sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
|
||||||
|
endif
|
||||||
|
" Sort by groups
|
||||||
|
execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
|
||||||
|
for l:g in l:groups
|
||||||
|
let l:pat=a:symbol.l:g.'.*$'
|
||||||
|
if(exists("g:Todo_txt_debug"))
|
||||||
|
echo l:pat
|
||||||
|
endif
|
||||||
|
normal gg
|
||||||
|
" Find the beginning of the group
|
||||||
|
let l:groupBegin=search(l:pat,'c')
|
||||||
|
" Find the end of the group
|
||||||
|
let l:groupEnd=search(l:pat,'b')
|
||||||
|
|
||||||
|
" I'm too lazy to sort groups of one line
|
||||||
|
if(l:groupEnd==l:groupBegin)
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
if a:dolastsort
|
||||||
|
if( a:symbolsub!='')
|
||||||
|
" Sort by subgroups
|
||||||
|
let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd)
|
||||||
|
" Go before the first line of the group
|
||||||
|
" Sort the group using the second symbol
|
||||||
|
for l:sg in l:subgroups
|
||||||
|
normal gg
|
||||||
|
let l:pat=a:symbol.l:g.'.*'.a:symbolsub.l:sg.'.*$\|'.a:symbolsub.l:sg.'.*'.a:symbol.l:g.'.*$'
|
||||||
|
" Find the beginning of the subgroup
|
||||||
|
let l:subgroupBegin=search(l:pat,'c')
|
||||||
|
" Find the end of the subgroup
|
||||||
|
let l:subgroupEnd=search(l:pat,'b')
|
||||||
|
" Sort by priority
|
||||||
|
execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal
|
||||||
|
endfor
|
||||||
|
else
|
||||||
|
" Sort by priority
|
||||||
|
if(exists("g:Todo_txt_debug"))
|
||||||
|
echo 'execute '.l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
|
||||||
|
endif
|
||||||
|
execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
" Restore the cursor position
|
||||||
|
call setpos('.', position)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Returns the list of groups starting by a:symbol between lines a:begin and
|
||||||
|
" a:end
|
||||||
|
function! GetGroups(symbol,begin, end)
|
||||||
|
let l:curline=a:begin
|
||||||
|
let l:groups=[]
|
||||||
|
while l:curline <= a:end
|
||||||
|
let l:curproj=strpart(matchstr(getline(l:curline),a:symbol.'\S*'),1)
|
||||||
|
if l:curproj != "" && index(l:groups,l:curproj) == -1
|
||||||
|
let l:groups=add(l:groups , l:curproj)
|
||||||
|
endif
|
||||||
|
let l:curline += 1
|
||||||
|
endwhile
|
||||||
|
return l:groups
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Insert a space if needed (the first char isn't '!' or ' ') in front of
|
||||||
|
" sort parameters
|
||||||
|
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
|
||||||
|
|
||||||
|
" Completion {{{1
|
||||||
|
|
||||||
|
" Simple keyword completion on all buffers {{{2
|
||||||
|
function! TodoKeywordComplete(base)
|
||||||
|
" Search for matches
|
||||||
|
let res = []
|
||||||
|
for bufnr in range(1,bufnr('$'))
|
||||||
|
let lines=getbufline(bufnr,1,"$")
|
||||||
|
for line in lines
|
||||||
|
if line =~ a:base
|
||||||
|
" init temporary item
|
||||||
|
let item={}
|
||||||
|
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
|
||||||
|
call add(res,item)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
return res
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Convert an item to the completion format and add it to the completion list
|
||||||
|
fun! TodoAddToCompletionList(list,item,opp)
|
||||||
|
" Create the definitive item
|
||||||
|
let resitem={}
|
||||||
|
let resitem.word=a:item.word
|
||||||
|
let resitem.info=a:opp=='+'?"Projects":"Contexts"
|
||||||
|
let resitem.info.=": ".join(a:item.related, ", ")
|
||||||
|
\."\nBuffers: ".join(a:item.buffers, ", ")
|
||||||
|
call add(a:list,resitem)
|
||||||
|
endfun
|
||||||
|
|
||||||
|
fun! TodoCopyTempItem(item)
|
||||||
|
let ret={}
|
||||||
|
let ret.word=a:item.word
|
||||||
|
let ret.related=[a:item.related]
|
||||||
|
let ret.buffers=[a:item.buffers]
|
||||||
|
return ret
|
||||||
|
endfun
|
||||||
|
|
||||||
|
" Intelligent completion for projects and Contexts {{{2
|
||||||
|
fun! todo#Complete(findstart, base)
|
||||||
|
if a:findstart
|
||||||
|
let line = getline('.')
|
||||||
|
let start = col('.') - 1
|
||||||
|
while start > 0 && line[start - 1] !~ '\s'
|
||||||
|
let start -= 1
|
||||||
|
endwhile
|
||||||
|
return start
|
||||||
|
else
|
||||||
|
if a:base !~ '^+' && a:base !~ '^@'
|
||||||
|
return TodoKeywordComplete(a:base)
|
||||||
|
endif
|
||||||
|
" Opposite sign
|
||||||
|
let opp=a:base=~'+'?'@':'+'
|
||||||
|
" Search for matchs
|
||||||
|
let res = []
|
||||||
|
for bufnr in range(1,bufnr('$'))
|
||||||
|
let lines=getbufline(bufnr,1,"$")
|
||||||
|
for line in lines
|
||||||
|
if line =~ "[x\s0-9\-]*([a-Z]).* ".a:base
|
||||||
|
" init temporary item
|
||||||
|
let item={}
|
||||||
|
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
|
||||||
|
let item.buffers=bufname(bufnr)
|
||||||
|
let item.related=substitute(line,'.*\s\('.opp.'\S\S*\).*','\1',"")
|
||||||
|
call add(res,item)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
call sort(res)
|
||||||
|
" Here all results are sorted in res, but we need to merge them
|
||||||
|
let ret=[]
|
||||||
|
if res != []
|
||||||
|
let curitem=TodoCopyTempItem(res[0])
|
||||||
|
for it in res
|
||||||
|
if curitem.word==it.word
|
||||||
|
" Merge results
|
||||||
|
if index(curitem.related,it.related) <0
|
||||||
|
call add(curitem.related,it.related)
|
||||||
|
endif
|
||||||
|
if index(curitem.buffers,it.buffers) <0
|
||||||
|
call add(curitem.buffers,it.buffers)
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
" Add to list
|
||||||
|
call TodoAddToCompletionList(ret,curitem,opp)
|
||||||
|
" Init new item from it
|
||||||
|
let curitem=TodoCopyTempItem(it)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
" Don't forget to add the list item
|
||||||
|
call TodoAddToCompletionList(ret,curitem,opp)
|
||||||
|
endif
|
||||||
|
return ret
|
||||||
|
endif
|
||||||
|
endfun
|
||||||
|
|
||||||
123
autoload/todo/txt.vim
Normal file
123
autoload/todo/txt.vim
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
" File: todo.txt.vim
|
||||||
|
" Description: Todo.txt filetype detection
|
||||||
|
" Author: Leandro Freitas <freitass@gmail.com>
|
||||||
|
" License: Vim license
|
||||||
|
" Website: http://github.com/freitass/todo.txt-vim
|
||||||
|
" Version: 0.4
|
||||||
|
|
||||||
|
" Export Context Dictionary for unit testing {{{1
|
||||||
|
function! s:get_SID()
|
||||||
|
return matchstr(expand('<sfile>'), '<SNR>\d\+_')
|
||||||
|
endfunction
|
||||||
|
let s:SID = s:get_SID()
|
||||||
|
delfunction s:get_SID
|
||||||
|
|
||||||
|
function! todo#txt#__context__()
|
||||||
|
return { 'sid': s:SID, 'scope': s: }
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Functions {{{1
|
||||||
|
function! s:remove_priority()
|
||||||
|
:s/^(\w)\s\+//ge
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:get_current_date()
|
||||||
|
return strftime('%Y-%m-%d')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#prepend_date()
|
||||||
|
execute 'normal! I' . s:get_current_date() . ' '
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#replace_date()
|
||||||
|
let current_line = getline('.')
|
||||||
|
if (current_line =~ '^\(([a-zA-Z]) \)\?\d\{2,4\}-\d\{2\}-\d\{2\} ') &&
|
||||||
|
\ exists('g:todo_existing_date') && g:todo_existing_date == 'n'
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
execute 's/^\(([a-zA-Z]) \)\?\(\d\{2,4\}-\d\{2\}-\d\{2\} \)\?/\1' . s:get_current_date() . ' /'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#mark_as_done()
|
||||||
|
call s:remove_priority()
|
||||||
|
call todo#txt#prepend_date()
|
||||||
|
normal! Ix
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#mark_all_as_done()
|
||||||
|
:g!/^x /:call todo#txt#mark_as_done()
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:append_to_file(file, lines)
|
||||||
|
let l:lines = []
|
||||||
|
|
||||||
|
" Place existing tasks in done.txt at the beggining of the list.
|
||||||
|
if filereadable(a:file)
|
||||||
|
call extend(l:lines, readfile(a:file))
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Append new completed tasks to the list.
|
||||||
|
call extend(l:lines, a:lines)
|
||||||
|
|
||||||
|
" Write to file.
|
||||||
|
call writefile(l:lines, a:file)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#remove_completed()
|
||||||
|
" Check if we can write to done.txt before proceeding.
|
||||||
|
|
||||||
|
let l:target_dir = expand('%:p:h')
|
||||||
|
let l:todo_file = expand('%:p')
|
||||||
|
let l:done_file = substitute(substitute(l:todo_file, 'todo.txt$', 'done.txt', ''), 'Todo.txt$', 'Done.txt', '')
|
||||||
|
if !filewritable(l:done_file) && !filewritable(l:target_dir)
|
||||||
|
echoerr "Can't write to file 'done.txt'"
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:completed = []
|
||||||
|
:g/^x /call add(l:completed, getline(line(".")))|d
|
||||||
|
call s:append_to_file(l:done_file, l:completed)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#sort_by_context() range
|
||||||
|
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs@[^[:blank:]]\\+/ r"
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#sort_by_project() range
|
||||||
|
execute a:firstline . "," . a:lastline . "sort /\\(^\\| \\)\\zs+[^[:blank:]]\\+/ r"
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#sort_by_date() range
|
||||||
|
let l:date_regex = "\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}"
|
||||||
|
execute a:firstline . "," . a:lastline . "sort /" . l:date_regex . "/ r"
|
||||||
|
execute a:firstline . "," . a:lastline . "g!/" . l:date_regex . "/m" . a:lastline
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#sort_by_due_date() range
|
||||||
|
let l:date_regex = "due:\\d\\{2,4\\}-\\d\\{2\\}-\\d\\{2\\}"
|
||||||
|
execute a:firstline . "," . a:lastline . "sort /" . l:date_regex . "/ r"
|
||||||
|
execute a:firstline . "," . a:lastline . "g!/" . l:date_regex . "/m" . a:lastline
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Increment and Decrement The Priority
|
||||||
|
:set nf=octal,hex,alpha
|
||||||
|
|
||||||
|
function! todo#txt#prioritize_increase()
|
||||||
|
normal! 0f)h
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#prioritize_decrease()
|
||||||
|
normal! 0f)h
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#prioritize_add(priority)
|
||||||
|
" Need to figure out how to only do this if the first visible letter in a line is not (
|
||||||
|
:call todo#txt#prioritize_add_action(a:priority)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! todo#txt#prioritize_add_action(priority)
|
||||||
|
execute 's/^\(([a-zA-Z]) \)\?/(' . a:priority . ') /'
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Modeline {{{1
|
||||||
|
" vim: ts=8 sw=4 sts=4 et foldenable foldmethod=marker foldcolumn=1
|
||||||
327
doc/todo.txt
327
doc/todo.txt
@@ -1,94 +1,261 @@
|
|||||||
*todo.txt*
|
*Todo.txt-vim*
|
||||||
|
|
||||||
==============================================================================
|
##### # #
|
||||||
COMMANDS *todo-commands*
|
# #### ##### #### ##### # # ##### # # # # #
|
||||||
|
# # # # # # # # # # # # # # ## ##
|
||||||
|
# # # # # # # # ## # ### # # # # ## #
|
||||||
|
# # # # # # # # ## # # # # # #
|
||||||
|
# # # # # # # ## # # # # # # # # #
|
||||||
|
# #### ##### #### ## # # # # # # # #
|
||||||
|
|
||||||
`<LocalLeader>s` : Sort the file by priority
|
Efficient Todo.txt management in vim
|
||||||
|
|
||||||
`<LocalLeader>s+` : Sort the file on +Projects
|
|
||||||
|
|
||||||
`<LocalLeader>s@` : Sort the file on @Contexts
|
|
||||||
|
|
||||||
`<LocalLeader>s@` : Sort the file on due dates
|
|
||||||
|
|
||||||
`<LocalLeader>sc` : Sort the file by context then by priority
|
|
||||||
|
|
||||||
`<LocalLeader>scp` : Sort the file by context, project then by priority
|
|
||||||
|
|
||||||
`<LocalLeader>sp` : Sort the file by project then by priority
|
|
||||||
|
|
||||||
`<LocalLeader>spc` : Sort the file by project, context then by priority
|
|
||||||
|
|
||||||
`<leader>-sd` : Sort the file by due-date. Entries with a due date appears
|
|
||||||
sorted by at the beginning of the file, the rest of the file is not modified.
|
|
||||||
|
|
||||||
`<LocalLeader>j` : Lower the priority of the current line
|
|
||||||
|
|
||||||
`<LocalLeader>k` : Increase the priority of the current line
|
|
||||||
|
|
||||||
`<LocalLeader>a` : Add the priority (A) to the current line
|
|
||||||
|
|
||||||
`<LocalLeader>b` : Add the priority (B) to the current line
|
|
||||||
|
|
||||||
`<LocalLeader>c` : Add the priority (C) to the current line
|
|
||||||
|
|
||||||
`<LocalLeader>d` : Insert the current date
|
|
||||||
|
|
||||||
`date<tab>` : (Insert mode) Insert the current date
|
|
||||||
|
|
||||||
`due:` : (Insert mode) Insert `due:` followed by the current date
|
|
||||||
|
|
||||||
`DUE:` : (Insert mode) Insert `DUE:` followed by the current date
|
|
||||||
|
|
||||||
`<LocalLeader>x` : Toggle mark task as done (inserts or remove current date as
|
|
||||||
completion date)
|
|
||||||
|
|
||||||
`<LocalLeader>X` : Mark all tasks as completed
|
|
||||||
|
|
||||||
`<LocalLeader>D` : Move completed tasks to done.txt
|
|
||||||
|
|
||||||
<LocalLeader> is \ by default, so <leader>-s means you type \s
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
CONFIGURATION *todo-configuration*
|
Table of Contents *TodoTxt-Contents* ~
|
||||||
|
|
||||||
|
1. Release notes.................................|TodoTxt-ReleaseNotes|
|
||||||
|
2. Introduction..................................|TodoTxt-Introduction|
|
||||||
|
2.1 Todo.txt rules...........................|TodoTxt-Rules|
|
||||||
|
2.2 Why this Fork............................|TodoTxt-Fork|
|
||||||
|
2.3 Installation.............................|TodoTxt-Installation|
|
||||||
|
3. TodoTxt Files.................................|TodoTxt-Files|
|
||||||
|
4. Completion....................................|TodoTxt-Completion|
|
||||||
|
5. Hierarchical Sort.............................|TodoTxt-HierarchicalSort|
|
||||||
|
6. Mappings......................................|TodoTxt-Mappings|
|
||||||
|
6.1 Sort.....................................|TodoTxt-Sort|
|
||||||
|
6.2 Priorities...............................|TodoTxt-Priorities|
|
||||||
|
6.3 Dates....................................|TodoTxt-Dates|
|
||||||
|
6.4 Done.txt.................................|TodoTxt-Done|
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
1. Release notes *TodoTxt-ReleaseNotes* ~
|
||||||
|
|
||||||
|
v0.7.4 includes the overduedate support from Guilherme Victal (see pull
|
||||||
|
request #45 on freitass version (https://github.com/freitass/todo.txt-vim/pull/45)),
|
||||||
|
it highlight dates in overdue tasks as an Error. It depends on a
|
||||||
|
Python library, however, and as such will only be able to work if your version
|
||||||
|
of Vim was compiled with the `+python` option (as most common versions do).
|
||||||
|
|
||||||
|
Since v0.7.3, `TodoComplete` is replaced by `todo#Complete`, you might need to
|
||||||
|
update your vimrc (see |TodoTxt-Completion|).
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
2. Introduction *TodoTxt-Introduction* ~
|
||||||
|
|
||||||
|
Todo.txt-vim is a plugin to manage todo.txt files it was initially designed by
|
||||||
|
Freitass (https://github.com/freitass/todo.txt-vim) then forked and improved
|
||||||
|
by David Beniamine.
|
||||||
|
|
||||||
|
2.1 Todo.txt rules *TodoTxt-Rules*
|
||||||
|
|
||||||
|
Todo.txt is a standard human readable todo notes file defined here:
|
||||||
|
http://todotxt.com
|
||||||
|
|
||||||
|
"The todo.txt format is a simple set of
|
||||||
|
rules(https://github.com/ginatrapani/todo.txt-cli/wiki/The-Todo.txt-Format)
|
||||||
|
that make todo.txt both human and machine-readable. The format supports
|
||||||
|
priorities, creation and completion dates, projects and contexts. That's
|
||||||
|
all you need to be productive. See an example Todo.txt file":
|
||||||
|
>
|
||||||
|
(A) Call Mom @Phone +Family
|
||||||
|
(A) Schedule annual checkup +Health
|
||||||
|
(B) Outline chapter 5 +FamilyNovel @Computer
|
||||||
|
(C) Add cover sheets @ComputerOffice +FamilyTPSReports
|
||||||
|
Plan backyard herb garden @ComputerHome
|
||||||
|
Pick up milk @ComputerGroceryStore
|
||||||
|
Research self-publishing services +FamilyNovel @ComputerComputer
|
||||||
|
x Download Todo.txt mobile app @ComputerPhone
|
||||||
|
<
|
||||||
|
2.2 Why this fork ? *TodoTxt-Fork*
|
||||||
|
|
||||||
|
This plugin is a fork of freitass todo.txt-vim
|
||||||
|
(https://github.com/freitass/todo.txt-vim). It add severals cool
|
||||||
|
functionalities including:
|
||||||
|
|
||||||
|
+ Hierarchical sort: |TodoTxt-Sort| and |TodoTxt-HierarchicalSort|.
|
||||||
|
+ A completion function: |TodoTxt-Completion|.
|
||||||
|
+ A proper handling of due dates: |TodoTxt-Dates|
|
||||||
|
+ A Flexible file naming: |TodoTxt-Files|.
|
||||||
|
+ Syntax Highlight for couples key:value.
|
||||||
|
+ `<LocalLeader>x` is a toggle which allow you to unmark a task as done.
|
||||||
|
+ `<LocalLeader>C` Toggle Mark a task cancelled
|
||||||
|
+ If the current buffer is a done.txt file, the basic sort sorts on
|
||||||
|
completion date.
|
||||||
|
+ ...
|
||||||
|
|
||||||
|
2.3 Installation *TodoTxt-Installation*
|
||||||
|
|
||||||
|
+ Vizardry
|
||||||
|
|
||||||
|
If you have Vizardry(https://github.com/dbeniamine/vizardry) installed,
|
||||||
|
you can run from vim:
|
||||||
|
>
|
||||||
|
:Invoke -u dbeniamine todo.txt-vim
|
||||||
|
<
|
||||||
|
+ Pathogen install
|
||||||
|
>
|
||||||
|
git clone https://github.com/dbeniamine/todo.txt-vim.git ~/.vim/bundle/todo.txt-vim
|
||||||
|
<
|
||||||
|
Then from vim: `:Helptags` to update the doc
|
||||||
|
|
||||||
|
+ Quick install
|
||||||
|
>
|
||||||
|
git clone https://github.com/dbeniamine/todo.txt-vim.git
|
||||||
|
cd todo.txt-vim
|
||||||
|
cp -r ./* ~/.vim
|
||||||
|
<
|
||||||
|
|
||||||
|
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`
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
3. TodoTxt Files *TodoTxt-Files* ~
|
||||||
|
|
||||||
|
This plugin provides a Flexible file naming for todo.txt, all the following
|
||||||
|
names are recognized as todo:
|
||||||
|
>
|
||||||
|
YYYY-MM-[Tt]odo.txt
|
||||||
|
YYYY-MM-DD[Tt]odo.txt
|
||||||
|
[Tt]odo-YYYY-MM.txt
|
||||||
|
[Tt]odo-YYYY-MM-DD.txt
|
||||||
|
[Tt]odo.txt
|
||||||
|
[Tt]oday.txt
|
||||||
|
<
|
||||||
|
And obviously the same are recognize as done:
|
||||||
|
>
|
||||||
|
YYYY-MM-[Dd]one.txt
|
||||||
|
YYYY-MM-DD[Dd]one.txt
|
||||||
|
[Dd]one-YYYY-MM.txt
|
||||||
|
[Dd]one-YYYY-MM-DD.txt
|
||||||
|
[Dd]one.txt
|
||||||
|
[Dd]one-[Tt]oday.txt
|
||||||
|
<
|
||||||
|
Moreover, `<LocalLeader>D` moves the task under the cursor to the done.txt
|
||||||
|
file corresponding to the current todo.txt, aka if you are editing
|
||||||
|
2015-07-07-todo.txt, the done file while be 2015-07-07-done.txt. If you don't
|
||||||
|
like this behavior, you can set the default done.txt name:
|
||||||
|
>
|
||||||
|
let g:TodoTxtForceDoneName='done.txt'
|
||||||
|
<
|
||||||
|
===============================================================================
|
||||||
|
4. Completion *TodoTxt-Completion* ~
|
||||||
|
|
||||||
|
This plugin provides a nice complete function for project and context, to use
|
||||||
|
it add the following lines to your vimrc:
|
||||||
|
>
|
||||||
|
" Use todo#complete as the omni complete function for todo files
|
||||||
|
au filetype todo setlocal omnifunc=todo#complete
|
||||||
|
<
|
||||||
|
You can also start automatically the completion when entering '+' or '@' by
|
||||||
|
adding the next lines to your vimrc:
|
||||||
|
>
|
||||||
|
" Auto complete projects
|
||||||
|
au filetype todo imap <buffer> + +<C-X><C-O>
|
||||||
|
|
||||||
|
" Auto complete contexts
|
||||||
|
au filetype todo imap <buffer> @ @<C-X><C-O>
|
||||||
|
<
|
||||||
|
|
||||||
|
The `todo#complete` function is designed to complete projects (starting by `+`)
|
||||||
|
and context (starting by `@`). If you use it on a regular word, it will do a
|
||||||
|
normal keyword completion (on all buffers).
|
||||||
|
|
||||||
|
If you try to complete a project, it will propose all projects in all open
|
||||||
|
buffers and for each of them, it will show their context and the name of the
|
||||||
|
buffers in which they appears in the preview window. It does the same thing
|
||||||
|
for context except that it gives in the preview the list of projects existing
|
||||||
|
in each existing contexts.
|
||||||
|
|
||||||
|
===============================================================================
|
||||||
|
5. Hierarchical sort *TodoTxt-HierarchicalSort* ~
|
||||||
|
|
||||||
|
This fork provides a hierarchical sorting function designed to do by project
|
||||||
|
and/or by context sorts and a priority sort.
|
||||||
|
|
||||||
|
`<LocalLeader>sc` : Sort the file by context then by priority
|
||||||
|
`<LocalLeader>scp` : Sort the file by context, project then by priority
|
||||||
|
`<LocalLeader>sp` : Sort the file by project then by priority
|
||||||
|
`<LocalLeader>spc` : Sort the file by project, context then by priority
|
||||||
|
|
||||||
The user can give argument for the two calls to vim sort function by changing
|
The user can give argument for the two calls to vim sort function by changing
|
||||||
the following variables:
|
the following variables:
|
||||||
|
>
|
||||||
g:Todo_txt_first_level_sort_mode
|
g:Todo_txt_first_level_sort_mode
|
||||||
g:Todo_txt_second_level_sort_mode
|
g:Todo_txt_second_level_sort_mode
|
||||||
|
<
|
||||||
Defaults values are:
|
Defaults values are:
|
||||||
|
|
||||||
g:Todo_txt_first_level_sort_mode="i"
|
>
|
||||||
g:Todo_txt_second_level_sort_mode="i"
|
g:Todo_txt_first_level_sort_mode="i"
|
||||||
|
g:Todo_txt_second_level_sort_mode="i"
|
||||||
|
<
|
||||||
|
|
||||||
|
For more information on the available flags see |:sort|
|
||||||
For more information on the available flags see help :sort
|
|
||||||
|
|
||||||
We also provide a nice complete function for project and context, to use it
|
|
||||||
add the following lines to your vimrc:
|
|
||||||
|
|
||||||
" Use TodoComplete as the omni complete for todo files
|
|
||||||
au filetype todo setlocal omnifunc=TodoComplete
|
|
||||||
|
|
||||||
You can also start automatically the completion when entering '+' or '@' by
|
|
||||||
adding the next lines to your vimrc:
|
|
||||||
|
|
||||||
" Auto complete projects
|
|
||||||
au filetype todo imap <buffer> + +<C-X><C-O>
|
|
||||||
|
|
||||||
" Auto complete contexts
|
|
||||||
au filetype todo imap <buffer> @ @<C-X><C-O>
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
COMPLETION *todo-complete*
|
6. Mappings *TodoTxt-Mappings* ~
|
||||||
|
|
||||||
The TodoComplete function is designed to complete projects (starting by '+')
|
By default todo-txt.vim set all the mappings secribed in this section. To
|
||||||
and context (starting by '@'). If you use it on a regular word, it will do a
|
prevent this behavior, add the following line to your vimrc
|
||||||
normal keyword completion (on all buffers).
|
>
|
||||||
If you try to complete a project, it will propose all projects in all open
|
let g:Todo_txt_do_not_map=1
|
||||||
buffers and for each of them, it will show their context and the name of the
|
<
|
||||||
buffers in which they appears in the preview window.
|
|
||||||
TodoCompelte does the same thing for context except that it gives in the
|
6.1 Sort *TodoTxt-Sort*
|
||||||
preview the list of projects existing in each existing contexts.
|
|
||||||
|
`<LocalLeader>s` : Sort the file by priority
|
||||||
|
|
||||||
|
`<LocalLeader>s+` : Sort the file on +Projects
|
||||||
|
|
||||||
|
`<LocalLeader>s@` : Sort the file on @Contexts
|
||||||
|
|
||||||
|
`<LocalLeader>sd` : Sort the file on due dates
|
||||||
|
|
||||||
|
`<LocalLeader>sc` : Sort the file by context then by priority
|
||||||
|
|
||||||
|
`<LocalLeader>scp` : Sort the file by context, project then by priority
|
||||||
|
|
||||||
|
`<LocalLeader>sp` : Sort the file by project then by priority
|
||||||
|
|
||||||
|
`<LocalLeader>spc` : Sort the file by project, context then by priority
|
||||||
|
|
||||||
|
`<leader>-sd` : Sort the file by due-date. Entries with a due date appears
|
||||||
|
sorted by at the beginning of the file, the rest of the file is not modified.
|
||||||
|
|
||||||
|
6.2 Priorities *TodoTxt-Priorities*
|
||||||
|
|
||||||
|
`<LocalLeader>j` : Lower the priority of the current line
|
||||||
|
|
||||||
|
`<LocalLeader>k` : Increase the priority of the current line
|
||||||
|
|
||||||
|
`<LocalLeader>a` : Add the priority (A) to the current line
|
||||||
|
|
||||||
|
`<LocalLeader>b` : Add the priority (B) to the current line
|
||||||
|
|
||||||
|
`<LocalLeader>c` : Add the priority (C) to the current line
|
||||||
|
|
||||||
|
6.3 Dates *TodoTxt-Dates*
|
||||||
|
|
||||||
|
`<LocalLeader>d` : Insert the current date
|
||||||
|
|
||||||
|
`date<tab>` : (Insert mode) Insert the current date
|
||||||
|
|
||||||
|
`due:` : (Insert mode) Insert `due:` followed by the current date
|
||||||
|
|
||||||
|
`DUE:` : (Insert mode) Insert `DUE:` followed by the current date
|
||||||
|
|
||||||
|
6.4 Done *TodoTxt-Done*
|
||||||
|
|
||||||
|
|
||||||
|
`<LocalLeader>x` : Toggle mark task as done (inserts or remove current
|
||||||
|
date as completion date)
|
||||||
|
|
||||||
|
`<LocalLeader>C` : Toggle mark task cancelled
|
||||||
|
|
||||||
|
`<LocalLeader>X` : Mark all tasks as completed
|
||||||
|
|
||||||
|
`<LocalLeader>D` : Move completed tasks to done file, see |TodoTxt-Files|
|
||||||
|
|
||||||
|
`<LocalLeader>` is \ by default, so ̀`<LocaLeader>-s` means you type \s
|
||||||
|
|||||||
@@ -3,8 +3,17 @@
|
|||||||
" Author: David Beniamine <david@beniamine.net>, Leandro Freitas <freitass@gmail.com>
|
" Author: David Beniamine <david@beniamine.net>, Leandro Freitas <freitass@gmail.com>
|
||||||
" License: Vim license
|
" License: Vim license
|
||||||
" Website: http://github.com/dbeniamine/todo.txt-vim
|
" Website: http://github.com/dbeniamine/todo.txt-vim
|
||||||
" Version: 0.7
|
" vim: ts=4 sw=4 :help tw=78 cc=80
|
||||||
|
|
||||||
autocmd BufNewFile,BufRead [Tt]odo.txt set filetype=todo
|
autocmd BufNewFile,BufRead [Tt]odo.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead [Tt]odo-\d\\\{4\}-\d\\\{2\}-\d\\\{2\}.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead [Tt]odo-\d\\\{4\}-\d\\\{2\}.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-\d\\\{2\}-[Tt]odo.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-[Tt]odo.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead [Tt]oday.txt set filetype=todo
|
||||||
autocmd BufNewFile,BufRead [Dd]one.txt set filetype=todo
|
autocmd BufNewFile,BufRead [Dd]one.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead [Dd]one-\d\\\{4\}-\d\\\{2\}-\d\\\{2\}.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead [Dd]one-\d\\\{4\}-\d\\\{2\}.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-\d\\\{2\}-[Dd]one.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead \d\\\{4\}-\d\\\{2\}-[Dd]one.txt set filetype=todo
|
||||||
|
autocmd BufNewFile,BufRead [Dd]one-[Tt]oday.txt set filetype=todo
|
||||||
|
|||||||
@@ -3,12 +3,18 @@
|
|||||||
" Author: David Beniamine <David@Beniamine.net>, Leandro Freitas <freitass@gmail.com>
|
" Author: David Beniamine <David@Beniamine.net>, Leandro Freitas <freitass@gmail.com>
|
||||||
" License: Vim license
|
" License: Vim license
|
||||||
" Website: http://github.com/dbeniamine/todo.txt-vim
|
" Website: http://github.com/dbeniamine/todo.txt-vim
|
||||||
" Version: 0.7.1
|
" vim: ts=4 sw=4 :help tw=78 cc=80
|
||||||
|
|
||||||
" Save context {{{1
|
" Save context {{{1
|
||||||
let s:save_cpo = &cpo
|
let s:save_cpo = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
|
if exists("g:Todo_txt_loaded")
|
||||||
|
finish
|
||||||
|
else
|
||||||
|
let g:Todo_txt_loaded=0.7.4
|
||||||
|
endif
|
||||||
|
|
||||||
" General options {{{1
|
" General options {{{1
|
||||||
" Some options lose their values when window changes. They will be set every
|
" Some options lose their values when window changes. They will be set every
|
||||||
" time this script is invocated, which is whenever a file of this type is
|
" time this script is invocated, which is whenever a file of this type is
|
||||||
@@ -16,235 +22,53 @@ set cpo&vim
|
|||||||
setlocal textwidth=0
|
setlocal textwidth=0
|
||||||
setlocal wrapmargin=0
|
setlocal wrapmargin=0
|
||||||
|
|
||||||
|
|
||||||
" Functions {{{1
|
|
||||||
function! s:TodoTxtRemovePriority()
|
|
||||||
:s/^(\w)\s\+//ge
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtPrependDate()
|
|
||||||
normal! 0"=strftime("%Y-%m-%d ")
|
|
||||||
P
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtToggleMarkAsDone()
|
|
||||||
if (getline(".") =~ 'x\s*\d\{4\}')
|
|
||||||
:call TodoTxtUnMarkAsDone()
|
|
||||||
else
|
|
||||||
:call TodoTxtMarkAsDone()
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtUnMarkAsDone()
|
|
||||||
:s/\s*x\s*\d\{4}-\d\{1,2}-\d\{1,2}\s*//g
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtMarkAsDone()
|
|
||||||
call TodoTxtPrependDate()
|
|
||||||
normal! Ix
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtMarkAllAsDone()
|
|
||||||
:g!/^x /:call TodoTxtMarkAsDone()
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:AppendToFile(file, lines)
|
|
||||||
let l:lines = []
|
|
||||||
|
|
||||||
" Place existing tasks in done.txt at the beggining of the list.
|
|
||||||
if filereadable(a:file)
|
|
||||||
call extend(l:lines, readfile(a:file))
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Append new completed tasks to the list.
|
|
||||||
call extend(l:lines, a:lines)
|
|
||||||
|
|
||||||
" Write to file.
|
|
||||||
call writefile(l:lines, a:file)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtRemoveCompleted()
|
|
||||||
" Check if we can write to done.txt before proceeding.
|
|
||||||
let l:target_dir = expand('%:p:h')
|
|
||||||
let l:done_file = l:target_dir.'/done.txt'
|
|
||||||
if !filewritable(l:done_file) && !filewritable(l:target_dir)
|
|
||||||
echoerr "Can't write to file 'done.txt'"
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let l:completed = []
|
|
||||||
:g/^x /call add(l:completed, getline(line(".")))|d
|
|
||||||
call s:AppendToFile(l:done_file, l:completed)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtSort()
|
|
||||||
" vim :sort is usually stable
|
|
||||||
" we sort first on contexts, then on projects and then on priority
|
|
||||||
if expand('%')=~'done.txt'
|
|
||||||
silent! %s/\(x\s*\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
|
|
||||||
sort n /^x\s*/
|
|
||||||
silent! %s/\(x\s*\d\{4}\)\(\d\{2}\)/\1-\2-/g
|
|
||||||
else
|
|
||||||
sort /@[a-zA-Z]*/ r
|
|
||||||
sort /+[a-zA-Z]*/ r
|
|
||||||
sort /\v\([A-Z]\)/ r
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtSortDue()
|
|
||||||
silent! %s/\([dD][uU][eE]:\d\{4}\)-\(\d\{2}\)-\(\d\{2}\)/\1\2\3/g
|
|
||||||
" Sort adding entries with due dates add the beginning
|
|
||||||
sort n /[dD][uU][eE]:/
|
|
||||||
" Count the number of lines
|
|
||||||
silent normal gg
|
|
||||||
execute "/[dD][uU][eE]:"
|
|
||||||
let l:first=getpos(".")[1]
|
|
||||||
silent normal N
|
|
||||||
let l:last=getpos(".")[1]
|
|
||||||
let l:diff=l:last-l:first+1
|
|
||||||
" Put the sorted lines at the beginning of the file
|
|
||||||
execute ':'.l:first
|
|
||||||
execute ':d'.l:diff
|
|
||||||
silent normal gg
|
|
||||||
silent normal P
|
|
||||||
silent! %s/\([dD][uU][eE]:\d\{4}\)\(\d\{2}\)/\1-\2-/g
|
|
||||||
" TODO: add time sorting (YYYY-MM-DD HH:MM)
|
|
||||||
endfunction
|
|
||||||
" Mappings {{{1
|
" Mappings {{{1
|
||||||
|
|
||||||
|
if !exists("g:Todo_txt_do_not_map")
|
||||||
|
" Sort todo by (first) context
|
||||||
|
noremap <silent><localleader>sc :call todo#HierarchicalSort('@', '', 1)<CR>
|
||||||
|
|
||||||
|
noremap <silent><localleader>scp :call todo#HierarchicalSort('@', '+', 1)<CR>
|
||||||
|
" Sort todo by (first) project
|
||||||
|
noremap <silent><localleader>sp :call todo#HierarchicalSort('+', '',1)<CR>
|
||||||
|
noremap <silent><localleader>spc :call todo#HierarchicalSort('+', '@',1)<CR>
|
||||||
|
|
||||||
" Sort tasks {{{2
|
" Sort tasks {{{2
|
||||||
" Sort tasks {{{2
|
nnoremap <script> <silent> <buffer> <LocalLeader>s :call todo#Sort()<CR>
|
||||||
if !hasmapto("<localleader>s",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>s :call TodoTxtSort()<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>s@ :sort /.\{-}\ze@/ <CR>
|
nnoremap <script> <silent> <buffer> <LocalLeader>s@ :sort /.\{-}\ze@/ <CR>
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>s@ :sort /.\{-}\ze@/ <CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>s+ :sort /.\{-}\ze+/ <CR>
|
nnoremap <script> <silent> <buffer> <LocalLeader>s+ :sort /.\{-}\ze+/ <CR>
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>s+ :sort /.\{-}\ze+/ <CR>
|
" Priorities {{{2
|
||||||
|
noremap <script> <silent> <buffer> <LocalLeader>j :call todo#PrioritizeIncrease()<CR>
|
||||||
|
noremap <script> <silent> <buffer> <LocalLeader>k :call todo#PrioritizeDecrease()<CR>
|
||||||
|
|
||||||
|
noremap <script> <silent> <buffer> <LocalLeader>a :call todo#PrioritizeAdd('A')<CR>
|
||||||
" Increment and Decrement The Priority
|
noremap <script> <silent> <buffer> <LocalLeader>b :call todo#PrioritizeAdd('B')<CR>
|
||||||
:set nf=octal,hex,alpha
|
noremap <script> <silent> <buffer> <LocalLeader>c :call todo#PrioritizeAdd('C')<CR>
|
||||||
|
|
||||||
function! TodoTxtPrioritizeIncrease()
|
|
||||||
normal! 0f)h
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtPrioritizeDecrease()
|
|
||||||
normal! 0f)h
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtPrioritizeAdd (priority)
|
|
||||||
let oldpos=getcurpos()
|
|
||||||
let line=getline('.')
|
|
||||||
if line !~ '^([A-F])'
|
|
||||||
:call TodoTxtPrioritizeAddAction(a:priority)
|
|
||||||
let oldpos[2]+=4
|
|
||||||
else
|
|
||||||
exec ':s/^([A-F])/('.a:priority.')/'
|
|
||||||
endif
|
|
||||||
call setpos('.',oldpos)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! TodoTxtPrioritizeAddAction (priority)
|
|
||||||
execute "normal! mq0i(".a:priority.") \<esc>`q"
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>j",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>j :call TodoTxtPrioritizeIncrease()<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>j",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <LocalLeader>j :call TodoTxtPrioritizeIncrease()<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>k",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>k :call TodoTxtPrioritizeDecrease()<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>k",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <LocalLeader>k :call TodoTxtPrioritizeDecrease()<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>a",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>a :call TodoTxtPrioritizeAdd('A')<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>a",'i')
|
|
||||||
inoremap <script> <silent> <buffer> <LocalLeader>a <ESC>:call TodoTxtPrioritizeAdd('A')<CR>i
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>a",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <LocalLeader>a :call TodoTxtPrioritizeAdd('A')<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>b",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>b :call TodoTxtPrioritizeAdd('B')<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>b",'i')
|
|
||||||
inoremap <script> <silent> <buffer> <LocalLeader>b <ESC>:call TodoTxtPrioritizeAdd('B')<CR>i
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>b",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <LocalLeader>b :call TodoTxtPrioritizeAdd('B')<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>c",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <LocalLeader>c :call TodoTxtPrioritizeAdd('C')<CR>
|
|
||||||
endif
|
|
||||||
if !hasmapto("<LocalLeader>c",'i')
|
|
||||||
inoremap <script> <silent> <buffer> <LocalLeader>c <ESC>:call TodoTxtPrioritizeAdd('C')<CR>i
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<LocalLeader>c",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <LocalLeader>c :call TodoTxtPrioritizeAdd('C')<CR>
|
|
||||||
|
|
||||||
" Insert date {{{2
|
" Insert date {{{2
|
||||||
" Insert date {{{2
|
|
||||||
inoremap <script> <silent> <buffer> date<Tab> <C-R>=strftime("%Y-%m-%d")<CR>
|
inoremap <script> <silent> <buffer> date<Tab> <C-R>=strftime("%Y-%m-%d")<CR>
|
||||||
inoremap <script> <silent> <buffer> date<Tab> <C-R>=strftime("%Y-%m-%d")<CR>
|
|
||||||
|
|
||||||
|
|
||||||
inoremap <script> <silent> <buffer> due: due:<C-R>=strftime("%Y-%m-%d")<CR>
|
inoremap <script> <silent> <buffer> due: due:<C-R>=strftime("%Y-%m-%d")<CR>
|
||||||
inoremap <script> <silent> <buffer> due: due:<C-R>=strftime("%Y-%m-%d")<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
inoremap <script> <silent> <buffer> DUE: DUE:<C-R>=strftime("%Y-%m-%d")<CR>
|
inoremap <script> <silent> <buffer> DUE: DUE:<C-R>=strftime("%Y-%m-%d")<CR>
|
||||||
inoremap <script> <silent> <buffer> DUE: DUE:<C-R>=strftime("%Y-%m-%d")<CR>
|
|
||||||
|
|
||||||
|
noremap <script> <silent> <buffer> <localleader>d :call todo#PrependDate()<CR>
|
||||||
if !hasmapto("<localleader>d",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <localleader>d :call TodoTxtPrependDate()<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !hasmapto("<localleader>d",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <localleader>d :call TodoTxtPrependDate()<CR>
|
|
||||||
|
|
||||||
" Mark done {{{2
|
" Mark done {{{2
|
||||||
" Mark done {{{2
|
noremap <script> <silent> <buffer> <localleader>x :call todo#ToggleMarkAsDone('')<CR>
|
||||||
if !hasmapto("<localleader>x",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <localleader>x :call TodoTxtToggleMarkAsDone()<CR>
|
" Mark done {{{2
|
||||||
|
noremap <script> <silent> <buffer> <localleader>C :call todo#ToggleMarkAsDone('Cancelled')<CR>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if !hasmapto("<localleader>x",'v')
|
|
||||||
vnoremap <script> <silent> <buffer> <localleader>x :call TodoTxtToggleMarkAsDone()<CR>
|
|
||||||
|
|
||||||
" Mark all done {{{2
|
" Mark all done {{{2
|
||||||
" Mark all done {{{2
|
noremap <script> <silent> <buffer> <localleader>X :call todo#MarkAllAsDone()<CR>
|
||||||
if !hasmapto("<localleader>X",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <localleader>X :call TodoTxtMarkAllAsDone()<CR>
|
|
||||||
|
|
||||||
" Remove completed {{{2
|
" Remove completed {{{2
|
||||||
" Remove completed {{{2
|
nnoremap <script> <silent> <buffer> <localleader>D :call todo#RemoveCompleted()<CR>
|
||||||
if !hasmapto("<localleader>D",'n')
|
|
||||||
nnoremap <script> <silent> <buffer> <localleader>D :call TodoTxtRemoveCompleted()<CR>
|
|
||||||
|
|
||||||
" Sort by due: date {{{2
|
" Sort by due: date {{{2
|
||||||
" Sort by due: date {{{2
|
nnoremap <script> <silent> <buffer> <localleader>sd :call todo#SortDue()<CR>
|
||||||
if !hasmapto("<localleader>sd".'n')
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Folding {{{1
|
" Folding {{{1
|
||||||
@@ -275,89 +99,5 @@ function! TodoFoldText()
|
|||||||
\ . ' Completed tasks '
|
\ . ' Completed tasks '
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
" Simple keyword completion on all buffers
|
|
||||||
function! TodoKeywordComplete(base)
|
|
||||||
" Search for matchs
|
|
||||||
let res = []
|
|
||||||
for bufnr in range(1,bufnr('$'))
|
|
||||||
let lines=getbufline(bufnr,1,"$")
|
|
||||||
for line in lines
|
|
||||||
if line =~ a:base
|
|
||||||
" init temporary item
|
|
||||||
let item={}
|
|
||||||
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
|
|
||||||
call add(res,item)
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endfor
|
|
||||||
return res
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Intelligent completion for projects and Contexts
|
|
||||||
fun! TodoComplete(findstart, base)
|
|
||||||
if a:findstart
|
|
||||||
let line = getline('.')
|
|
||||||
let start = col('.') - 1
|
|
||||||
while start > 0 && line[start - 1] !~ '\s'
|
|
||||||
let start -= 1
|
|
||||||
endwhile
|
|
||||||
return start
|
|
||||||
else
|
|
||||||
if a:base !~ '^+' && a:base !~ '^@'
|
|
||||||
return TodoKeywordComplete(a:base)
|
|
||||||
endif
|
|
||||||
" Opposite sign
|
|
||||||
let opp=a:base=~'+'?'@':'+'
|
|
||||||
" Search for matchs
|
|
||||||
let res = []
|
|
||||||
for bufnr in range(1,bufnr('$'))
|
|
||||||
let lines=getbufline(bufnr,1,"$")
|
|
||||||
for line in lines
|
|
||||||
if line =~ "[x\s0-9\-]*([a-Z]).* ".a:base
|
|
||||||
" init temporary item
|
|
||||||
let item={}
|
|
||||||
let item.word=substitute(line,'.*\('.a:base.'\S*\).*','\1',"")
|
|
||||||
let item.buffers=bufname(bufnr)
|
|
||||||
let item.related=substitute(line,'.*\s\('.opp.'\S\S*\).*','\1',"")
|
|
||||||
call add(res,item)
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
endfor
|
|
||||||
call sort(res)
|
|
||||||
" Here all results are sorted in res, but we need to merge them
|
|
||||||
let ret=[]
|
|
||||||
let curitem={}
|
|
||||||
let curitem.word=res[0].word
|
|
||||||
let curitem.related=[]
|
|
||||||
let curitem.buffers=[]
|
|
||||||
for it in res
|
|
||||||
if curitem.word==it.word
|
|
||||||
" Merge results
|
|
||||||
if index(curitem.related,it.related) <0
|
|
||||||
call add(curitem.related,it.related)
|
|
||||||
endif
|
|
||||||
if index(curitem.buffers,it.buffers) <0
|
|
||||||
call add(curitem.buffers,it.buffers)
|
|
||||||
endif
|
|
||||||
else
|
|
||||||
" Create the definitive item
|
|
||||||
let resitem={}
|
|
||||||
let resitem.word=curitem.word
|
|
||||||
let resitem.info=opp=='+'?"Projects":"Contexts"
|
|
||||||
let resitem.info.=": ".join(curitem.related, ", ")
|
|
||||||
\."\nBuffers: ".join(curitem.buffers, ", ")
|
|
||||||
call add(ret,resitem)
|
|
||||||
" Init new item from it
|
|
||||||
let curitem.word=it.word
|
|
||||||
let curitem.related=[it.related]
|
|
||||||
let curitem.buffers=[it.buffers]
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
return ret
|
|
||||||
endif
|
|
||||||
endfun
|
|
||||||
" Restore context {{{1
|
" Restore context {{{1
|
||||||
let &cpo = s:save_cpo
|
let &cpo = s:save_cpo
|
||||||
let &cpo = s:save_cpo
|
|
||||||
" Modeline {{{1
|
|
||||||
|
|||||||
@@ -1,133 +0,0 @@
|
|||||||
" File: todo.txt.vim
|
|
||||||
" Description: Todo.txt sorting plugin
|
|
||||||
" Author: David Beniamine <david@beniamine.net>
|
|
||||||
" Licence: Vim licence
|
|
||||||
" Website: http://github.com/dbeniamine/todo.txt.vim
|
|
||||||
" Version: 0.7
|
|
||||||
" vim: ts=4 sw=4 :help tw=78 cc=80
|
|
||||||
|
|
||||||
" These two variables are parameters for the successive calls the vim sort
|
|
||||||
" '' 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
|
|
||||||
if (! exists("g:Todo_txt_third_level_sort_mode"))
|
|
||||||
let g:Todo_txt_third_level_sort_mode='i'
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Sort todo by (first) context
|
|
||||||
if !hasmapto("<localleader>sc",'n')
|
|
||||||
noremap <localleader>sc :call Todo_txt_HierarchicalSort('@', '', 1)<CR>
|
|
||||||
endif
|
|
||||||
if !hasmapto("<localleader>scp",'n')
|
|
||||||
noremap <localleader>scp :call Todo_txt_HierarchicalSort('@', '+', 1)<CR>
|
|
||||||
endif
|
|
||||||
" Sort todo by (first) project
|
|
||||||
if !hasmapto("<localleader>sp",'n')
|
|
||||||
noremap <localleader>sp :call Todo_txt_HierarchicalSort('+', '',1)<CR>
|
|
||||||
endif
|
|
||||||
if !hasmapto("<localleader>spc",'n')
|
|
||||||
noremap <localleader>spc :call Todo_txt_HierarchicalSort('+', '@',0)<CR>
|
|
||||||
endif
|
|
||||||
|
|
||||||
" This is a Hierarchical sort designed for todo.txt todo lists, however it
|
|
||||||
" might be used for other files types
|
|
||||||
" 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. At the second level, the same kind of sort is done based on
|
|
||||||
" a:symbolsub, is a:symbol==' ', the second sort doesn't occurs
|
|
||||||
" 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 last level of sort is done directly on the line, so according to
|
|
||||||
" todo.txt syntax, it means by priority. This sort is done if and only if the
|
|
||||||
" las argument is not 0
|
|
||||||
function! Todo_txt_HierarchicalSort(symbol, symbolsub, dolastsort)
|
|
||||||
if v:statusmsg =~ '--No lines in buffer--'
|
|
||||||
"Empty buffer do nothing
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
"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:sortmodesub=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_second_level_sort_mode)
|
|
||||||
let l:sortmodefinal=Todo_txt_InsertSpaceIfNeeded(g:Todo_txt_third_level_sort_mode)
|
|
||||||
|
|
||||||
" Count the number of lines
|
|
||||||
let l:position= getpos(".")
|
|
||||||
execute "silent normal g\<c-g>"
|
|
||||||
let l:linecount=str2nr(split(v:statusmsg)[7])
|
|
||||||
|
|
||||||
" Get all the groups names
|
|
||||||
let l:groups=GetGroups(a:symbol,0,l:linecount)
|
|
||||||
|
|
||||||
" Sort by groups
|
|
||||||
execute 'sort'.l:sortmode.' /.\{-}\ze'.a:symbol.'/'
|
|
||||||
for l:g in l:groups
|
|
||||||
" Find the beginning of the group
|
|
||||||
execute '/'.a:symbol.l:g.'.*$'
|
|
||||||
let l:groupBegin=getpos(".")[1]
|
|
||||||
" Find the end of the group
|
|
||||||
silent normal N
|
|
||||||
let l:groupEnd=getpos(".")[1]
|
|
||||||
|
|
||||||
" I'm too lazy to sort one groups of one line
|
|
||||||
if(l:groupEnd==l:groupBegin)
|
|
||||||
continue
|
|
||||||
endif
|
|
||||||
if( a:symbolsub!='')
|
|
||||||
" Sort by subgroups
|
|
||||||
let l:subgroups=GetGroups(a:symbolsub,l:groupBegin,l:groupEnd)
|
|
||||||
" Go before the first line of the group
|
|
||||||
" Sort the group using the second symbol
|
|
||||||
for l:sg in l:subgroups
|
|
||||||
" Find the beginning of the subgroup
|
|
||||||
execute '/'.a:symbol.l:g.'.*'.a:symbolsub.l:sg.'.*$\|'.a:symbolsub.l:sg.'.*'.a:symbol.l:g.'.*$'
|
|
||||||
let l:subgroupBegin=getpos(".")[1]
|
|
||||||
" Find the end of the subgroup
|
|
||||||
silent normal N
|
|
||||||
let l:subgroupEnd=getpos(".")[1]
|
|
||||||
" Sort by priority
|
|
||||||
if a:dolastsort
|
|
||||||
execute l:subgroupBegin.','.l:subgroupEnd.'sort'.l:sortmodefinal
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
else
|
|
||||||
" Sort by priority
|
|
||||||
if a:dolastsort
|
|
||||||
execute l:groupBegin.','.l:groupEnd.'sort'.l:sortmodefinal
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
" Restore the cursor position
|
|
||||||
call setpos('.', position)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Returns the list of groups starting by a:symbol between lines a:begin and
|
|
||||||
" a:end
|
|
||||||
function! GetGroups(symbol,begin, end)
|
|
||||||
let l:curline=a:begin
|
|
||||||
let l:groups=[]
|
|
||||||
while l:curline <= a:end
|
|
||||||
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
|
|
||||||
return l:groups
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Insert a space if needed (the first char isn't '!' or ' ') in front of
|
|
||||||
" sort parameters
|
|
||||||
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
|
|
||||||
11
syntax/python/dateregex/dateregex/__init__.py
Normal file
11
syntax/python/dateregex/dateregex/__init__.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# File: __init__.py
|
||||||
|
# Author: Guilherme Victal <guilherme at victal.eti.br>
|
||||||
|
# Description: Dateregex library entry point
|
||||||
|
# License: Vim license
|
||||||
|
# Website: http://github.com/freitass/todo.txt-vim
|
||||||
|
# Version: 0.1
|
||||||
|
|
||||||
|
from after import regex_date_after
|
||||||
|
from before import regex_date_before
|
||||||
95
syntax/python/dateregex/dateregex/after.py
Normal file
95
syntax/python/dateregex/dateregex/after.py
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# File: after.py
|
||||||
|
# Author: Guilherme Victal <guilherme at victal.eti.br>
|
||||||
|
# Description: Generates regexes after a certain date
|
||||||
|
# License: Vim license
|
||||||
|
# Website: http://github.com/freitass/todo.txt-vim
|
||||||
|
# Version: 0.1
|
||||||
|
|
||||||
|
from datetime import date, timedelta, MAXYEAR
|
||||||
|
|
||||||
|
|
||||||
|
def _year_regex_after(year):
|
||||||
|
if int(year) > MAXYEAR:
|
||||||
|
return None
|
||||||
|
|
||||||
|
year_regex = r'(\d+\d{%s}' % len(year)
|
||||||
|
for idx, digit in enumerate(year):
|
||||||
|
if digit != '9':
|
||||||
|
regex = '|' + year[0:idx]
|
||||||
|
regex += '9' if digit == '8' else '[%s-9]' % str(int(digit) + 1)
|
||||||
|
if idx < len(year) - 1:
|
||||||
|
regex += '\d{%s}' % (len(year) - (idx + 1))
|
||||||
|
year_regex += regex
|
||||||
|
|
||||||
|
year_regex += ')'
|
||||||
|
return '-'.join((year_regex, r'\d{2}', r'\d{2}'))
|
||||||
|
|
||||||
|
|
||||||
|
def _month_regex_after(year, month):
|
||||||
|
if month == '12':
|
||||||
|
return None
|
||||||
|
|
||||||
|
digit1, digit2 = month
|
||||||
|
if digit1 == '1':
|
||||||
|
month_regex = r'12' if month == '11' else r'1[12]'
|
||||||
|
else:
|
||||||
|
month_regex = r'1[0-2]'
|
||||||
|
if digit2 != '9':
|
||||||
|
if digit2 == '8':
|
||||||
|
month_regex = r'(' + month_regex + r'|09)'
|
||||||
|
else:
|
||||||
|
month_regex = r'(' + month_regex + r'|0[%s-9])'
|
||||||
|
month_regex = month_regex % str(int(digit2) + 1)
|
||||||
|
return '-'.join((year, month_regex, r'\d{2}'))
|
||||||
|
|
||||||
|
def _day_regex_after(year, month, day):
|
||||||
|
last_month_day = str((date(int(year), (int(month) + 1) % 12, 1) + - date.resolution).day)
|
||||||
|
if day == last_month_day:
|
||||||
|
return None
|
||||||
|
day_regex = r'('
|
||||||
|
digit1, digit2 = day
|
||||||
|
last_digit1, last_digit2 = last_month_day
|
||||||
|
if digit1 == last_digit1:
|
||||||
|
day_regex = last_month_day if int(digit2) == int(last_digit2) - 1 else last_digit1 + r'[%s-%s]' % (str(int(digit2) + 1), last_digit2)
|
||||||
|
else:
|
||||||
|
day_regex = r'('
|
||||||
|
day_regex += last_digit1 if int(digit1) == int(last_digit1) - 1 else r'[%s-%s]' % (str(int(digit1) + 1), last_digit1)
|
||||||
|
day_regex +=r'\d'
|
||||||
|
if digit2 < '9':
|
||||||
|
day_regex += '|' + digit1
|
||||||
|
day_regex += '9' if digit2 == '8' else r'[%s-9]' % str(int(digit2) + 1)
|
||||||
|
|
||||||
|
day_regex += ')'
|
||||||
|
return '-'.join((year, month, day_regex))
|
||||||
|
|
||||||
|
|
||||||
|
def regex_date_after(given_date):
|
||||||
|
year, month, day = given_date.isoformat().split('-')
|
||||||
|
|
||||||
|
year_regex = _year_regex_after(year)
|
||||||
|
month_regex = _month_regex_after(year, month)
|
||||||
|
day_regex = _day_regex_after(year, month, day)
|
||||||
|
|
||||||
|
date_regex = '(' + year_regex if year_regex else '('
|
||||||
|
date_regex += ('|' + month_regex) if month_regex else ''
|
||||||
|
date_regex += ('|' + day_regex) if day_regex else ''
|
||||||
|
date_regex += ')'
|
||||||
|
return date_regex
|
||||||
|
|
||||||
|
|
||||||
|
def __main():
|
||||||
|
import re
|
||||||
|
date_regex = regex_date_after(date(1999,12,31))
|
||||||
|
print(date_regex)
|
||||||
|
pattern = re.compile(date_regex)
|
||||||
|
|
||||||
|
|
||||||
|
d = date.today() + date.resolution
|
||||||
|
assert pattern.match(date.strftime(d, '%Y-%m-%d')) is not None
|
||||||
|
print(date.strftime(d, '%Y-%m-%d') + ' is okay')
|
||||||
|
d += date.resolution
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
__main()
|
||||||
79
syntax/python/dateregex/dateregex/before.py
Normal file
79
syntax/python/dateregex/dateregex/before.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# File: before.py
|
||||||
|
# Author: Guilherme Victal <guilherme at victal.eti.br>
|
||||||
|
# Description: Generates regexes before a certain date
|
||||||
|
# License: Vim license
|
||||||
|
# Website: http://github.com/freitass/todo.txt-vim
|
||||||
|
# Version: 0.1
|
||||||
|
|
||||||
|
from datetime import date, timedelta, MINYEAR
|
||||||
|
|
||||||
|
def _year_regex_before(year):
|
||||||
|
if int(year) <= MINYEAR:
|
||||||
|
return None
|
||||||
|
year_regex = r'('
|
||||||
|
year_regex += r'\d{1,%s}' % str(len(year) - 1) if len(year) > 1 else ''
|
||||||
|
for idx, digit in enumerate(year):
|
||||||
|
if digit != '0':
|
||||||
|
regex = '|' + year[0:idx]
|
||||||
|
regex += '0' if digit == '1' else '[0-%s]' % str(int(digit) - 1)
|
||||||
|
if idx < len(year) - 1:
|
||||||
|
regex += '\d{%s}' % (len(year) - (idx + 1))
|
||||||
|
year_regex += regex
|
||||||
|
|
||||||
|
year_regex += ')'
|
||||||
|
return '-'.join((year_regex, r'\d{2}', r'\d{2}'))
|
||||||
|
|
||||||
|
def _month_regex_before(year, month):
|
||||||
|
if month == '01':
|
||||||
|
return None
|
||||||
|
|
||||||
|
digit1, digit2 = month
|
||||||
|
if digit1 == '0':
|
||||||
|
month_regex = '01' if month == '02' else r'0[1-%s]' % str(int(digit2) - 1)
|
||||||
|
elif month == '10':
|
||||||
|
month_regex = r'0\d'
|
||||||
|
elif month == '11':
|
||||||
|
month_regex = r'(0\d|10)'
|
||||||
|
else:
|
||||||
|
month_regex = r'(0\d|1[01])'
|
||||||
|
|
||||||
|
return '-'.join((year, month_regex, r'\d{2}'))
|
||||||
|
|
||||||
|
def _day_regex_before(year, month, day):
|
||||||
|
if day == '01':
|
||||||
|
return None
|
||||||
|
last_month_day = str((date(int(year), (int(month) + 1) % 12, 1) + - date.resolution).day)
|
||||||
|
last_digit1, last_digit2 = last_month_day
|
||||||
|
|
||||||
|
digit1, digit2 = day
|
||||||
|
if digit1 == '0':
|
||||||
|
day_regex = '01' if day == '02' else r'0[1-%s]' % str(int(digit2) - 1)
|
||||||
|
else:
|
||||||
|
day_regex = r'('
|
||||||
|
day_regex += '0' if digit1 == '1' else r'[0-%s]' % str(int(digit1) - 1)
|
||||||
|
day_regex += r'\d'
|
||||||
|
if digit2 != '0':
|
||||||
|
day_regex += '|'
|
||||||
|
day_regex += digit1
|
||||||
|
day_regex += '0' if digit2 == '1' else r'[0-%s]' % str(int(digit2) - 1)
|
||||||
|
day_regex += ')'
|
||||||
|
|
||||||
|
return '-'.join((year, month, day_regex))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def regex_date_before(given_date):
|
||||||
|
year, month, day = given_date.isoformat().split('-')
|
||||||
|
|
||||||
|
year_regex = _year_regex_before(year)
|
||||||
|
month_regex = _month_regex_before(year, month)
|
||||||
|
day_regex = _day_regex_before(year, month, day)
|
||||||
|
|
||||||
|
date_regex = '(' + year_regex if year_regex else '('
|
||||||
|
date_regex += ('|' + month_regex) if month_regex else ''
|
||||||
|
date_regex += ('|' + day_regex) if day_regex else ''
|
||||||
|
date_regex += ')'
|
||||||
|
return date_regex
|
||||||
31
syntax/python/todo.py
Normal file
31
syntax/python/todo.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python2
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# File: todo.py
|
||||||
|
# Description: Todo.txt overdue date syntax script
|
||||||
|
# License: Vim license
|
||||||
|
# Website: http://github.com/freitass/todo.txt-vim
|
||||||
|
# Version: 0.1
|
||||||
|
|
||||||
|
import vim
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
dateregex_dir = os.path.join(vim.eval('s:script_dir'), 'dateregex')
|
||||||
|
if os.path.isdir(dateregex_dir):
|
||||||
|
sys.path.insert(0, dateregex_dir)
|
||||||
|
|
||||||
|
def add_due_date_syntax_highlight():
|
||||||
|
try:
|
||||||
|
from dateregex import regex_date_before
|
||||||
|
except ImportError:
|
||||||
|
print("dateregex module not found. Overdue dates won't be highlighted")
|
||||||
|
return
|
||||||
|
|
||||||
|
regex = regex_date_before(date.today())
|
||||||
|
regex = r'(^|<)due:%s(>|$)' % regex
|
||||||
|
|
||||||
|
vim.command("syntax match OverDueDate '\\v%s'" % regex)
|
||||||
|
vim.command("highlight default link OverDueDate Error")
|
||||||
|
|
||||||
|
add_due_date_syntax_highlight()
|
||||||
@@ -3,41 +3,41 @@
|
|||||||
" Author: David Beniamine <David@Beniamine.net>,Leandro Freitas <freitass@gmail.com>
|
" Author: David Beniamine <David@Beniamine.net>,Leandro Freitas <freitass@gmail.com>
|
||||||
" License: Vim license
|
" License: Vim license
|
||||||
" Website: http://github.com/dbeniamine/todo.txt-vim
|
" Website: http://github.com/dbeniamine/todo.txt-vim
|
||||||
" Version: 0.7
|
" vim: ts=4 sw=4 :help tw=78 cc=80
|
||||||
|
|
||||||
if exists("b:current_syntax")
|
if exists("b:current_syntax")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syntax match TodoDone '^[xX]\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoDone '^[xX]\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityA '^([aA])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityA '^([aA])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityB '^([bB])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityB '^([bB])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityC '^([cC])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityC '^([cC])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityD '^([dD])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityD '^([dD])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityE '^([eE])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityE '^([eE])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityF '^([fF])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityF '^([fF])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityG '^([gG])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityG '^([gG])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityH '^([hH])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityH '^([hH])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityI '^([iI])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityI '^([iI])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityJ '^([jJ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityJ '^([jJ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityK '^([kK])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityK '^([kK])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityL '^([lL])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityL '^([lL])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityM '^([mM])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityM '^([mM])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityN '^([nN])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityN '^([nN])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityO '^([oO])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityO '^([oO])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityP '^([pP])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityP '^([pP])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityQ '^([qQ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityQ '^([qQ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityR '^([rR])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityR '^([rR])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityS '^([sS])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityS '^([sS])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityT '^([tT])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityT '^([tT])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityU '^([uU])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityU '^([uU])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityV '^([vV])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityV '^([vV])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityW '^([wW])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityW '^([wW])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityX '^([xX])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityX '^([xX])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityY '^([yY])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityY '^([yY])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoPriorityZ '^([zZ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
syntax match TodoPriorityZ '^([zZ])\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,OverDueDate
|
||||||
syntax match TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE
|
syntax match TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE
|
||||||
syntax match TodoKey '\S*:\S*' contains=TodoDate
|
syntax match TodoKey '\S*\S:\S\S*' contains=TodoDate
|
||||||
syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE
|
syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE
|
||||||
syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE
|
syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE
|
||||||
|
|
||||||
@@ -51,4 +51,12 @@ highlight default link TodoDate PreProc
|
|||||||
highlight default link TodoProject Special
|
highlight default link TodoProject Special
|
||||||
highlight default link TodoContext Special
|
highlight default link TodoContext Special
|
||||||
|
|
||||||
|
if has('python')
|
||||||
|
let b:curdir = expand('<sfile>:p:h')
|
||||||
|
let s:script_dir = b:curdir . "/python/"
|
||||||
|
execute "pyfile " . s:script_dir. "todo.py"
|
||||||
|
else
|
||||||
|
echom "Your version of vim has no python support. Overdue dates won't be highlighted"
|
||||||
|
endif
|
||||||
|
|
||||||
let b:current_syntax = "todo"
|
let b:current_syntax = "todo"
|
||||||
|
|||||||
28
test/tc_date.todo.txt
Normal file
28
test/tc_date.todo.txt
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# lorem_ipsum
|
||||||
|
example task
|
||||||
|
# end_lorem_ipsum
|
||||||
|
|
||||||
|
# date_after_priority
|
||||||
|
(A) Call Mom
|
||||||
|
# end_date_after_priority
|
||||||
|
|
||||||
|
# date_after_priority_visual
|
||||||
|
(A) Call Mom
|
||||||
|
(B) Call Dad
|
||||||
|
# end_date_after_priority_visual
|
||||||
|
|
||||||
|
# existing_date_no_priority
|
||||||
|
2014-05-06 example task
|
||||||
|
# end_existing_date_no_priority
|
||||||
|
|
||||||
|
# existing_date_after_priority
|
||||||
|
(A) 2014-05-06 Call Mom
|
||||||
|
# end_existing_date_after_priority
|
||||||
|
|
||||||
|
# existing_date_do_nothing
|
||||||
|
2014-05-06 example task
|
||||||
|
# end_existing_date_do_nothing
|
||||||
|
|
||||||
|
# non_existing_date_do_nothing
|
||||||
|
new todo line
|
||||||
|
# end_non_existing_date_do_nothing
|
||||||
84
test/tc_date.vim
Normal file
84
test/tc_date.vim
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:context = todo#txt#__context__()
|
||||||
|
let s:context['data'] = s:here . '/tc_date.todo.txt'
|
||||||
|
let s:tc = unittest#testcase#new('Date', s:context)
|
||||||
|
|
||||||
|
let s:TODAY = strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
function! s:tc.test_current_date()
|
||||||
|
call self.assert_equal(s:TODAY, self.call('s:get_current_date', []))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:DATE_INSERTED = [
|
||||||
|
\ s:TODAY . ' example task',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:DATE_INSERTED_AFTER_PRIORITY = [
|
||||||
|
\ '(A) ' . s:TODAY . ' Call Mom',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:DATE_INSERTED_AFTER_PRIORITY_VISUAL = [
|
||||||
|
\ '(A) ' . s:TODAY . ' Call Mom',
|
||||||
|
\ '(B) ' . s:TODAY . ' Call Dad',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:DATE_INSERTED_DO_NOTHING = [
|
||||||
|
\ '2014-05-06 example task',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:NON_EXISTING_DATE_INSERTED_DO_NOTHING = [
|
||||||
|
\ s:TODAY . ' new todo line',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_insert_date_normal_mode()
|
||||||
|
call self.data.goto('lorem_ipsum')
|
||||||
|
call todo#txt#replace_date()
|
||||||
|
call self.assert_equal(s:DATE_INSERTED, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_date_insert_mode()
|
||||||
|
call self.data.goto('lorem_ipsum')
|
||||||
|
execute 'normal idate '
|
||||||
|
call self.assert_equal(s:DATE_INSERTED, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_date_visual_mode()
|
||||||
|
call self.data.visual_execute('call todo#txt#replace_date()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:DATE_INSERTED, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_date_after_priority_normal_mode()
|
||||||
|
call self.data.execute('call todo#txt#replace_date()', 'date_after_priority')
|
||||||
|
call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY, self.data.get('date_after_priority'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_date_after_priority_visual_mode()
|
||||||
|
call self.data.visual_execute('call todo#txt#replace_date()', 'date_after_priority_visual')
|
||||||
|
call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY_VISUAL, self.data.get('date_after_priority_visual'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_with_existing_date()
|
||||||
|
call self.data.execute('call todo#txt#replace_date()', 'existing_date_no_priority')
|
||||||
|
call self.assert_equal(s:DATE_INSERTED, self.data.get('existing_date_no_priority'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_with_existing_date_and_priority()
|
||||||
|
call self.data.execute('call todo#txt#replace_date()', 'existing_date_after_priority')
|
||||||
|
call self.assert_equal(s:DATE_INSERTED_AFTER_PRIORITY, self.data.get('existing_date_after_priority'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_with_existing_date_and_priority()
|
||||||
|
let g:todo_existing_date = 'n'
|
||||||
|
call self.data.execute('call todo#txt#replace_date()', 'existing_date_do_nothing')
|
||||||
|
call self.assert_equal(s:DATE_INSERTED_DO_NOTHING, self.data.get('existing_date_do_nothing'))
|
||||||
|
unlet g:todo_existing_date
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_insert_with_existing_date_and_priority()
|
||||||
|
let g:todo_existing_date = 'n'
|
||||||
|
call self.data.execute('call todo#txt#replace_date()', 'non_existing_date_do_nothing')
|
||||||
|
call self.assert_equal(s:NON_EXISTING_DATE_INSERTED_DO_NOTHING, self.data.get('non_existing_date_do_nothing'))
|
||||||
|
unlet g:todo_existing_date
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
5
test/tc_mark_as_done.todo.txt
Normal file
5
test/tc_mark_as_done.todo.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# lorem_ipsum
|
||||||
|
first task to be marked as done
|
||||||
|
second task to be marked as done
|
||||||
|
2015-05-20 third task to be marked as done
|
||||||
|
# end_lorem_ipsum
|
||||||
36
test/tc_mark_as_done.vim
Normal file
36
test/tc_mark_as_done.vim
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:context = todo#txt#__context__()
|
||||||
|
let s:context['data'] = s:here . '/tc_mark_as_done.todo.txt'
|
||||||
|
let s:tc = unittest#testcase#new('Mark As Done', s:context)
|
||||||
|
|
||||||
|
let s:TODAY = strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
let s:FIRST_TASK_DONE = [
|
||||||
|
\ 'x ' . s:TODAY . ' first task to be marked as done',
|
||||||
|
\ 'second task to be marked as done',
|
||||||
|
\ '2015-05-20 third task to be marked as done',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:ALL_TASKS_DONE = [
|
||||||
|
\ 'x ' . s:TODAY . ' first task to be marked as done',
|
||||||
|
\ 'x ' . s:TODAY . ' second task to be marked as done',
|
||||||
|
\ 'x ' . s:TODAY . ' 2015-05-20 third task to be marked as done',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_mark_as_done()
|
||||||
|
call self.data.goto('lorem_ipsum')
|
||||||
|
call todo#txt#mark_as_done()
|
||||||
|
call self.assert_equal(s:FIRST_TASK_DONE, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_mark_range_as_done()
|
||||||
|
call self.data.execute('call todo#txt#mark_as_done()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:ALL_TASKS_DONE, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_mark_selection_as_done()
|
||||||
|
call self.data.visual_execute('call todo#txt#mark_as_done()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:ALL_TASKS_DONE, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
7
test/tc_priority.todo.txt
Normal file
7
test/tc_priority.todo.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# insert_priority
|
||||||
|
example task
|
||||||
|
# end_insert_priority
|
||||||
|
|
||||||
|
# replace_priority
|
||||||
|
(A) example task
|
||||||
|
# end_replace_priority
|
||||||
28
test/tc_priority.vim
Normal file
28
test/tc_priority.vim
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:context = todo#txt#__context__()
|
||||||
|
let s:context['data'] = s:here . '/tc_priority.todo.txt'
|
||||||
|
let s:tc = unittest#testcase#new('Priority', s:context)
|
||||||
|
|
||||||
|
let s:TODAY = strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
let s:PRIORITY_INSERTED = [
|
||||||
|
\ '(A) example task',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:PRIORITY_REPLACED = [
|
||||||
|
\ '(C) example task',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_insert_priority()
|
||||||
|
call self.data.goto('insert_priority')
|
||||||
|
call todo#txt#prioritize_add('A')
|
||||||
|
call self.assert_equal(s:PRIORITY_INSERTED, self.data.get('insert_priority'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_replace_priority()
|
||||||
|
call self.data.goto('replace_priority')
|
||||||
|
call todo#txt#prioritize_add('C')
|
||||||
|
call self.assert_equal(s:PRIORITY_REPLACED, self.data.get('replace_priority'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
5
test/tc_sort_context.todo.txt
Normal file
5
test/tc_sort_context.todo.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# lorem_ipsum
|
||||||
|
(B) Linear regression Rnet=Qh@Qle. @cons_emp_model
|
||||||
|
(B) Review key questions. @benchmarking
|
||||||
|
(A) simple model first @cons_emp_model
|
||||||
|
# end_lorem_ipsum
|
||||||
18
test/tc_sort_context.vim
Normal file
18
test/tc_sort_context.vim
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:tc = unittest#testcase#new('Sort Context',
|
||||||
|
\ { 'data': s:here . '/tc_sort_context.todo.txt' })
|
||||||
|
|
||||||
|
let s:LEADER = mapleader
|
||||||
|
|
||||||
|
let s:SORTED_TASKS = [
|
||||||
|
\ '(B) Review key questions. @benchmarking',
|
||||||
|
\ '(B) Linear regression Rnet=Qh@Qle. @cons_emp_model',
|
||||||
|
\ '(A) simple model first @cons_emp_model',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_sort_by_context()
|
||||||
|
call self.data.visual_execute('call todo#txt#sort_by_context()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
12
test/tc_sort_date.todo.txt
Normal file
12
test/tc_sort_date.todo.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# lorem_ipsum
|
||||||
|
(B) 2013-03-15 2015-03-17
|
||||||
|
(B) 2012-04-16 2015-04-16
|
||||||
|
(A) 2013-03-16 2013-03-10
|
||||||
|
# end_lorem_ipsum
|
||||||
|
# task_with_no_date
|
||||||
|
2013-03-15 task with date
|
||||||
|
task with no date
|
||||||
|
2013-03-15 task with date
|
||||||
|
2013-03-15 task with date
|
||||||
|
task with no date
|
||||||
|
# end_task_with_no_date
|
||||||
31
test/tc_sort_date.vim
Normal file
31
test/tc_sort_date.vim
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:tc = unittest#testcase#new('Sort Date',
|
||||||
|
\ { 'data': s:here . '/tc_sort_date.todo.txt' })
|
||||||
|
|
||||||
|
let s:LEADER = mapleader
|
||||||
|
|
||||||
|
let s:SORTED_TASKS = [
|
||||||
|
\ '(B) 2012-04-16 2015-04-16',
|
||||||
|
\ '(B) 2013-03-15 2015-03-17',
|
||||||
|
\ '(A) 2013-03-16 2013-03-10',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
let s:SORTED_TASKS_WITH_NO_DATE = [
|
||||||
|
\ '2013-03-15 task with date',
|
||||||
|
\ '2013-03-15 task with date',
|
||||||
|
\ '2013-03-15 task with date',
|
||||||
|
\ 'task with no date',
|
||||||
|
\ 'task with no date',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_sort_by_date()
|
||||||
|
call self.data.visual_execute('call todo#txt#sort_by_date()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:tc.test_sort_by_date_with_tasks_without_date()
|
||||||
|
call self.data.visual_execute('call todo#txt#sort_by_date()', 'task_with_no_date')
|
||||||
|
call self.assert_equal(s:SORTED_TASKS_WITH_NO_DATE, self.data.get('task_with_no_date'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
5
test/tc_sort_project.todo.txt
Normal file
5
test/tc_sort_project.todo.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# lorem_ipsum
|
||||||
|
(B) Linear regression Rnet=Qh+Qle. +cons_emp_model
|
||||||
|
(B) Review key questions. +benchmarking
|
||||||
|
(A) simple model first +cons_emp_model
|
||||||
|
# end_lorem_ipsum
|
||||||
18
test/tc_sort_project.vim
Normal file
18
test/tc_sort_project.vim
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
let s:here = expand('<sfile>:p:h')
|
||||||
|
let s:tc = unittest#testcase#new('Sort Project',
|
||||||
|
\ { 'data': s:here . '/tc_sort_project.todo.txt' })
|
||||||
|
|
||||||
|
let s:LEADER = mapleader
|
||||||
|
|
||||||
|
let s:SORTED_TASKS = [
|
||||||
|
\ '(B) Review key questions. +benchmarking',
|
||||||
|
\ '(B) Linear regression Rnet=Qh+Qle. +cons_emp_model',
|
||||||
|
\ '(A) simple model first +cons_emp_model',
|
||||||
|
\ ]
|
||||||
|
|
||||||
|
function! s:tc.test_sort_by_project()
|
||||||
|
call self.data.visual_execute('call todo#txt#sort_by_project()', 'lorem_ipsum')
|
||||||
|
call self.assert_equal(s:SORTED_TASKS, self.data.get('lorem_ipsum'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
unlet s:tc
|
||||||
Reference in New Issue
Block a user