• Login
Community
  • Login

How do I create a new User Defined Language "based on" an existing one ?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
13 Posts 3 Posters 5.2k 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.
  • C
    Chal Chinehsoyo @PeterJones
    last edited by Chal Chinehsoyo Jul 23, 2022, 4:42 PM Jul 23, 2022, 4:41 PM

    @PeterJones thanks… really I’d just like to change certain colours in the C++ one.
    But there seems to be no way of doing that, like you can in the User Defined Language section. Is there?

    P 1 Reply Last reply Jul 23, 2022, 5:09 PM Reply Quote 0
    • P
      PeterJones @Chal Chinehsoyo
      last edited by PeterJones Jul 23, 2022, 5:09 PM Jul 23, 2022, 5:09 PM

      @Chal-Chinehsoyo ,

      The Settings > Style Configurator is where you set the per-language colors for any of the builtin lexer languages.

      C 2 Replies Last reply Jul 23, 2022, 11:07 PM Reply Quote 3
      • C
        Chal Chinehsoyo @PeterJones
        last edited by Jul 23, 2022, 11:07 PM

        @PeterJones ah ok, that makes sense thanks

        1 Reply Last reply Reply Quote 0
        • C
          Chal Chinehsoyo @PeterJones
          last edited by Chal Chinehsoyo Jul 25, 2022, 3:09 PM Jul 25, 2022, 3:07 PM

          @PeterJones said in How do I create a new User Defined Language "based on" an existing one ?:

          @Chal-Chinehsoyo ,

          The Settings > Style Configurator is where you set the per-language colors for any of the builtin lexer languages.

          I’ve settled with using C++ language.
          But, is there anyway to change this Style’s colours? Is there a file in the resources directories I can edit somehow?
          Is it C:\Program Files\Notepad++\stylers.model.xml ?

          Also, is it possible in Notepad++ to tell it to change the colour of any word beginning with “M_” for example.

          Or the colour of the word following, for example, "void " ?

          P 1 Reply Last reply Jul 25, 2022, 3:28 PM Reply Quote 0
          • P
            PeterJones @Chal Chinehsoyo
            last edited by PeterJones Jul 25, 2022, 3:29 PM Jul 25, 2022, 3:28 PM

            @Chal-Chinehsoyo

            But, is there anyway to change this Style’s colours?

            Yes, using the Style Configurator, as I said. Use this dialog, with C++ selected on the left, and cycle through all the entries in the Style column and edit the Colour Style for any that you want to change.
            0d990290-1eb1-4992-b971-718b160b0017-image.png

            Or if you really want to punish yourself by editing the raw XML, you can edit %AppData%\Notepad++\stylers.xml if you have the default style selected – though you will need to follow the Editing Configuration File advice in the Online User Manual if you want to do that. (Your location for that file may be different, depending on your configuration )

            Is it C:\Program Files\Notepad++\stylers.model.xml ?

            That is the default version of stylers.xml that Notepad++ will copy into %AppData%\Notepad++\stylers.xml(or equivalent) if it doesn’t find stylers.xml in the right place. Changing that file will not help if you already have a copy of stylers.xml in the right place, because changes to stylers.model.xml do not automatically propagate to stylers.xml.

            Also, is it possible in Notepad++ to tell it to change the colour of any word beginning with “M_” for example.
            Or the colour of the word following, for example, "void " ?

            Not without a plugin. The Enhance Any Lexer would allow you to specify colors in GBR format (0xGGBBRR) on the left of the equals and a regex for what. The following configuration for EnhanceAnyLexer will make M_... be red and the word after void be blue, in addition to the styles that the C++ lexer already applies.

            [c++]
            0x0000FF = M_\w+
            0x00FF00 = (?<=void\h+)\w+
            
            C 1 Reply Last reply Jul 25, 2022, 5:31 PM Reply Quote 2
            • C
              Chal Chinehsoyo @PeterJones
              last edited by Jul 25, 2022, 5:31 PM

              @PeterJones said in How do I create a new User Defined Language "based on" an existing one ?:

              [c++]
              0x0000FF = M_\w+
              0x00FF00 = (?<=void\h+)\w+

              Great, thats working for me : )
              I changed the colour of the word as you described above.
              Is there anyway of making it bold ?

              P 1 Reply Last reply Jul 25, 2022, 6:17 PM Reply Quote 0
              • P
                PeterJones @Chal Chinehsoyo
                last edited by Jul 25, 2022, 6:17 PM

                @Chal-Chinehsoyo ,

                The EnhanceAnyLexer will only affect foreground colour. It cannot change background colour; it cannot make matched text bold, italic, or underlined; it cannot change the font size or font name.

                C 1 Reply Last reply Jul 25, 2022, 6:35 PM Reply Quote 1
                • C
                  Chal Chinehsoyo @PeterJones
                  last edited by Jul 25, 2022, 6:35 PM

                  @PeterJones Thanks…
                  This line for void is not working.
                  ;0x00FF00 = (?<=void\h+)\w+

                  Is there a reference guide to the regular expressions and what they mean ? I didn’t see one on his github.

                  P E 2 Replies Last reply Jul 25, 2022, 6:45 PM Reply Quote 0
                  • P
                    PeterJones @Chal Chinehsoyo
                    last edited by PeterJones Jul 25, 2022, 6:46 PM Jul 25, 2022, 6:45 PM

                    @Chal-Chinehsoyo said in How do I create a new User Defined Language "based on" an existing one ?:

                    @PeterJones Thanks…
                    This line for void is not working.
                    ;0x00FF00 = (?<=void\h+)\w+

                    With a semicolon, it won’t , because that comments out that line of the config file. I am assuming you don’t actually have that semicolon there.

                    That said, the reason it didn’t work, even without the semicolon, is because I didn’t try it myself, and I forgot that lookbehinds have to be fixed-length, but \h+ is not fixed-length. If you know it will always be exactly one space, then change the regex to (?<=void\h)\w+ … but if you need to allow any number of spaces or tabs between void and the word, then use void\h+\K\w+ instead; if you want void and the word to also allow linebreaks between (which are valid in c/c++, and even meet some of the style guides out there, though I dislike that style, personally), then void\s+\K\w+ will work. (I tested all three of these before posting, this time).

                    Is there a reference guide to the regular expressions and what they mean ? I didn’t see one on his github.

                    I think that it’s using boost regular expressions, which match what is available to Notepad++, so you can look at the Notepad++ regex docs . But @Ekopalypse can chime in if a different regex library is being used.

                    1 Reply Last reply Reply Quote 2
                    • E
                      Ekopalypse
                      last edited by Jul 26, 2022, 8:28 AM

                      @Chal-Chinehsoyo said in How do I create a new User Defined Language "based on" an existing one ?:

                      ;0x00FF00 = (?<=void\h+)\w+

                      EnhanceAnyLexer uses what Npp uses, there is no own regex implementation.
                      I have been thinking about this problem and will implement a function to notify about invalid regex.
                      I am thinking of something like this

                      94072f3c-bd74-49c7-8397-e4ff2a22abc3-image.png

                      1 Reply Last reply Reply Quote 2
                      • E
                        Ekopalypse @Chal Chinehsoyo
                        last edited by Jul 26, 2022, 7:26 PM

                        @Chal-Chinehsoyo

                        see here for the news :-)

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