• Login
Community
  • Login

UDL folding closer questions

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
udl foldingudludl
11 Posts 4 Posters 1.3k 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.
  • S
    SBICNCUser
    last edited by Mar 1, 2022, 7:06 PM

    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:

    e6f5e210-a441-45f4-b49f-53ced0a535fb-image.png

    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?

    Thanks

    A P 2 Replies Last reply Mar 1, 2022, 7:12 PM Reply Quote 0
    • A
      Alan Kilborn @SBICNCUser
      last edited by Alan Kilborn Mar 1, 2022, 7:12 PM Mar 1, 2022, 7:12 PM

      @sbicncuser

      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.

      S 1 Reply Last reply Mar 1, 2022, 8:06 PM Reply Quote 0
      • P
        PeterJones @SBICNCUser
        last edited by Mar 1, 2022, 7:40 PM

        @sbicncuser ,

        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 0x)

        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 \b for word boundaries, so CLASSLESS will not match) and for the end expression (in your case, r'\h0\h to 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.

        P 1 Reply Last reply Mar 1, 2022, 8:06 PM Reply Quote 1
        • S
          SBICNCUser @Alan Kilborn
          last edited by Mar 1, 2022, 8:06 PM

          @alan-kilborn That is for LISP scripting within AutoCAD.

          @PeterJones Thanks for the help. At that point I might as well move on to implementing this in an IDE so I’ll see what I can do in JetBrains or Visual Studio.

          A P 2 Replies Last reply Mar 1, 2022, 8:17 PM Reply Quote 0
          • P
            PeterJones @PeterJones
            last edited by Mar 1, 2022, 8:06 PM

            @SBICNCUser ,

            Alternately, if CLASSes are always within SECTIONs, you might be able to get away with CLASS as 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
            
            ccb893a3-1351-4950-bbff-d44fb471b52d-image.png d2c2b266-505c-4a35-a1a0-02ccd48eafd2-image.png
            S 1 Reply Last reply Mar 1, 2022, 10:15 PM Reply Quote 2
            • A
              Alan Kilborn @SBICNCUser
              last edited by Mar 1, 2022, 8:17 PM

              @sbicncuser said in UDL folding closer questions:

              @alan-kilborn That is for LISP scripting within AutoCAD.

              Ah, OK, sorry, no idea about anything UDL/AutoCAD/LISP, although before berate me, my other Notepad++ knowledge is pretty good. :-)

              1 Reply Last reply Reply Quote 1
              • P
                PeterJones @SBICNCUser
                last edited by Mar 1, 2022, 8:30 PM

                @sbicncuser said in UDL folding closer questions:

                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.
                1 Reply Last reply Reply Quote 1
                • S
                  SBICNCUser @PeterJones
                  last edited by Mar 1, 2022, 10:15 PM

                  @peterjones Unfortunately that breaks collapsing the section with all the classes within it.

                  P 1 Reply Last reply Mar 1, 2022, 10:22 PM Reply Quote 0
                  • P
                    PeterJones @SBICNCUser
                    last edited by PeterJones Mar 1, 2022, 10:22 PM Mar 1, 2022, 10:22 PM

                    @sbicncuser ,

                    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.

                    S R 2 Replies Last reply Mar 1, 2022, 10:33 PM Reply Quote 1
                    • S
                      SBICNCUser @PeterJones
                      last edited by Mar 1, 2022, 10:33 PM

                      @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.

                      1 Reply Last reply Reply Quote 0
                      • R
                        rinzwind5 @PeterJones
                        last edited by about 15 hours ago

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