Highlight INI files?

Topics: Developer Forum
Mar 23, 2014 at 5:15 AM
Edited Mar 23, 2014 at 3:33 PM

In the SCide comments it is said that "SciLexer.DLL already has an INI capable lexer". So the SCide.IniLexer class apparently duplicates this lexer and is included just as a sample, I guess. My question is: how can we use that "INI capable lexer" that is already included in SciLexer.DLL? A code sample would be appreciated!

Thank you.

UPD: I loaded a sample INI-file into SCide document (C:\Windows\msdfmap.ini) and noticed that highlighting doesn't work as expected: some lines are highlighted and some are not, and the latter become highlighted only if I click on such line (several clicks are needed for some lines). Seems to be a repaint issue. Is it related to the current SCide.IniLexer implementation? or to the native Scintilla library? Can we fix it?
Mar 26, 2014 at 12:48 AM
The native Scintilla lexer for INI files is called "properties" or "props". In the Scintilla header file it is defined as:
I apologize that I don't know the exact API to call off the top of my head, but something within the Scintilla.Lexer class will let you specify the "properties" or "props" or "9" lexer. You'll then need to manually set the appropriate styles based on these style indexes:
#define SCE_PROPS_KEY 5
Mar 26, 2014 at 4:46 AM
Thank You!

I disabled usage of the SCide.IniLexer class and this code works fine with the built-in lexer:
public static class ScintillaConstants
    public const int SCE_PROPS_DEFAULT = 0;
    public const int SCE_PROPS_COMMENT = 1;
    public const int SCE_PROPS_SECTION = 2;
    public const int SCE_PROPS_ASSIGNMENT = 3;
    public const int SCE_PROPS_DEFVAL = 4;
    public const int SCE_PROPS_KEY = 5;

// ...

// (here editor is instance of the Scintilla editor component)
editor.Lexing.Lexer = ScintillaNET.Lexer.Properties;
editor.Styles[ScintillaConstants.SCE_PROPS_KEY].ForeColor = Color.FromArgb(0, 0, 153);
editor.Styles[ScintillaConstants.SCE_PROPS_ASSIGNMENT].ForeColor = Color.OrangeRed;
editor.Styles[ScintillaConstants.SCE_PROPS_DEFVAL].ForeColor = Color.FromArgb(102, 0, 102);
editor.Styles[ScintillaConstants.SCE_PROPS_COMMENT].ForeColor = Color.DarkGreen; // Color.FromArgb(102, 102, 102);
editor.Styles[ScintillaConstants.SCE_PROPS_SECTION].ForeColor = Color.DarkRed; // Color.FromArgb(0, 0, 102);
editor.Styles[ScintillaConstants.SCE_PROPS_SECTION].Bold = true;
The only drawback is that the native "Properties" lexer has no "quoted style" defined :(