How do I create a new User Defined Language "based on" an existing one ?
-
I’d like to create a new user defined language based on the exisitng C++ one.
I tried copying the Cpp.xml file and making changes in the header (name etc.) but Notepadd++ didn’t pick that up.How do I do it?
-
Existing lexer languages are a completely different creature than UDL, so you cannot start a UDL from an existing language (like C++).
If you are just wanting to add extra keywords to the C++, use the types that have user-defined boxes in some of their keyword definitions in the Style Configurator.
-
@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? -
The Settings > Style Configurator is where you set the per-language colors for any of the builtin lexer languages.
-
@PeterJones ah ok, that makes sense thanks
-
@PeterJones said in How do I create a new User Defined Language "based on" an existing one ?:
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 " ?
-
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.
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 findstylers.xml
in the right place. Changing that file will not help if you already have a copy ofstylers.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 aftervoid
be blue, in addition to the styles that the C++ lexer already applies.[c++] 0x0000FF = M_\w+ 0x00FF00 = (?<=void\h+)\w+
-
@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 ? -
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.
-
@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.
-
@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 usevoid\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), thenvoid\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.
-
@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 -
see here for the news :-)