Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created April 8, 2014 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/10102149 to your computer and use it in GitHub Desktop.
Save AndrewVos/10102149 to your computer and use it in GitHub Desktop.
function! s:ConvertToCharClass(cur)
if a:cur =~ '[2-9]'
return '[0-' . (a:cur-1) . ']'
endif
return '0'
endfunction
function! s:MatchNumberBefore(num)
let branches = []
let init = ''
for i in range(len(a:num))
if a:num[i] =~ '[1-9]'
call add(branches, init . s:ConvertToCharClass(a:num[i]) . repeat('\d', len(a:num) - i - 1))
endif
let init .= a:num[i]
endfor
return '\%(' . join(branches, '\|') .'\)'
endfunction
let s:beforeYear = s:MatchNumberBefore(strftime("%Y"))
let s:beforeMonth = s:MatchNumberBefore(strftime("%m"))
let s:beforeDay = s:MatchNumberBefore(strftime("%d"))
let s:year = strftime("%Y")
let s:month = strftime("%m")
let s:day = strftime("%d")
exec "syntax match TodoDatePast \"\\[\\d\\{2}-\\d\\{2}-" . s:beforeYear . "\\]\""
exec "syntax match TodoDatePast \"\\[\\d\\{2}-" . s:beforeMonth . "-" . s:year . "\\]\""
exec "syntax match TodoDatePast \"\\[" . s:beforeDay . "-" . s:month . "-" . s:year . "\\]\""
highlight link TodoDatePast TodoRed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment