Community
    • Login

    "Dot Notation" Folding

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    language udlcollapse
    2 Posts 2 Posters 442 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Daniel McMahonD
      Daniel McMahon
      last edited by Daniel McMahon

      I’m trying to get language folding for the below file format…

      O
      .O
      ..O1=Value1
      ..O2=Value2
      ..O3=Value3
      

      The single dot within .O indicates that “O” is a member of “O”.
      The double dot within …O1 (etc.) indicates that “O1” is a member of “O.O”.

      So effectively there are three objects in the example, as below…

      O.O.O1
      O.O.O2
      O.O.O3
      

      How can I get the code to fold (using a custom language) such that collapsing “O” would hide everything below it until there was another letter without any dots preceding it?

      If I added “P” and the file became…

      O
      .O
      ..O1=Value1
      ..O2=Value2
      ..O3=Value3
      P
      .X=Number1
      .Y=Number2
      .Z=Number3
      

      …then “collapsing” the first line/“O” should leave me showing…

      O (<--- COLLAPSED)
      P
      .X=Number1
      .Y=Number2
      .Z=Number3
      

      Thanks if anyone can help with some hints.

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Daniel McMahon
        last edited by

        @Daniel-McMahon said in "Dot Notation" Folding:

        How can I get the code to fold (using a custom language) such that collapsing “O” would hide everything below it

        If O were your only start keyword, then you could define your UserDefinedLanguage with Folding-in-Code-2 with START = O and something else (maybe ((A B C D E F G H I J K L M N O P Q R S T U V W X Y Z))) as the close.

        Actually, using the ((A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)) list shown for both open and close comes close, but not quite, because it’s seeing each one as a new nested open, rather than a close for the previous one.

        The User Defined Language feature is great for “simple” languages, where the folding is just pairs of OPEN/CLOSE keywords or symbols (with optional middle for “if-else-endif”-like situations)… but it’s not hard to find yourself straying beyond what it can handle.

        In theory, you could look at the FAQ section of this Forum, and see the FAQ Desk entry on creating official feature requests … but the UDL system hasn’t had much attention (really, not any attention) for a few years, and nothing is likely to come about from such a feature request, unfortunately.

        The first options at this point are creating your own lexer plugin, which would be able to implement the syntax highlighting and code folding according to whatever rules you want to program.

        The second option is that the scripting plugins like PythonScript have access to the underlying Scintilla folding commands – so you might be able to code up a script that will enable the folding you want; I don’t know if there are examples in the forum, but you could search for “pythonscript fold” or some such and see what you find. (My guess in PythonScript is that editor.setFoldLevel(line, level) which implements scintilla SCI_SETFOLDLEVEL message is where you would start, which would define how many levels deep, and which line is the start of each fold block).

        1 Reply Last reply Reply Quote 2
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors