Thursday, June 27, 2013

Re: folding output of tree command?

On Wed, June 26, 2013 17:31, Oliver Rath wrote:
> Hi list,
>
> Im looking for some expression to fold the output of tree command, i.e.:
>
> ДеДЯДЯ opt
> ДеДЯДЯ run -> /run
> ДеДЯДЯ spool
> Да ДеДЯДЯ anacron
> Да ДеДЯДЯ asterisk [error opening dir]
> Да ДеДЯДЯ cron
> Да Да ДеДЯДЯ atjobs
> Да Да ДеДЯДЯ atspool
> Да Да ДдДЯДЯ crontabs
> Да ДеДЯДЯ cups [error opening dir]
> Да ДеДЯДЯ libreoffice
> Да Да ДдДЯДЯ uno_packages
> Да ДеДЯДЯ lintian
> Да ДеДЯДЯ mail -> ../mail
> Да ДеДЯДЯ plymouth
> Да ДеДЯДЯ rsyslog
> Да ДдДЯДЯ samba
> ДдДЯДЯ tmp
>
> So imho I have to find a way to count the number of "Да" (including the
> following spaces), so i could define a rule to open/cloes the folds
> recursivly. Any idea for an appropriate expression doing this?

From your sample, I came up with this expression:

fu! FoldTree(lnum)
return len(split(matchstr(getline(a:lnum),
'^\%([ДаДеДд]\s*\)\+\%(\%([ДдДе]\?ДЯ\)\+\)')))
endfu
setl fen fdm=expr fde=FoldTree(v:lnum)

This seems to work for me. Make sure you have utf8 encoding, so the
characters are correct.

(Please note, the mail may get mangled because either of my Webmailer
sucks or Google mangles it (or even both)). So I attach a copy of this
to this mail.


Regards,
Christian

--
--
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/groups/opt_out.

No comments:

Post a Comment