1

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?
Ray
  • 7,940
  • 7
  • 58
  • 90

1 Answers1

3

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

miroxlav
  • 11,796
  • 5
  • 58
  • 99
  • Thanks for the answer after such a long time and the background info on UDL / built-in languages, I'll look further into those :) – Ray Apr 10 '14 at 11:30
  • 1
    @PacMani - I have looked into them today - check directory ` \scintilla\lexers\ ` in Notepad++ source archive. In contains lexer files; token detection is handled also procedurally, not only declaratively. This means you have infinite possibilities to implement what you need and build your own N++. Good luck :) (Or maybe you can also have a look at *SynWrite* as I added few days ago at the end of my answer.) – miroxlav Apr 11 '14 at 23:02
  • Great stuff! Looking into it now :) – Ray Apr 12 '14 at 06:31