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

C syntax folding at #if 0 and #if 1

Expand Messages
  • Felix Kater
    Hi, I d like to change the syntax folding for {#if,#endif} pairs a bit: First I aim to not disable all syntax and folding within a {#if 0,#endif} pair. It
    Message 1 of 1 , Jul 30, 2007
      Hi,

      I'd like to change the syntax folding for {#if,#endif} pairs a bit:
      First I aim to not disable all syntax and folding within a
      {#if 0,#endif} pair. It shall behave like a normal {,} pair. And second
      I'd like to use folding at #if 1 like for #if 0.

      I have found some lines in the global syntax/c.vim file which are
      probably relevant for this (see extract below) but I don't understand
      the code. I'd also prefere to set some entries into my home's
      ~/.vim/syntax/c.vim rather then using the global config if possible.

      Thank You

      Felix


      /usr/share/vim/vim71/syntax/c.vim, from line 262 on:

      " Accept %: for # (C99)

      syn region cPreCondit start="^\s*\(%:\|#\)\s*\(if\|ifdef
      \| ifndef\|elif\)\>" skip="\\$" end="$" end="//"me=s-1
      contains=cComment,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError

      syn match cPreCondit display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"

      if !exists("c_no_if0")

      if !exists("c_no_if0_fold") syn

      region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\|$"
      contains=cCppOut2 fold

      else

      syn region cCppOut start="^\s*\(%:\|#\)\s*if\s\+0\+\>" end=".\@=\| $"
      contains=cCppOut2

      endif

      syn region cCppOut2 contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|
      else \>\|elif\>\)" contains=cSpaceError,cCppSkip

      syn region cCppSkip contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|
      ifndef\>\)" skip="\\ $" end="^ \s*\(%:\|#\)\s*endif\>"
      contains=cSpaceError,cCppSkip

      endif


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