On Oct 8, 11:25 am, yosi izaq <[email protected]> wrote:
> On Thu, Oct 8, 2009 at 5:44 PM, Brett Stahlman wrote:
> > None of the lines start with `contains'. The lines were broken
> > automatically. The simplest way to test would be to paste it into a
> > file (e.g., /tmp/todo_syntax.vim) and source the file from within the
> > file containing your TODO items. E.g.,
>
> > :so /tmp/todo_syntax.vim
>
> > Here's the same script with backslashes continuing the long lines to
> > prevent their being broken:
>
> > syn region Lvl1 start=/^\s*-\{1}>/ end=/^\s*-\{1}>/me=s-1
> > \ contains=Lvl2,Lvl3,Lvl4 fold
> > syn region Lvl2 start=/^\s*-\{2}>/ end=/^\s*-\{1,2}>/me=s-1 contained
> > \ contains=Lvl3,Lvl4 fold
> > syn region Lvl3 start=/^\s*-\{3}>/ end=/^\s*-\{1,3}>/me=s-1 contained
> > \ contains=Lvl4 fold
> > syn region Lvl4 start=/^\s*-\{4}>/ end=/^\s*-\{1,4}>/me=s-1 contained
> > \ fold
> > set foldmethod=syntax
>
> Yes. That gets the job done. However, the way it currently folds I
> lose track of the dates. So I want to modify the file structure
> accordingly in a way that will allow me to see the date lines as well.
> The structure I have in mind is:
> date1:
> -> asdsd
> -> aaaa
>
> date2:
> ->11211231
> ->erewrer
> fdsfdsf
>
> etc.
> date can be in format of, DD or DD/MM or DD/MM/YYYY
> Could you please be kind enough to suggest the syntax to make such
> folding possible?
Assuming that the date will always appear on the line immediately
preceding a first-level todo (i.e., ->), you could do something like
this...
syn region Lvl1 start=/^\s*-\{1}>/
\ end=/^\d\d\%(\/\d\d\%(\/\d\d\d\d\)\?\)\?:\n\s*->/me=s-1
\ end=/^\s*-\{1}>/me=s-1 contains=Lvl2,Lvl3,Lvl4 fold
syn region Lvl2 start=/^\s*-\{2}>/
\ end=/^\d\d\%(\/\d\d\%(\/\d\d\d\d\)\?\)\?:\n\s*->/me=s-1
\ end=/^\s*-\{1,2}>/me=s-1 contained contains=Lvl3,Lvl4 fold
syn region Lvl3 start=/^\s*-\{3}>/
\ end=/^\d\d\%(\/\d\d\%(\/\d\d\d\d\)\?\)\?:\n\s*->/me=s-1
\ end=/^\s*-\{1,3}>/me=s-1 contained contains=Lvl4 fold
syn region Lvl4 start=/^\s*-\{4}>/
\ end=/^\d\d\%(\/\d\d\%(\/\d\d\d\d\)\?\)\?:\n\s*->/me=s-1
\ end=/^\s*-\{1,4}>/me=s-1 contained fold
set foldmethod=syntax
Note that it's possible to get much fancier with the date pattern to
ensure that something like 99/99/9999, for example, is not recognized
as a date. Also note that I'm assuming you would have only one date
for a top-level entry and any nested entries below it. In other words,
I'm assuming a --> or ---> entry takes its date from the enclosing ->.
This is why the end regexes ignore dates not followed by a newline,
optional whitespace, and a `->'.
Brett Stahlman
>
> Thank you very much!
> Yosi- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---