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

Re: C/C++ Syntax Folding - Special treatment for functions/methods

Expand Messages
  • Neil Bird
    Around about 08/02/05 15:17, Jean-Sebastien Trottier typed ... ... Ah ... that might ve helped, mightn t it :-) ... although I was (at the time) more
    Message 1 of 10 , Feb 9, 2005
    • 0 Attachment
      Around about 08/02/05 15:17, Jean-Sebastien Trottier typed ...
      > What are your folding requirements now? Can you clearly state them or
      > will you keep us guessing? ;^)
      > Please also post code examples and explain how you want them folded...

      Ah ... that might've helped, mightn't it :-) ... although I was (at
      the time) more interested in why my config. generated fake parenthesis
      errors, but here you go:

      I don't want to make it /too/ complex at the outset, so this isn't
      *quite* what I'm after, but it's a step:


      a) in a namespace block, fold only on '^\s\+[{}]' indented blocks; the
      extension for this would be to only do the first one block; the
      extension for *that* (final) would be to only do it for the first
      brace-pair inside 'class {}' itself inside 'namespace {}'.

      So I was thinking along the lines of defining a 'namspace-block'
      syntax region, then a 'class-block' region which is only allowed in a
      namespace-block and can't contain other class-blocks, then finally a
      brace-fold-block which (ditto) can only be inside class blocks and
      cannot contain other brace-fold-blocks.


      b) not in a namespace block, fold only on '^[{}]' (column-0 blocks).


      Primarily, (a) is for our headers [and is v. tricky], (b) for our
      cpp's [and is trivial & I have it working].


      namespace CODEBASE
      {
      class jobby
      {
      public:
      int stuff;
      void do_it()
      {
      // some inline code
      {
      // some block that'll not be folded
      }
      }
      };
      }


      // body
      CODEBASE::jobby::do_it()
      {
      // main code
      // lives here
      {
      // another inline block that'll not be folded
      }
      }


      .. goes to:

      namespace CODEBASE
      {
      class jobby
      {
      public:
      int stuff;
      void do_it()
      +-- 6 lines: {-----------------------------
      };
      }


      // body
      CODEBASE::jobby::do_it()
      {
      // main code
      // lives here
      +-- 3 lines: {-----------------------------
      }



      This is what currently doesn't work right; one thing that's
      obviously wrong is that it prematurely ends cFoldSimpleInner blocks, and
      it think that's also corrupting the parenthesis checks.

      syn region cFoldSimpleOuter start='^{' end='^}' transparent fold
      syn region cFoldSimpleNamespace start='^namespace\>.*\n{' end='^}'
      \ transparent contains=ALLBUT,cFoldSimpleOuter
      syn region cFoldSimpleInner start='^\s\+{' end='^\s]+}'
      \ transparent fold contains=ALLBUT,cFoldSimpleInner
      \ containedin=cFoldSimpleNamespace


      > For completeness, I would use:
      > start='^namespace\>.*\n{'

      Yes, I've tried a few variants of this. I'll try that one
      specifially in a bit, though.


      > You probably should specify end='^[ \t]\+}'

      Oops ...


      > By the way, you can easily replace '[ \t]' with a simple '\s', they mean
      > the same thing... and tend to read better

      You're right; too many regex syntaxes ... :)

      --
      [neil@fnx ~]# rm -f .signature
      [neil@fnx ~]# ls -l .signature
      ls: .signature: No such file or directory
      [neil@fnx ~]# exit
    Your message has been successfully submitted and would be delivered to recipients shortly.