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

Re: A question on folds syntax definition

Expand Messages
  • Boris Danilov
    ... Okay, if anybody interested I did it like this and pretty satisfied with the result. syntax region langCommentLine start= // end= $ syntax region
    Message 1 of 11 , Jan 8, 2013
      Am 07.01.2013 19:29, schrieb Boris Danilov:
      > Hello! I have a language with one-line comments that start from '//'
      > (double slash) and last to the end of the line. I want to
      > syntactically define folds that start with '//>' and end at '//<'.
      > Folds can nest. It looks simple, but I can't come up with a good
      > solution.

      Okay, if anybody interested I did it like this and pretty satisfied
      with the result.

      syntax region langCommentLine start="//" end="$"
      syntax region langFold start="//>"
      \ end="//<.\{-}\(\(//>\)\@=\|\(//<\)\@=\|$\)"
      \ keepend extend
      \ contains=TOP transparent fold

      Regards,
      Boris

      --
      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
    • Andy Wokula
      ... And the help topic is at ... I don t know why you insist on folding by syntax, it doesn t make sense for your language (imho). The opening marker
      Message 2 of 11 , Jan 8, 2013
        Am 08.01.2013 09:33, schrieb Boris Danilov:
        > Am 07.01.2013 19:29, schrieb Boris Danilov:
        >> Hello! I have a language with one-line comments that start from '//'
        >> (double slash) and last to the end of the line. I want to
        >> syntactically define folds that start with '//>' and end at '//<'.
        >> Folds can nest. It looks simple, but I can't come up with a good
        >> solution.
        >
        > Okay, if anybody interested I did it like this and pretty satisfied
        > with the result.
        >
        > syntax region langCommentLine start="//" end="$"
        > syntax region langFold start="//>"
        > \ end="//<.\{-}\(\(//>\)\@=\|\(//<\)\@=\|$\)"
        > \ keepend extend
        > \ contains=TOP transparent fold

        And the help topic is at
        :h :syn-fold

        I don't know why you insist on folding by syntax, it doesn't make sense
        for your language (imho). The opening marker contained in the linewise
        comment need to extend that comment over several lines up to the closing
        marker, it's not one-line anymore.

        And fdm=syntax is also known to be slow.

        And you cannot create/delete folds with `zf', `zd' etc. but maybe that
        is intended?

        --
        Andy

        --
        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
      • Boris Danilov
        Andy, ... The language has another kind of folds based on it s meaningful syntax and I want to have them along with the user defined foldings. The reason user
        Message 3 of 11 , Jan 8, 2013
          Andy,

          > And the help topic is at
          > :h :syn-fold
          >
          > I don't know why you insist on folding by syntax, it doesn't make sense
          > for your language (imho). The opening marker contained in the linewise
          > comment need to extend that comment over several lines up to the closing
          > marker, it's not one-line anymore.
          >
          > And fdm=syntax is also known to be slow.
          >
          > And you cannot create/delete folds with `zf', `zd' etc. but maybe that
          > is intended?

          The language has another kind of folds based on it's meaningful syntax
          and I want to have them along with the user defined foldings. The
          reason user defined folds look like '//>' and '//<' because there is
          already quite enough of source code that uses that convention.

          By the way, is there a quick method to unfold 2 fold levels from
          bottom while keeping the rest folds unchanged?

          Regards,
          Boris

          --
          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
        • Ben Fritz
          ... What does this mean? Are you looking for the zR/zr/zM/zm commands? See the help entry for each. (mnemonic: zr = fold reveal zm = fold more ) -- You
          Message 4 of 11 , Jan 8, 2013
            On Tuesday, January 8, 2013 8:16:48 AM UTC-6, Boris Danilov wrote:
            >
            >
            > By the way, is there a quick method to unfold 2 fold levels from
            >
            > bottom while keeping the rest folds unchanged?
            >

            What does this mean? Are you looking for the zR/zr/zM/zm commands? See the help entry for each. (mnemonic: zr = "fold reveal" zm = "fold more")

            --
            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
          • Boris Danilov
            ... Yeah like those, but I want to fold/unfold from *bottom* while those commands do this from *top*. I want to open last one fold from behind while keeping
            Message 5 of 11 , Jan 8, 2013
              On Tue, Jan 8, 2013 at 7:33 PM, Ben Fritz <fritzophrenic@...> wrote:
              > On Tuesday, January 8, 2013 8:16:48 AM UTC-6, Boris Danilov wrote:
              >>
              >>
              >> By the way, is there a quick method to unfold 2 fold levels from
              >>
              >> bottom while keeping the rest folds unchanged?
              >>
              >
              > What does this mean? Are you looking for the zR/zr/zM/zm commands? See the help entry for each. (mnemonic: zr = "fold reveal" zm = "fold more")

              Yeah like those, but I want to fold/unfold from *bottom* while those
              commands do this from *top*. I want to open last one fold from behind
              while keeping top folds without change.

              Regards,
              Boris

              --
              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
            • Ben Fritz
              ... I still don t understand what you re trying to do. I don t know what you mean by unfold from the bottom vs. unfold from the top or what open last one
              Message 6 of 11 , Jan 8, 2013
                On Tuesday, January 8, 2013 10:54:46 AM UTC-6, Boris Danilov wrote:
                > On Tue, Jan 8, 2013 at 7:33 PM, Ben Fritz <fritzophrenic@...> wrote:
                >
                > > On Tuesday, January 8, 2013 8:16:48 AM UTC-6, Boris Danilov wrote:
                >
                > >>
                >
                > >>
                >
                > >> By the way, is there a quick method to unfold 2 fold levels from
                >
                > >>
                >
                > >> bottom while keeping the rest folds unchanged?
                >
                > >>
                >
                > >
                >
                > > What does this mean? Are you looking for the zR/zr/zM/zm commands? See the help entry for each. (mnemonic: zr = "fold reveal" zm = "fold more")
                >
                >
                >
                > Yeah like those, but I want to fold/unfold from *bottom* while those
                >
                > commands do this from *top*. I want to open last one fold from behind
                >
                > while keeping top folds without change.
                >

                I still don't understand what you're trying to do. I don't know what you mean by "unfold from the bottom" vs. "unfold from the top" or what "open last one fold from behind" means.

                Can you give an example of text indicating where folds are, which folds start closed, and which folds would be open after whatever command you run?

                --
                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
              • Boris Danilov
                Ben, ... Okay, it s been a while until I felt I could formulate my question better. I want to open all folds that doesn t contain other folds inside of them
                Message 7 of 11 , Jan 9, 2013
                  Ben,

                  On Wed, Jan 9, 2013 at 1:16 AM, Ben Fritz <fritzophrenic@...> wrote:
                  > On Tuesday, January 8, 2013 10:54:46 AM UTC-6, Boris Danilov wrote:
                  >> On Tue, Jan 8, 2013 at 7:33 PM, Ben Fritz <fritzophrenic@...> wrote:
                  >>
                  >> > On Tuesday, January 8, 2013 8:16:48 AM UTC-6, Boris Danilov wrote:
                  >> >> By the way, is there a quick method to unfold 2 fold levels from
                  >> >>
                  >> >> bottom while keeping the rest folds unchanged?
                  >> >>
                  >> > What does this mean? Are you looking for the zR/zr/zM/zm commands? See the help entry for each. (mnemonic: zr = "fold reveal" zm = "fold more")
                  >>
                  > Yeah like those, but I want to fold/unfold from *bottom* while those
                  > commands do this from *top*. I want to open last one fold from behind
                  > while keeping top folds without change.
                  >
                  > I still don't understand what you're trying to do. I don't know what you mean by "unfold from the bottom" vs. "unfold from the top" or what "open last one fold from behind" means.
                  > Can you give an example of text indicating where folds are, which folds start closed, and which folds would be open after whatever command you run?

                  Okay, it's been a while until I felt I could formulate my question
                  better. I want to open all folds that doesn't contain other folds
                  inside of them (or in more complex scenario to open folds that contain
                  at most N folds inside). I want other folds state keep unchanged.

                  Then, why do I need it? I want the last (in this meaning that the fold
                  is *last* when it doesn't contain other forlds) fold level always be
                  open no matter what, so that when I finally get to it I don't need to
                  open that. Actually I want to control it this way: open the *last*
                  level or close the *last* level.

                  Regards,
                  Boris

                  --
                  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
                • Ben Fritz
                  ... Ok, so if I understand correctly, with foldmethod=marker and the default fold markers, and this example text: folded text {{{1 is great {{{2 {{{3 for
                  Message 8 of 11 , Jan 10, 2013
                    On Wednesday, January 9, 2013 4:20:44 PM UTC-6, Boris Danilov wrote:
                    >
                    > Okay, it's been a while until I felt I could formulate my question
                    > better. I want to open all folds that doesn't contain other folds
                    > inside of them (or in more complex scenario to open folds that contain
                    > at most N folds inside). I want other folds state keep unchanged.
                    >
                    > Then, why do I need it? I want the last (in this meaning that the fold
                    > is *last* when it doesn't contain other forlds) fold level always be
                    > open no matter what, so that when I finally get to it I don't need to
                    > open that. Actually I want to control it this way: open the *last*
                    > level or close the *last* level.
                    >

                    Ok, so if I understand correctly, with foldmethod=marker and the default fold
                    markers, and this example text:

                    folded text {{{1
                    is great {{{2 {{{3
                    for showing only parts }}}3
                    of a file }}}2
                    or maybe an outline }}}1

                    With all folds closed, this turns into:

                    folded text

                    After pressing zo:

                    folded text {{{1
                    is great
                    or maybe an outline }}}1

                    Now press zo on the "is great" line:

                    folded text {{{1
                    is great
                    of a file }}}2
                    or maybe an outline }}}1

                    But instead you want all folds open.

                    This cannot be accomplished with a simple option setting. However, if you press
                    zO or zA instead of zo or za, then any folds under the cursor will be opened
                    automatically to any level. Maybe this gets you where you want?

                    The other possibility I can think of, is to start with all folds open, then use
                    a :g or :folddoopen command combined with foldlevel() to close folds selectively
                    using the :foldclose command. This could be done in a BufWinEnter autocmd, for
                    example.

                    --
                    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
                  Your message has been successfully submitted and would be delivered to recipients shortly.