Tuesday, July 3, 2012

Re: Fold all blocks without TODO in vim notes file

On Tue, Jul 3, 2012 at 2:27 PM, Sepp Tannhuber <sepp.tannhuber@yahoo.de> wrote:
> Dear all,
>
> I have the following vim notes file:
>
> ~ notes
> ~
> ~ #2012-04-12
> ~ ◦ DONE beer
> ~
> ~ #2012-04-13
> ~ ◦ DONE beer
> ~ ◦ DONE another beer
> ~
> ~ #2012-06-30
> ~ ◦ DONE beer
> ~ ◦ TODO another beer
> ~
> ~ #2012-07-02
> ~ ◦ TODO beer
>
>
> If I start vim with
> ~ vi notes -c 'set foldenable' -c 'set foldlevel=0'
> all blocks beginning with a hash mark are folded.
> But I would like to have only the blocks folded
> that do not have a TODO item in their list. In the
> given example only the first two blocks 2012-04-12
>
> and 2012-04-13 should be folded because they are
> done completely.
>
> How can this be done?
>
>
> Best regards
> Joseph

Quick answer that comes to me off the top of my head: use a custom
fold expression. (See :help 'foldexpr')

Basically, you want something that does something like this:

if indent of current line is 0 (probably a date line, not a DONE or
TODO line) or line is entirely whitespace
return 0 (no fold)
else
check if current line starts with TODO
return 0
else
go up, checking lines until indent is 0 (or is a whitespace
line); if any line has a TODO, return 0
go down from current line, checking the same

Finally, if we got this far, we're not a TODO block or on an empty or
date line; return 1 to fold it.

Salman

--
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

No comments:

Post a Comment