Merge branch 'master' of https://github.com/dbeniamine/todo.txt-vim
This commit is contained in:
@@ -95,10 +95,10 @@ function! todo#UnMarkAsDone(status)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! todo#MarkAsDone(status)
|
function! todo#MarkAsDone(status)
|
||||||
|
exec ':s/\C^(\([A-Z]\))\(.*\)/\2 pri:\1/e'
|
||||||
if a:status!=''
|
if a:status!=''
|
||||||
exec 'normal! I'.a:status.' '
|
exec 'normal! I'.a:status.' '
|
||||||
endif
|
endif
|
||||||
exec ':s/\C^(\([A-Z]\))\(.*\)/\2 pri:\1/e'
|
|
||||||
call todo#PrependDate()
|
call todo#PrependDate()
|
||||||
if (getline(".") =~ '^ ')
|
if (getline(".") =~ '^ ')
|
||||||
normal! gIx
|
normal! gIx
|
||||||
@@ -708,7 +708,7 @@ fun! todo#Complete(findstart, base)
|
|||||||
for it in res
|
for it in res
|
||||||
if curitem.word==it.word
|
if curitem.word==it.word
|
||||||
" Merge results
|
" Merge results
|
||||||
if has_key(curitem, "related") && has_key(it, "related") && index(curitem.related,it.related) <0
|
if has_key(it, "related") && index(curitem.related,it.related) <0
|
||||||
call add(curitem.related,it.related)
|
call add(curitem.related,it.related)
|
||||||
endif
|
endif
|
||||||
if index(curitem.buffers,it.buffers) <0
|
if index(curitem.buffers,it.buffers) <0
|
||||||
|
|||||||
@@ -1,123 +0,0 @@
|
|||||||
" 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-Z]) \)\?\d\{2,4\}-\d\{2\}-\d\{2\} ') &&
|
|
||||||
\ exists('g:todo_existing_date') && g:todo_existing_date == 'n'
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
execute 's/^\(([A-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-Z]) \)\?/(' . a:priority . ') /'
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Modeline {{{1
|
|
||||||
" vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab foldmethod=marker
|
|
||||||
@@ -457,8 +457,8 @@ Execute (2017-10-01 should NOT match with reference 2017-10-01):
|
|||||||
Given todo (Tasks):
|
Given todo (Tasks):
|
||||||
x 2017-09-18 Complete task
|
x 2017-09-18 Complete task
|
||||||
x 2017-09-18 2017-09-01 Completed task with a created date
|
x 2017-09-18 2017-09-01 Completed task with a created date
|
||||||
x 2017-09-18 (A) Completed priority task
|
x 2017-09-18 Completed priority pri:A task
|
||||||
x 2017-09-18 2017-09-01 (A) Completed priority task with a created date
|
x 2017-09-18 2017-09-01 Completed priority task with a created date pri:A
|
||||||
X 2017-09-18 Not to be confused for a complete task
|
X 2017-09-18 Not to be confused for a complete task
|
||||||
Active task
|
Active task
|
||||||
2017-09-01 Active task with a created date
|
2017-09-01 Active task with a created date
|
||||||
@@ -475,7 +475,7 @@ Expect todo (Toggled tasks with today as **TODAY**):
|
|||||||
Complete task
|
Complete task
|
||||||
2017-09-01 Completed task with a created date
|
2017-09-01 Completed task with a created date
|
||||||
(A) Completed priority task
|
(A) Completed priority task
|
||||||
2017-09-01 (A) Completed priority task with a created date
|
(A) 2017-09-01 Completed priority task with a created date
|
||||||
x **TODAY** X 2017-09-18 Not to be confused for a complete task
|
x **TODAY** X 2017-09-18 Not to be confused for a complete task
|
||||||
x **TODAY** Active task
|
x **TODAY** Active task
|
||||||
x **TODAY** 2017-09-01 Active task with a created date
|
x **TODAY** 2017-09-01 Active task with a created date
|
||||||
@@ -493,7 +493,7 @@ Expect todo (Tasks, completed on today):
|
|||||||
x **TODAY** Complete task
|
x **TODAY** Complete task
|
||||||
x **TODAY** 2017-09-01 Completed task with a created date
|
x **TODAY** 2017-09-01 Completed task with a created date
|
||||||
x **TODAY** Completed priority task pri:A
|
x **TODAY** Completed priority task pri:A
|
||||||
x **TODAY** 2017-09-01 (A) Completed priority task with a created date
|
x **TODAY** 2017-09-01 Completed priority task with a created date pri:A
|
||||||
X 2017-09-18 Not to be confused for a complete task
|
X 2017-09-18 Not to be confused for a complete task
|
||||||
Active task
|
Active task
|
||||||
2017-09-01 Active task with a created date
|
2017-09-01 Active task with a created date
|
||||||
@@ -509,6 +509,63 @@ Expect todo (Tasks, completed on today):
|
|||||||
Execute (Check todo#ToggleMarkAsDone for exceptions):
|
Execute (Check todo#ToggleMarkAsDone for exceptions):
|
||||||
:%call todo#ToggleMarkAsDone('')
|
:%call todo#ToggleMarkAsDone('')
|
||||||
|
|
||||||
|
" function! todo#ToggleMarkAsDone('Cancelled') {{{2
|
||||||
|
|
||||||
|
Given todo (Tasks):
|
||||||
|
x 2017-09-18 Cancelled Cancelled task
|
||||||
|
x 2017-09-18 Cancelled 2017-09-01 Cancelledd task with a created date
|
||||||
|
x 2017-09-18 Cancelled Cancelledd priority pri:A task
|
||||||
|
x 2017-09-18 Cancelled 2017-09-01 Cancelledd priority task with a created date pri:A
|
||||||
|
X 2017-09-18 Cancelled Not to be confused for a cancelle task
|
||||||
|
Active task
|
||||||
|
2017-09-01 Active task with a created date
|
||||||
|
(A) Active priority task
|
||||||
|
(C) 2017-09-01 Active priority task with a created date
|
||||||
|
X 2017-09-18 Not to be confused for a cancelle task
|
||||||
|
XNot to be confused for a cancelle task
|
||||||
|
x 2017-09-18 Leading whitespace is not valid
|
||||||
|
Tricky incancelle task x 2017-09-18
|
||||||
|
Execute (Toggle cancelled):
|
||||||
|
:global/./call todo#ToggleMarkAsDone('Cancelled')
|
||||||
|
execute "%substitute/" . strftime("%Y-%m-%d") . "/**TODAY**/"
|
||||||
|
Expect todo (Toggled tasks with today as **TODAY**):
|
||||||
|
Cancelled task
|
||||||
|
2017-09-01 Cancelledd task with a created date
|
||||||
|
(A) Cancelledd priority task
|
||||||
|
(A) 2017-09-01 Cancelledd priority task with a created date
|
||||||
|
x **TODAY** Cancelled X 2017-09-18 Cancelled Not to be confused for a cancelle task
|
||||||
|
x **TODAY** Cancelled Active task
|
||||||
|
x **TODAY** Cancelled 2017-09-01 Active task with a created date
|
||||||
|
x **TODAY** Cancelled Active priority task pri:A
|
||||||
|
x **TODAY** Cancelled 2017-09-01 Active priority task with a created date pri:C
|
||||||
|
x **TODAY** Cancelled X 2017-09-18 Not to be confused for a cancelle task
|
||||||
|
x **TODAY** Cancelled XNot to be confused for a cancelle task
|
||||||
|
x **TODAY** Cancelled x 2017-09-18 Leading whitespace is not valid
|
||||||
|
x **TODAY** Cancelled Tricky incancelle task x 2017-09-18
|
||||||
|
Execute (Toggle twice):
|
||||||
|
:global/./call todo#ToggleMarkAsDone('Cancelled')
|
||||||
|
:global/./call todo#ToggleMarkAsDone('Cancelled')
|
||||||
|
execute "%substitute/" . strftime("%Y-%m-%d") . "/**TODAY**/"
|
||||||
|
Expect todo (Tasks, cancelled on today):
|
||||||
|
x **TODAY** Cancelled Cancelled task
|
||||||
|
x **TODAY** Cancelled 2017-09-01 Cancelledd task with a created date
|
||||||
|
x **TODAY** Cancelled Cancelledd priority task pri:A
|
||||||
|
x **TODAY** Cancelled 2017-09-01 Cancelledd priority task with a created date pri:A
|
||||||
|
X 2017-09-18 Cancelled Not to be confused for a cancelle task
|
||||||
|
Active task
|
||||||
|
2017-09-01 Active task with a created date
|
||||||
|
(A) Active priority task
|
||||||
|
(C) 2017-09-01 Active priority task with a created date
|
||||||
|
X 2017-09-18 Not to be confused for a cancelle task
|
||||||
|
XNot to be confused for a cancelle task
|
||||||
|
x 2017-09-18 Leading whitespace is not valid
|
||||||
|
Tricky incancelle task x 2017-09-18
|
||||||
|
" The tests above use :global/ to run todo#ToggleMarkAsDone on every line, this
|
||||||
|
" is because Vader seems to have an issue with updating the line using %,
|
||||||
|
" however, using global avoids catching exceptions, whereas % gets them.
|
||||||
|
Execute (Check todo#ToggleMarkAsDone for exceptions):
|
||||||
|
:%call todo#ToggleMarkAsDone('Cancelled')
|
||||||
|
|
||||||
" function: todo#SortDue() {{{2
|
" function: todo#SortDue() {{{2
|
||||||
|
|
||||||
Before:
|
Before:
|
||||||
|
|||||||
Reference in New Issue
Block a user