Community
    • Login

    comment line open with a character and space

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 1.6k 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.
    • jason1820J
      jason1820
      last edited by

      I am trying to create a user defined language syntax where the comment line opens with a letter C and space. I was not able to just type a space after C on the User Define Language dialog box. Can this be done? Thanks!

      1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones
        last edited by

        @jason1820 ,

        Can this be done?

        Unfortunately, not natively (that I can tell). The keywords have the Prefix Mode toggle, which when off requires a space; the operators have the operators 2 which require separators; but there doesn’t appear to be a similar option for comments.

        That said, you can add extra highlighting to a UDL language using regexes via the script EnhanceUDLLexer.py that @Ekopalypse shares in this linked post – so instead of being a “comment”, you could set up that script to highlight lines that match with ^\h*C\h+ (that regex should work, but I haven’t tested it with the script)

        jason1820J 1 Reply Last reply Reply Quote 0
        • jason1820J
          jason1820 @PeterJones
          last edited by

          @PeterJones
          Thank you. I was hoping there was a native solution for simply task like that. regards.

          1 Reply Last reply Reply Quote 0
          • Peter BrandP
            Peter Brand
            last edited by

            Looking at the langs.xml file in NPP configuration folder, I see the commentLine attribute of the langage sometimes uses html entities. Try using "C ".

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Peter Brand
              last edited by

              @Peter-Brand said in comment line open with a character and space:

              Looking at the langs.xml file in NPP configuration folder, I see the commentLine attribute of the langage sometimes uses html entities. Try using “C ”.

              Two problems with that: First, C  would be the non-breaking-space, which wouldn’t be the character that @jason1820 would use; it would be C . Second, that entry doesn’t fully use entities: when I have the following:

                          <Keywords name="Comments">00C&#32; 00C&nbsp; 00&gt;&gt;&gt; 00C&#x00A0; 00C&#xA0; 01 02 03 04</Keywords>
              

              it recognizes the entities for the >>>, but not for the space or NBSP:
              – it treats the &#32; and &nbsp; as literals (so if you have that literal text in your document, it will recognize those as comments), though it seems to recognize &#x00A0; and/or 00C&#xA0; as being something, but doesn’t match them when the NBSP character is present.
              c893f1f7-8b62-418d-9dce-5e5d37666903-image.png

              Reminding myself, the Wikipedia article on character entities points out that XML only has a short list of pre-defined entities, compared to the fuller list of HTML entities: only "&'<> have default XML entities.

              If I expand to more options

                          <Keywords name="Comments">00C&#32; 00C&nbsp; 00&gt;&gt;&gt; 00C&#x00A0; 00C&#x0020; 00C&#xA0; 00C&#x20; 01 02 03 04</Keywords>
              

              It appears to be treating the C&x#20; as C[space], but that then behaves like a normal space is there separating entries, so anything starting with C is commented again.
              b46eb45a-9e2d-4d66-876a-978bb600dd68-image.png

              1 Reply Last reply Reply Quote 0
              • jason1820J
                jason1820
                last edited by

                Thanks @PeterJones and @Peter-Brand. I tried the different options you guys suggested by modifying userDefinedLang.xml. Nothing works exactly like I wanted. BTW, I also tried to modify langs.xml under AppData\Roaming\Notepad++ (to adapt a predefined language for my own) and it appears changes made there commentLine="C " did not take effect - original comment character still works. is that not the file supposed to be changed?

                1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones
                  last edited by

                  @jason1820 said in comment line open with a character and space:

                  langs.xml

                  Sorry, I hadn’t noticed the mention of that file earlier. No, that’s not the right file. UDL syntax highlighting is found in userDefineLangs subfolder (one XML file per UDL) or in the userDefineLang.xml.

                  langs.xml only applies to the builtin syntax highlighter languages, and cannot be adapted to work with a UDL

                  1 Reply Last reply Reply Quote 0
                  • PeterJonesP
                    PeterJones
                    last edited by

                    @jason1820 said in comment line open with a character and space:

                    Nothing works exactly like I wanted.

                    That was actually the point of the experiments I showed; AFAICT, you cannot trick the UDL engine into requiring a space after the comment start sequence.

                    did not take effect

                    Editing NPP config files inside NPP takes a bit of finesse. The best sequence is close all Notepad++ windows, then open one, do the edits, save and exit, then reload for it to take effect. (Not that “adapt[ing] a predefined language for my own” will work; but even a valid change requires that sequence)

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