How to add a custom language?

Feb 26, 2008 at 8:55 PM

how to add a custom language in 2.0 ?
I created a folder named "cfg", then I copied the xml-file "cs.xml" from the built-in folder to my "cfg" folder and renamed it to "cx.xml" (for testing).
Now I changed the language-tag within the xml-file to "language Name='cx'".
In the scintilla control properties under ConfigurationManager I entered "cfg" to "CustomLocation" and I entered "cx" in the language field.
But it is not loaded. Why not?
Feb 26, 2008 at 9:58 PM
Edited Feb 26, 2008 at 10:00 PM
The custom location has to be an absolute path. This isn't ideal for ease of use so there's actually two things I'll be changing. 1 is making the customlocation a relative path to the executing assembly. 2 right now the custom location must be a folder path, and the configuration manager always tries to load (language name).xml. This should allow a file to be specified as well for maximum flexability.

Also you need to add the LexerName="cs" attribute to the Lexer element. See for more info.
Feb 26, 2008 at 10:32 PM
Changeset 30972 has the above changes. Note that if you want the relative path to work in Visual Studio you have to mark your config file to Copy to Output Folder. Otherwise since the executing assembly is in bin/debug ScintillaNET won't find your file.
Feb 27, 2008 at 12:11 PM
Thank you.
Feb 27, 2008 at 5:24 PM
Edited Feb 27, 2008 at 5:54 PM
I still have problems with it.
If I enter a path and name which is not existing in the CustomLocation field - I entered "cfg\cb.xml" - I don't get any error message.
There is happening just ... nothing

Oh ... I have it. But...
I don't get what you mean with that:

3. As a path relative to the executing assembly, including filename. The executing assembly's base path is prepended to the path.

It seems it not working for me - can you post an example please?

EDIT: The complete thing isn't working for me.
I just copied the cs.xml from the 2.0 branch to my Cfg directory, renamed it to cx.xml.
then I changed the language-tag to language="cx"
I inserted the LexerName="cpp" as stated in the post you linked.

Now I thought, there must have been keywords such as "break;" highlighted, but nothing happens.

EDIT2: Oh, I see.
I set the property "IsBuildInEnabled" to "false". then it isn't working.
What is that property used for?

And please explain the point 3 I stated above.

And another question: How can I change the colors for the cpp-lexer?
The keywords are always blue and teal.


Feb 28, 2008 at 6:55 AM
Edited Feb 28, 2008 at 7:03 AM
This is another big topic that I'll try and cover briefly:

I don't get what you mean with that:
can you post an example please?

This means that say you have your project located at c:\ScintillaNetTest. When you compile and debug your exe will be

If you set CustomLocation to cfg\cx.xml, it will try to load the following files in order. The first one that it finds, wins.
  1. cfg\cx.xml
  2. cfg\cx.xml\cx.xml
  3. c:\ScintillaNetTest\bin\debug\cfg\cx.xml
  4. c:\ScintillaNetTest\bin\debug\cfg\cx.xml\cx.xml

Now obviously from above only #3 has a chance of working. It means that c:\ScintillaNetTest\bin\debug\cfg\cx.xml has to exist. If none are found a FileNotFoundException is thrown. So if nothing happens you know that it's not because it couldn't find the file.

I just copied the cs.xml from the 2.0 branch to my Cfg directory, renamed it to cx.xml.
then I changed the language-tag to language="cx"
I inserted the LexerName="cpp" as stated in the post you linked.

Now I thought, there must have been keywords such as "break;" highlighted, but nothing happens.

Sounds like it should work. Zip up your project and email it to me ( and I'll take a look.

EDIT2: Oh, I see.
I set the property "IsBuildInEnabled" to "false". then it isn't working.
What is that property used for?

There are 3 layers of configuration: BuiltIn, User, and Custom.
Each layer can override a setting of the one before it. This allows for both ease of use and extreme flexibility. By default the configs are loaded in this order: BuiltIn, User, then Custom. BuiltIn configs are the configurations inside the ScintillaNet project under Configuration/builtIn. They are provided as default configurations for each language. The next level is User. This allows the user to specify their defaults for ALL ScintillaNET applications. These files are located under (user's application data folder)\ScintillaNET\(ScintillaNET version). So for instance say that for every ScintillaNET application I want my default font to be Consolas when the cpp language is loaded. All I have to do is drop a cpp.xml file in the said folder and it will automatically override the built in configuration. What's more is that I don't have to specify all the same values as the builtin cpp.xml, instead all I have to do is specify the style I want to change. The third and final level is the Custom. This is the developer specified configuration and has the highest precedence. All configs specified in this file override any of the other applied configs. Again since the configs are "inherited", only the items you want different from the built in config needs to be changed. This is why its both easy and powerful. Of course the order can be swapped around with the ConfigurationLoadOrder property. Also each level has an Is(level)Enabled that can suppress that level from loading.

And another question: How can I change the colors for the cpp-lexer?
The keywords are always blue and teal.

You've probably noticed that in cs.xml that there are no style definitions, yet the colors still seem to magically appear. Well this is because there is another set of inherited configuration that gets loaded, and thats the "default" configuration. For every language specific configuration that's loaded a default is also loaded. That means that when you set Configuration.Language="cx", the following configs are loaded (if they exist, most won't)
  1. BuiltIn/default.xml (exists)
  2. BuiltIn/cx.xml (doesn't exist)
  3. User/default.xml (doesn't exist unless you put it there)
  4. User/cx.xml (doesn't exist unless you put it there)
  5. Custom Location/default.xml (doesn't exist unless you put it there)
  6. Custom Location/cx.xml (exists because I know you put it there)

Now if you open builtin/default.xml you'll see A LOT of style elements. Now the thing is each lexer defines it's own set of named styles. Some of them are common like "number", "Keyword", and "comment". The list of styles defined by each lexer can be found under Confguration.BuiltIn/LexerStyleNames/(lexer).xml. So for instance cpp defines the following styles
WORD = 5
UUID = 8
REGEX = 14
WORD2 = 16

So it seems the two styles you want to change are WORD and WORD2. In know they aren't the most intuitive names, They are taken from the lexer files themselves, but I may end up going through and changing a lot of them to make them more consistent. Anyhow what you need to do in your config is to add the following:
<Style Name="WORD" ForeColor="red"/>
<Style Name="WORD2" ForeColor="Yellow"/>
Of Course substituting the style values with what you want.
Mar 4, 2008 at 7:47 PM
Thank you for your detailed answer.
One question I still have.

Is it possible to change the style at runtime, let's say to give the user a possibility to configure the styles?
Mar 4, 2008 at 11:33 PM
Yes, use the Styles property.
Apr 22, 2008 at 5:08 PM
Do you have an example? Because, I only see BraceBad, BraceLight, CallTip, ControlChar, Default, IndentGuide, LastPredefined, LineNumber, and Max. How do I change "COMMENT"'s forecolor at runtime without hardcoding in the xml?

Also, do you notice when you set the following initially, subsequent change to "cs" will not cause the syntax highlight to work?

if I have this:
sciDocument.ConfigurationManager.Language = "";

I can't do this, everything stays as default.
sciDocument.ConfigurationManager.Language = "cs";

even with calling ClearStyle before setting it.

ChrisRickard wrote:
Yes, use the Styles property.

May 22, 2008 at 10:05 PM
This post is responding to my previous post about changing either foreground or background color during runtime without creating a xml in Scintilla 2.0. What I did was I created a public interface SetStyleFore and SetStyleBack in ScintillaControl.cs so that my control could talk to it. 

public void SetStyleFore(int styleNumber, Color color)
   NativeInterface.StyleSetFore(styleNumber, Utilities.ColorToRgb(color);

Using the enumeration from builtin\cpp.txt (or refer to ChrisRickard's previous post) where COMMENT = 1, CONSTANT =5, etc. You can directly set the color during runtime.  Basically, it does another layer paint over the default language you set. 

From my control, I call the follow to change the color:

sciDocument.SetStyleFore(1, newCommentColor);
sciDocument.SetStyleFore(5, newConstantColor);

I don't know if this is a correct way to do it but it does what I need to do and it's pretty cool!!!

Jul 25, 2008 at 3:29 PM
The built in equivelant is
sciDocument.Styles[styleNumber].ForeColor = Color.SomeColor;
Aug 2, 2010 at 12:20 AM


I am also using the same lexer (cpp) and the same language (cs), but I need to have a third group of keywords, with a different color.

I've seen that WORD and WORD2 are Keyword1 and Keyword2 respectively, but can't find a way to add a third group.

Can you please help me?



Aug 2, 2010 at 4:43 PM

Each of the keyword lists are determined by the lexer code itself. You would have to modify Scintilla's built in cpp lexer to handle the new list. That means downloading/modifying/building SciLexer from the Scintilla source then replacing the SciLexer in use by ScintillaNet. If you're up to it I can provide some guidance, but this is mostly outside the realm of ScintillaNet.