• Login
Community
  • Login

User Defined language more folding in code styles

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 2.4k 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.
  • D
    denwitham
    last edited by denwitham Jan 29, 2023, 6:37 PM Jan 29, 2023, 5:36 PM

    I have writen a user defined Language highligher using the built in editor
    Language > User Defined Language > Define your language

    how do you do more than two folding code styles and one comment folding style ?

    My language has at least 3 if, foreach and switch and has a multiline comment fold style

    I have tried editing the xml and adding in
    <Keywords name=“Folders in code3, open”>Switch:</Keywords>
    <Keywords name=“Folders in code3, middle”>Case:</Keywords>
    <Keywords name=“Folders in code3, close”>EndSwitch:</Keywords>
    but that just gets ignored / removed

    Additionally how do you add more than one middle ?
    e.g.
    if / elsif / else / endif
    switch / case / default / endswitch

    P 1 Reply Last reply Jan 29, 2023, 9:30 PM Reply Quote 0
    • P
      PeterJones @denwitham
      last edited by Jan 29, 2023, 9:30 PM

      @denwitham said in User Defined language more folding in code styles:

      I have tried editing the xml and adding in …

      You cannot just add new structures in the UDL XML definition and hope that Notepad++ would just magically understand what you meant.

      how do you do more than two folding code styles and one comment folding style

      You can mix multiple fold structures of the same type in the same boxes.

      Folding in Code 1 is meant for things that fold that don’t require spaces surrounding it – so the c-style { … } folding would be a primary use case for FiC1.

      Folding in Code 2 is meant for things that fold that do require spaces, like words, so that it will fold on “if” but not “gif” or “iffy”. So if / else elsif / endif would be one such set.

      6dfc8cc0-2e34-4bd5-aa54-04eb58199010-image.png

      Folding in Comments is intended as a way to add a prompt inside a comment that will do folding. for example, =begin and =end as FoldingInComment with comment prefix of #:
      ed3deb6b-1b44-4947-b268-cf76aa8a02d3-image.png

      With multiple in the same box, like the if and switch constructs, you could technically trick N++ into doing folding on invalid combinations, like if / case / endswitch or switch / else / endif . So it’s imperfect, but N++ UDL isn’t meant as a code validator, and won’t enforce valid syntax.

      b200eee8-e37c-4562-bb66-b0961c405315-image.png

      But since most languages require fully nested, most combinations will fold the way you expect:

      a95db7b2-18ec-47b0-86d0-74d016717fc6-image.png

      You will notice that I earlier had a space between the default and the :, because in FoldingInCode2, spaces are required. If you moved it over to FoldingInCode1, then you wouldn’t need that space:

      9141e0d3-690a-46fa-b334-fd41b95bd00c-image.png

      D 1 Reply Last reply Feb 15, 2023, 4:47 PM Reply Quote 2
      • D
        denwitham @PeterJones
        last edited by Feb 15, 2023, 4:47 PM

        @PeterJones Thank you, just what I was looking for.

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