Scintilla icon Add a lexer to Scintilla and SciTE

Lexer addition.

The process of adding a new lexer to both Scintilla and SciTE is fairly long. Here is my response when asked how to add a lexer for Apache CONF files to SciTE. There is more information on writing the lexer code (steps 4 and 5, here) in the documentation for Scintilla.

Don't bother about steps which are for configurations you don't use all 6 makefiles - I'll patch them up later if you want to contribute the lexer.

  1. In scintilla/include/Scintilla.iface, add a lexer ID value:
    val SCLEX_CONF=17
  2. And any lexical class IDs:
  3. In the scintilla/scripts directory run to regenerate the SciLexer.h file. Alternatively (if you don't want to run a Python script) just add these values to SciLexer.h as #defines and I'll put them in Scintilla.iface.
  4. In the scintilla/src/LexOthers.cxx write a ColouriseConfDoc function similar to one of the other functions such as ColouriseLatexDoc.
    static void ColouriseConfDoc (unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler) {
  5. At the end of the file associate the lexer ID and name with the function:
    LexerModule lmConf(SCLEX_CONF, ColouriseConfDoc, "conf");
  6. If this is a complex lexer then it may be better off in its own file, in which case clone one of the current files. In the scite/scripts directory run to add the new lexer file to each make file.
  7. To the scite/src/ add an entry to associate the file extension with the lexer:
    If a new lexer file was created instead of adding to LexOthers, then a new properties file should be created by cloning scite/src/ and modifying that file in the following steps.
  8. Set up the styles:
    # Default
    # Comment
  9. A filter should be added for conf files in scite/src/ filter.conf=Configuration (.conf)|*.conf|
  10. In scite/src/ add $(filter.conf) to the definition of open.filter.
  11. To add this language to the Language menu of SciTE, add an entry to the menu.language property including the name of the language and the file extension used most commonly for it.
  12. Build both Scintilla and SciTE.
  13. Share and enjoy

For more extensive information on building lexers, see the instructions in the Scintilla documentation.