Label folding including local labels
When folding routines it would be useful if the local routines are folded too. If I have the following
SetPalette:
lea myimage,a1 ; Image into a1 again to search for the palette
.loop cmp.l #"CMAP",(a1) ; Looking for the colormap
beq .found ; Have we found the colormap
addq #2,a1 ; Not found, move on :)
bra.s .loop
.found addq #8,a1 ; Jump over the header
move.l #SCREEN_DEPTH<<2-1,d7 ; Number of colours in the image
clr.l d4
clr.l d3
clr.l d2
clr.l d1
When folding "SetPalette:" I want it to also fold ".loop" and ".found" and they wont be visible. Otherwise I endup with this
^SetPalette ^.loop ^found
Looks like a good way to do it, but I'm not sure that it is a common way to organize/use labels. It may be more suitable to detect the subroutines to fold it.
This is how the QT framework seems to fold subroutines. It makes sense (to me at least) to hide the local/sub-routines when folding the parent.
I agree to fold subroutines inside the main label is interesting. The question is : is it a common way to name a subroutine stating with a ".", and the main without ? I've seen code written in a different way. So how to know if it is a sub or a main label ?
If the label starts with a ".", in most assemblers that is treated as a local variable (you can have several "." labels named the same as long as they have a non "." label between them). But lots of code exists that don't use it.
So I would say that "." labels is a good starting point.
I would also like a "special" comment syntax for folding, or both ;)
;region Optional text that shows at the folded place
Subroutine
move.l #"DUMM",(a0)+
move.l #"MY C",(a0)+
move.l #"ODE"<<8,(a0)+
;region Nested region
waitformouse
btst.b #6,$bfe001
bne.b
;endregion
rts
;endregion
Maybe something configurable with regexp, like:
- main section start regexp: "^[A-Za-z:-_]+$"
- sub section start regexp: "^.[A-Za-z:-_]+.*$"
- sub section end regexp or new sub section found: "^\srts\s$"
- main section end regexp or new main section found: "" It would work with the comments too.
Hmm, several of my sections ends with a jump to another subroutine like:
jsr (_LVOEnable,a6)
rts
I usally optimize that to:
jmp (_LVOEnable,a6)
You should at least add rte.
I think I would prefere a separate keyword for folding but it is worth a test :)
In you case that would be:
- main section start regexp: "^;region .*$"
- main section end regexp or new main section found: "^;endregion .*$"
With a test to deal with the nested regions.