On Mo, 10 Jul 2017, Robert wrote:
> I have a specific tag "due:YYYY-MM-DD" in my files.
>
> Is it possible for a function to compare all the matches it finds to
> today's date and if the "due:" is is past, to highlight it?
You can do something like this.
func! HighlightMatches(substr)$
" Should also be done here:
" 1) Make sure, substr is actually a date
" 2) clear previous highlighting using matchdelete()
try
let cur=localtime()$
let match=system('date --date="'.a:substr.'" +%s')$
if cur > match$
call matchadd('Todo', a:substr)$
endif$
catch
" handle errors
finally
return a:substr$
endtry
endfunc$
Then you can use e.g.
:%s/due:\zs\d\{4}-\d\d-\d\d/\=HighlightMatch(submatch(0))/g
There doesn't seem to be a way to have Vim create a date for a given
string, so I had to use the shell's date command. Unfortunately, because
of using system() one cannot use the 'n' flag, because this is not
allowed in the sandbox.
All in all, this would make a nice plugin.
Best,
Christian
--
Das Christentum braucht nur ein Jahrtausend in seiner Geschichte
zurückzublättern: im Anfang war es wohl die Güte, die diese Religion
hat zu gebären helfen - zur Macht gebracht hat sie die Gewalt.
-- Kurt Tucholsky
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment