Search code examples
notepad++

Notepad++ UDL: Problems with folding start and end


I want to fold sections of the following Z80 assembly excerpt correctly, but I can't get it done:

.ORG $9D93
        .DB     t2ByteTok, tAsmCmp

    Increase:
        LD      A, B
        CP      255
        JR      Z, KeyLoop
        INC     B
        JR      Display

    Decrease:
        LD      A, B
        CP      0
        JR      Z, KeyLoop
        DEC     B
        JR      Display

.END

In this excerpt, three folding regions should be created:

  • #1 going from .ORG $9D93 to .END
  • #2 going from "Increase:" to the line before "Decrease:"
  • #3 going from "Decrease:" to the line before ".END"

Two problems with that:

  • I was able to create the first folding by setting the keyword "ORG" as an open token in "Folding in code 1 style" and "END" as the Close token. Funnily enough it doesn't work with ".ORG" and ".END" as a token. E.g. right now it is possible to create a fold if the dot is missing. Do I have to escape the dot in any way?
  • I can't get the second and third fold working at all. I tried to add ":" as the open token, but what to put in the Close token? It would be the line before the next fold starts or ends. How to express that in the UDL?

Solution

  • Please understand that folding is designed to work with pair constructs. Construct

    If (a)
    |
    |    If (b)
    |    |
    |    |    Print
    |    |
    |    End If
    |
    End If
    

    will fold as expected but in your case the evaluation is:

    .ORG $9D93
    |        .DB     t2ByteTok, tAsmCmp
    |
    |    Increase:
    |    |    LD      A, B
    |    |    CP      255
    |    |    JR      Z, KeyLoop
    |    |    INC     B
    |    |    JR      Display
    |    |
    |    ? (NO MATCH)
    |
    |    Decrease:
    |    |    LD      A, B
    |    |    CP      0
    |    |    JR      Z, KeyLoop
    |    |    DEC     B
    |    |    JR      Display
    |    |
    |    ? (NO MATCH)
    |
    .END
    

    Although this is not what you want to achieve, try adding .END this way and you will see all 3 foldings work as expected:

    .ORG $9D93
    |        .DB     t2ByteTok, tAsmCmp
    |
    |    Increase:
    |    |    LD      A, B
    |    |    CP      255
    |    |    JR      Z, KeyLoop
    |    |    INC     B
    |    |    JR      Display
    |    .END
    |
    |    Decrease:
    |    |    LD      A, B
    |    |    CP      0
    |    |    JR      Z, KeyLoop
    |    |    DEC     B
    |    |    JR      Display
    |    .END
    |
    .END
    

    As far as I understand UDL in Notepad++, folding in style suggested in your question is not achievable via UDL. Perhaps it might work in built-in N++ languages which are not bound with simplified UDL logic. For your information UDL is kept simplified intentionally to keep UI and logic manageable for most of people. (I'm not going to search where I recently read it, so sorry for not linking to source of last sentence.)

    Checking inner workings of N++, you might be able to add your own built-in language (not UDL) which will comply with your requirement.

    EDIT: I've found this comment recently: Consider another text editor, SynWrite, which can have lexer of much more flexibility. Just read the lexer tutorials in Synw Readme. – Alextp Oct 25 '13 at 19:46