Fixed a bug in <Leader>x (todo#PrependDate) introduced last commit. Fixed case sensitivity bug in todo#ToggleMarkAsDone() and todo#UnMarkAsDone() Fixed errors being reported for repeat#set if vim-repeat plugin is not installed. Fixed modeline in .vim files to work (only works on first/last 5 lines of file), and made the modelines consistent across all files. New unit tests for todo#ToggleMarkAsDone() Minor fixes for README.md and man page Fix anchoring of RegExp in todo#ToggleMarkAsDone Fixed a bug in overdue highlighting that resulted in the current date being matched on round dates like the 20th and 30th. Added more unit tests for overdue date highlighting. Corrected RegExp anchoring on today date highlighting. Added a few bash scripts to make running unit tests easier and more reliable, including testing with ignorecase user preference set.
183 lines
9.3 KiB
VimL
183 lines
9.3 KiB
VimL
" File: todo.txt.vim
|
|
" Description: Todo.txt syntax settings
|
|
" Author: David Beniamine <David@Beniamine.net>,Leandro Freitas <freitass@gmail.com>
|
|
" License: Vim license
|
|
" Website: http://github.com/dbeniamine/todo.txt-vim
|
|
|
|
if exists("b:current_syntax")
|
|
finish
|
|
endif
|
|
|
|
syntax match TodoDone '^[x]\s.\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext
|
|
syntax match TodoPriorityA '^(A) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityB '^(B) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityC '^(C) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityD '^(D) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityE '^(E) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityF '^(F) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityG '^(G) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityH '^(H) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityI '^(I) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityJ '^(J) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityK '^(K) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityL '^(L) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityM '^(M) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityN '^(N) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityO '^(O) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityP '^(P) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityQ '^(Q) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityR '^(R) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityS '^(S) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityT '^(T) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityU '^(U) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityV '^(V) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityW '^(W) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityX '^(X) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityY '^(Y) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoPriorityZ '^(Z) .\+$' contains=TodoKey,TodoDate,TodoProject,TodoContext,TodoDueToday,TodoOverDueDate
|
|
syntax match TodoDate '\d\{2,4\}-\d\{2\}-\d\{2\}' contains=NONE
|
|
syntax match TodoKey '\S*\S:\S\S*' contains=TodoDate
|
|
syntax match TodoProject '\(^\|\W\)+[^[:blank:]]\+' contains=NONE
|
|
syntax match TodoContext '\(^\|\W\)@[^[:blank:]]\+' contains=NONE
|
|
|
|
let s:todayDate=strftime('%Y\-%m\-%d')
|
|
execute 'syntax match TodoDueToday /\v\c<due:' . s:todayDate . '>/ contains=NONE'
|
|
|
|
" Other priority colours might be defined by the user
|
|
highlight default link TodoKey Special
|
|
highlight default link TodoDone Comment
|
|
highlight default link TodoPriorityA Identifier
|
|
highlight default link TodoPriorityB statement
|
|
highlight default link TodoPriorityC type
|
|
highlight default link TodoDate PreProc
|
|
highlight default link TodoProject Special
|
|
highlight default link TodoContext Special
|
|
highlight default link TodoDueToday Todo
|
|
|
|
function! todo#GetDateRegexForPastDates(...)
|
|
" Build a RegExp to match all dates prior to a reference date.
|
|
"
|
|
" Optionally accepts a (year, month, day) for the date, otherwise assumes the
|
|
" reference date is the current date.
|
|
"
|
|
" In the end, the RegExp will look something like:
|
|
" =todo#GetDateRegexForPastDates(2017, 09, 15)
|
|
" \v(([01]\d{3}|200\d|201[0-6])\-\d{2}\-\d{2}|(2017\-(0[0-8])\-\d{2})|(2017\-09\-0\d)|(2017\-09\-1[0-4]))
|
|
"
|
|
" We split the RegExp into a few alternation groups:
|
|
" 1. All dates prior to 2000, dates before this are not supported
|
|
" 2. All previous decades for the reference date century
|
|
" 3. The current decade up to the year prior to the reference year
|
|
" 4. All months for the reference year up to the end of the previous month
|
|
" 5. Days of the month part 1.
|
|
" 6. Days of the month part 2.
|
|
"
|
|
" Will not work on reference dates past 2099, or before 2000.
|
|
"
|
|
" Invalid months and days are not checked, i.e. 2015-14-67 will match.
|
|
"
|
|
" Years must be 4 digits.
|
|
"
|
|
|
|
" Get the reference date
|
|
let l:day=strftime("%d")
|
|
let l:month=strftime("%m")
|
|
let l:year=strftime("%Y")
|
|
if a:0 >= 1
|
|
let l:year=a:1
|
|
endif
|
|
if a:0 >= 2
|
|
let l:month=a:2
|
|
endif
|
|
if a:0 >= 3
|
|
let l:day=a:3
|
|
endif
|
|
|
|
" Use very magic mode, and start an alternation
|
|
let l:overdueRex = '\v('
|
|
|
|
" PART 1: 0000-1999
|
|
" This sucker is static and won't change to year 3000. I'm not coding for the year 3000.
|
|
let l:overdueRex = l:overdueRex . '([01]\d{3}'
|
|
|
|
" PART 2. All previous decades for the reference date century
|
|
" i.e. for 2017: "200\d", for 2035: "20[0-2]\d"
|
|
" for 2000: skip
|
|
let l:decade = strpart(l:year, 2, 1) " i.e. the 1 from 2017
|
|
if l:decade > 0
|
|
let l:overdueRex = l:overdueRex . '|20'
|
|
if l:decade > 1
|
|
let l:overdueRex = l:overdueRex . '[0-' . (l:decade - 1) . ']'
|
|
else
|
|
let l:overdueRex = l:overdueRex . '0'
|
|
endif
|
|
let l:overdueRex = l:overdueRex . '\d'
|
|
endif
|
|
|
|
" PART 3: This decade, to previous year
|
|
" i.e. for 2017: "201[0-6]", for 2035: "203[0-4]", for 2000: skip
|
|
let l:y = strpart(l:year, 3, 1) " Last digit of the year, i.e. 7 for 2017
|
|
if l:y > 0
|
|
if l:y > 1
|
|
let l:overdueRex = l:overdueRex . '|20' . l:decade . '[0-' . (l:y - 1) . ']'
|
|
else
|
|
let l:overdueRex = l:overdueRex . '|20' . l:decade . '0'
|
|
endif
|
|
endif
|
|
let l:overdueRex = l:overdueRex . ')\-\d{2}\-\d{2}|'
|
|
|
|
" PART 4: All months to the end of the previous month
|
|
" i.e. for a date of 2017-09-07, "2017-(0[1-8])-\d{2}"
|
|
" for 2017-11-30: "2017-(0\d|1[0-1])-\d{2}"
|
|
" for 2017-01-20: skip
|
|
" This only applies if the reference date is not in January
|
|
if l:month > 1
|
|
let l:overdueRex = l:overdueRex . '(' . l:year . '\-(0'
|
|
if l:month > 10
|
|
let l:overdueRex = l:overdueRex . '\d|1'
|
|
endif
|
|
let l:y = strpart(printf('%02d', l:month), 1, 1) " Second digit of the month
|
|
let l:overdueRex = l:overdueRex . '[0-' . (l:y - 1) . '])\-\d{2})|'
|
|
endif
|
|
|
|
" PART 5. Days of the month part 1.
|
|
" i.e. for 2017-09-07: skip
|
|
" for 2017-12-29: "2017-12-[0-1]\d"
|
|
let l:y = strpart(printf('%02d', l:day), 0, 1) " First digit of the day
|
|
if l:y > 0
|
|
if l:y > 1
|
|
let l:overdueRex = l:overdueRex . '(' . l:year . '\-' . printf('%02d', l:month) . '\-[0-' . (l:y - 1) . ']\d)|'
|
|
else
|
|
let l:overdueRex = l:overdueRex . '(' . l:year . '\-' . printf('%02d', l:month) . '\-0\d)|'
|
|
endif
|
|
endif
|
|
|
|
" PART 6. Days of the month part 2.
|
|
" i.e. for 2017-09-07: "2017-09-0[0-6]"
|
|
" for 2017-12-29: "2017-12-2[0-8]"
|
|
" for 2017-09-20: skip
|
|
let l:d = strpart(printf('%02d', l:day), 1, 1) " Last digit of the day
|
|
if l:d > 0
|
|
let l:y = strpart(printf('%02d', l:day), 0, 1) " First digit of the day
|
|
let l:overdueRex = l:overdueRex . '(' . l:year . '\-' . printf('%02d', l:month) . '\-' . l:y
|
|
if l:d > 1
|
|
let l:overdueRex = l:overdueRex . '[0-' . (l:d - 1) . ']'
|
|
else
|
|
let l:overdueRex = l:overdueRex . '0'
|
|
endif
|
|
let l:overdueRex = l:overdueRex . ')'
|
|
endif
|
|
|
|
let l:overdueRex = substitute(l:overdueRex, '|$', '', 'e')
|
|
let l:overdueRex = l:overdueRex . ')'
|
|
|
|
return l:overdueRex
|
|
endfunction
|
|
|
|
execute 'syntax match TodoOverDueDate /\v\c<due:' . todo#GetDateRegexForPastDates() . '>/'
|
|
highlight default link TodoOverDueDate Error
|
|
|
|
let b:current_syntax = "todo"
|
|
|
|
" vim: tabstop=4 shiftwidth=4 softtabstop=4 expandtab foldmethod=marker
|