Loading ...
Sorry, an error occurred while loading the content.

folding output of tree command?

Expand Messages
  • Oliver Rath
    Hi list, Im looking for some expression to fold the output of tree command, i.e.: ├── opt ├── run - /run ├── spool │ ├── anacron │
    Message 1 of 3 , Jun 26, 2013
    • 0 Attachment
      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?

      Tfh!
      Oliver


      --
      --
      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@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Christian Brabandt
      ... From your sample, I came up with this expression: fu! FoldTree(lnum) return len(split(matchstr(getline(a:lnum),
      Message 2 of 3 , Jun 27, 2013
      • 0 Attachment
        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@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Vlad Irnov
        ... The following assumes that encoding is a Unicode encoding. Vim thus uses utf-8 internally, and each drawing char in your sample is 3 bytes. func!
        Message 3 of 3 , Jun 27, 2013
        • 0 Attachment
          On 6/26/13, Oliver Rath <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?
          >
          > Tfh!
          > Oliver

          The following assumes that 'encoding' is a Unicode encoding. Vim thus
          uses utf-8 internally, and each drawing char in your sample is 3
          bytes.

          func! FoldTree(lnum)
          let ind = match(getline(a:lnum),'├\|└')/4+1
          let indn = match(getline(a:lnum+1),'├\|└')/4+1
          return indn>ind ? '>'.ind : ind-1
          endfunc
          setl fen fdm=expr fde=FoldTree(v:lnum)

          Regards,
          Vlad

          --
          --
          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@....
          For more options, visit https://groups.google.com/groups/opt_out.
        Your message has been successfully submitted and would be delivered to recipients shortly.