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

Problems with regions and 'fold' (syntax folding)

Expand Messages
  • Bernhard Walle
    Hi, I m trying to add syntax-based folding to the asciidoc.vim syntax file (which is not in the vim distribution but in the asciidoc distribution). I just want
    Message 1 of 2 , Feb 3, 2008
    • 0 Attachment
      Hi,

      I'm trying to add syntax-based folding to the asciidoc.vim syntax file
      (which is not in the vim distribution but in the asciidoc
      distribution).

      I just want auto-folding for the two top-most headlines:

      == H1 ==

      Body

      === H2 ===
      Body

      == H1 ==

      ...

      I'm trying following setting:

      syn region asciidocOneLineTitle2Foldregion \
      start=/^===\s\+.*\s\+=\?==$/ \
      end=/\n\(===\?\s\+.*\s\+=\?==\)\@=/ \
      fold
      syn region asciidocOneLineTitle1Foldregion \
      start=/^==\s\+.*\s\+==$/ \
      end=/\n\(==\s\+.*\s\+==\)\@=/ \
      fold \
      contains=asciidocOneLineTitle2Foldregion

      However, the problem seems to be that the end of
      asciidocOneLineTitle2Foldregion prevents the end of
      asciidocOneLineTitle1Foldregion to be detected. When a H1 doesn't
      contain H2 sections, it works ...

      Can anybody help here?


      Bernhard
      --
      Machine Always Crashes, If Not, The Operating System Hangs (MACINTOSH)
      -- Topic on #Linux

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_use" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Andy Wokula
      ... Right, you want the same n to be matched by two different rules. ... Suggestion: syn region asciidocOneLineTitle2Foldregion start=/^=== s.* s===$/
      Message 2 of 2 , Feb 3, 2008
      • 0 Attachment
        Bernhard Walle schrieb:
        > Hi,
        >
        > I'm trying to add syntax-based folding to the asciidoc.vim syntax file
        > (which is not in the vim distribution but in the asciidoc
        > distribution).
        >
        > I just want auto-folding for the two top-most headlines:
        >
        > == H1 ==
        >
        > Body
        >
        > === H2 ===
        > Body
        >
        > == H1 ==
        >
        > ...
        >
        > I'm trying following setting:
        >
        > syn region asciidocOneLineTitle2Foldregion \
        > start=/^===\s\+.*\s\+=\?==$/ \
        > end=/\n\(===\?\s\+.*\s\+=\?==\)\@=/ \
        > fold
        > syn region asciidocOneLineTitle1Foldregion \
        > start=/^==\s\+.*\s\+==$/ \
        > end=/\n\(==\s\+.*\s\+==\)\@=/ \
        > fold \
        > contains=asciidocOneLineTitle2Foldregion
        >
        > However, the problem seems to be that the end of
        > asciidocOneLineTitle2Foldregion prevents the end of
        > asciidocOneLineTitle1Foldregion to be detected. When a H1 doesn't
        > contain H2 sections, it works ...

        Right, you want the same \n to be matched by two different rules.

        :h region
        :h excludenl
        :h keepend

        > Can anybody help here?
        >
        > Bernhard

        Suggestion:

        syn region asciidocOneLineTitle2Foldregion
        \ start=/^===\s.*\s===$/
        \ end=/^==\%[=]\s/me=s-1
        \ fold
        \ excludenl

        syn region asciidocOneLineTitle1Foldregion
        \ start=/^==\s.*\s==$/
        \ end=/^==\s/me=s-1
        \ contains=asciidocOneLineTitle2Foldregion
        \ fold

        :h :syn-pattern-offset

        Assumptions:
        Can a H2 section start outside a (i.e. before the first) H1 section?
        yes
        Do other syntax elements start with /^==/ ?
        no
        "end=/^==\s/me=s-1" ends the region at the end of the previous line,
        as if a pattern with "...$" was involved.


        BTW:
        :h line-continuation

        --
        Andy

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_use" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.