marker-based folding?

2005-05-06
2012-11-13
  • Nobody/Anonymous

    Hi Don and all,

    I searched quite a long tie for a syntax folding editor. Once I  found npp, I know that it is the editor I am dreaming for.

    I know that npp is based on scintilla, and someone told me that scintilla support marker-based folding. However, I can't found any way to enable the marker based folding.

    Would anyone told me that if npp support marker-based folding ?  If so, how to use it? If not, will it be included in the comming release?

     
    • Don HO

      Don HO - 2005-05-08

      > Would anyone told me that if npp support marker-based folding ?

      I have no idea what "marker-based folding" is. Could you give more explaination?

      Don

       
    • Nobody/Anonymous

      Well, in syntax-base folding, the position to fold code is depended on the syntax.

      For marker-based folding, coder can mark make some special character patterns and the editor read the patterns and fold the code.

      someone told me that including "//{" and "//}" in a c++ code can make Scintilla fold that section. I tried that but it did not work. Maybe some hidden key binding I set into the scintilla.

      In case you need to have a feel of it, please download another open source editor - code-browser at http://code-browser.sourceforge.net/

       
    • Nobody/Anonymous

      Hi Don and all,

      I just playing with the 'folder and default option' in the user define language dialogue.

      It seems that if some folding keywords can be understanded even if it is in line comment or block comment, the marker-based folding can be archieved.

      Is it technically feasible?

       
      • Don HO

        Don HO - 2005-05-16

        You can use the User Language Define System to achieve your goal (by defining your marks as keywords), however, it has its limite : they need the white space to be recognized . ex, if you define '{' and '}' as a pair of folding symbol, the following code will be treated as folding block :

        { if (toto == 0)
          return -1; }

        but not for the folloing case, because there's no space between '{' and 'if' :

        {if (toto == 0)
          return -1;}

        hope the information is helpful for you

        Don

         
        • Nobody/Anonymous

          Hi Don,

          Is there a way to tell N++ to treat this as a folding block :
          {if (toto == 0)
          return -1;}

          Up till now, I have not found a solution for this. Maybe this should become an option to N++.

          Thanks for the work !

          Regards,

          Laurent

           
          • Don HO

            Don HO - 2005-05-26

            No, there's no solution yet.
            I'll try to work on it as I have time.

            Don

             
    • Nobody/Anonymous

      Hi Don and all,

      Or is it ok to define another set of folding keywords which only scan the comment section? If this can be implemented, the marker-based folding will be available at once.

      I think we all enjoy the benefits of folding as described in
      http://www.nyangau.fsnet.co.uk/ae/folding.htm

       
    • Nobody/Anonymous

      Hi Don,

      Maybe I should give you a detailed examples in the first post.

      For example in C

      /*
      C_FUNCTION: function_A - a dummy function
      */
      function_A()
      {
      printf ("hello world\n");
      }
      /*
      C_FUNCTION_END
      */

      /*
      C_FUNCTION: function_B - another dummy function
      */

      function_B()
      {
      printf ("hello world\n");
      }
      /*
      C_FUNCTION_END
      */

      At present npp folds the blocks in function_A and function B and also the comments. It is ok as npp folds based on the syntax of the C language. It is syntax folding.

      I just wonder if there is no folding on comment, and instead, folding on the tag C_FUNCTION and C_FUNCTION_END as start and end tag (which can be redefine by any developer). The 'folded' code may be like this...

      /*
      C_FUNCTION: function_A - a dummy function
      */

      /*
      C_FUNCTION: function_B - another dummy function
      */

      And when the fold mark (the plus sign) clicked, the section of the code unfolds. As the tags placed as markers for higher level of abstraction, this kind of folding is called marker-based folding.

      This may not be useful for code with small size. However, it can really help if there several thousands line of codes. It can help developer to organize and understand code in more logical way.

      Herman (and sorry for not giving my name here)

       
      • Don HO

        Don HO - 2005-05-24

        It's more clear for me now ;)

        In this case, User Language Define System won't meet your need at all. You need a specific lexer for Scintilla.
        (AFAIK, niether SciTE nor Scintilla supports mark-based folding feature).
        The lexer in question should recognize /*.+*/ (RegEx) as fold open symbol and '}' as fold close symbol.

        It's realizable, but quite difficult to implemented it (and I won't do it).

        Don

         
    • Nobody/Anonymous

      I think there is a solution for you. I'm using NPP for editing AutoHotKEy scripts and liked the idea of being able to fold sections of the text.

      To achieve this end I added ;REGION to start a fold and ;END_REGION to end the fold in the user-language define system.

      In case of AutoHotKey the semicolon denotes a comment. So you have to substitute it with whatever character denotes a comment in your case. But since these "comments" are defined as keywords for folding you can give them different colors to distinguish them from "real" comments.