UDL folding closer questions
I’m attempting to create a UDL for AutoCAD DXF files to make them more readable. I’m working first on folding. Here is the documentation for the “language” I’m trying to highlight: https://help.autodesk.com/view/OARX/2018/ENU/?guid=GUID-235B22E0-A567-4CF6-92D3-38A2306D73F3
Here is a more digestable summary with example code: https://www.scan2cad.com/blog/dxf/file-specification/
Basically, the parent blocks open with SECTION and end with ENDSEC. My problem is, the child entities that I also want to turn into blocks don’t have clear closers which I can get to work. I want to be able to collapse everything highlighted here:
Collapsing from CLASS to CLASS does not work, and I can’t get " 0" (whitespace whitespace zero" to register as a valid opener or closer.
Note these are CAD files generated to AutoCAD so I cannot control the output.
Is there a way to resolve this?
In a way to avoid answering your direct question (because I don’t know much if anything about UDLs), I’ll ask you if you’ve already checked out the AutoCAD UDL at this site: https://github.com/notepad-plus-plus/userDefinedLanguages/tree/master/UDLs
Maybe it meets your need or answers your question somehow.
Space is a separator, so cannot be part of one of those keywords unless inside quotes. Unfortunately, UDL doesn’t allow just numbers (or, apparently, numbers-with-spaces) as a valid keyword for the folding start/middle/end entries. If you had a non-numeric/non-space character as part of the closing tag, it would work (like
In this post in a topic about adding folding to logfiles, I supplied a script for the PythonScript plugin which would allow you to manually add folding to an existing file – with the caveat that as written, it will not automatically update the folding when you edit the file.
The script allows you to define a regex for the start expression (in your case,
r'\bCLASS\b', using the
\bfor word boundaries, so
CLASSLESSwill not match) and for the end expression (in your case,
r'\h0\hto make it 0 with spaces or tabs before and after).
If you are editing the file, rather than just navigating it, you could just run the script a pair of times each time you want to update the folding to match your edits.
Hmm, unfortunately, as is, it isn’t playing well with having folding defined in the UDL as well. I don’t have time right now to dig into a way to make it work for nested folding, or to cooperate with the normal UDL folding… but in theory, like switching to event-notifications for on-edit re-folding, the user could take the script as a starting point, and study PythonScript, and try to add features that the barebones does not give you.
Alternately, if CLASSes are always within SECTIONs, you might be able to get away with
CLASSas the “middle” of a SECTION:
SECTION 5 CLASS 3 2 1 0 CLASS 10 5 0 100 ENDSEC SECTION 5 CLASS 3 2 1 0 CLASS 10 5 0 100 ENDSEC
That is for LISP scripting within AutoCAD.
There are two AutoCAD-related UDL in the repo:
- https://github.com/notepad-plus-plus/userDefinedLanguages/blob/master/UDLs/AutoLISPforAutoCAD_MichaelPuckett.xml => obviously for LISP scripting of AutoCAD (and based on the syntax, might not even be compatible with modern UDL implementation… interesting)
- https://github.com/notepad-plus-plus/userDefinedLanguages/blob/master/UDLs/AutoCAD-LPSS.udl.xml => per its comments, it handles AutoCAD Linetype (*.lin), Pattern/Hatch (*.pat), Script (*.scr) and Shape (*.shp) files. But it doesn’t define folding, so it wouldn’t help you anyway.
@peterjones Unfortunately that breaks collapsing the section with all the classes within it.
The purpose of UDL was to give users something that gave a “Reasonably Good” syntax highlighting. The intention was that if something went beyond the abilities of UDL, someone would make a Lexer Plugin for that language, which handles all the edge cases that a UDL is incapable of handling. (Or that they’d find that Scintilla already had a lexer for that, and try to get that Scintilla code included in a future release of Notepad++.)
Do you really need to be able to collapse them, or would using the Function List feature of Notepad++ be sufficient to help navigate between the blocks without collapsing them? Because you could make a Function List definition for your UDL, which would (confusingly) set SECTION as the class-header, and CLASS as the function-header; that would allow easy navigation, even if they aren’t collapsed.
Or use my suggestion of “middle”, and use the View > Fold All or similar to fold them all, then just unfold the small section you are actively working in.
@peterjones It becomes a little messy if I can’t collapse sections around the child elements. There are a lot of classes and CLASS isn’t the only entity with this problem.
I’m going to have to decide if that’s good enough or if I need to put more work into this. The whole purpose of this is that I need to start parsing some data from these files programmatically and the structure makes it very difficult to follow. The format doesn’t lend itself well to syntax highlighting.