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

I'd like to disable syntax folds for all syntax definitions, but my own

Expand Messages
  • benjamin schnitzler
    Hello, I m currently stuck with the following problem: Often I like the syntax highlighting, but not the folds resulting from the syntax definition (e.g. in C,
    Message 1 of 2 , Nov 10 5:46 AM
      Hello,

      I'm currently stuck with the following problem: Often I like the syntax highlighting, but not the folds resulting from the syntax definition (e.g. in C, where #if 0 #else #endif is not fold correctly). For that, I'd rather like to define my own folds, based on my own syntax region definitions, but how prevent the syntax rules from the syntax file to trigger? (Of course this question is not only related to the C syntax definitions, but to syntax files in general, otherwise, I would have already modified the C syntax definition file.)

      I know, I could define syntax folding based on foldmethod=expr. That is what I have done often enough, but it gets tedious and it's not nice, especially, since I want to write a plugin to ease syntax definitions a bit. The method based on syntax regions is clear and beautiful.

      Do You know how to trick Vim, letting me accomplish, what I want to do?

      Thank You

      Benjamin Schnitzler

      --
      --
      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.
    • Ben Fritz
      ... If you want sytax-aware folding, neither using nor modifying the syntax file itself, then I would suggest using foldmethod=expr as you have done. HOWEVER,
      Message 2 of 2 , Nov 10 8:12 AM
        On Sunday, November 10, 2013 7:46:53 AM UTC-6, benjamin schnitzler wrote:
        > Hello,
        >
        >
        > I'm currently stuck with the following problem: Often I like the syntax highlighting, but not the folds resulting from the syntax definition (e.g. in C, where #if 0 #else #endif is not fold correctly). For that, I'd rather like to define my own folds, based on my own syntax region definitions, but how prevent the syntax rules from the syntax file to trigger? (Of course this question is not only related to the C syntax definitions, but to syntax files in general, otherwise, I would have already modified the C syntax definition file.)
        >
        >
        >
        > I know, I could define syntax folding based on foldmethod=expr. That is what I have done often enough, but it gets tedious and it's not nice, especially, since I want to write a plugin to ease syntax definitions a bit. The method based on syntax regions is clear and beautiful.
        >
        >
        >
        > Do You know how to trick Vim, letting me accomplish, what I want to do?
        >

        If you want sytax-aware folding, neither using nor modifying the syntax file itself, then I would suggest using foldmethod=expr as you have done.

        HOWEVER, rather than basing your foldexpr function on the text in the file, instead use functions to query the syntax highlight group at each position in the file and return a fold level accordingly. Thus, the syntax can completely define your folds, but you can set up those folds however you want.

        These may be useful:
        :help synID
        :help synIDattr
        :help synIDtrans
        :help synstack()

        Note that for some syntaxes, this might turn out to be quite slow.

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