Scintilla icon Add an external lexer to SciTE

Lexer addition.

This document assumes you know how to create a lexer.  It only covers information specific to making the changes necessary for that lexer to work as an external lexer.

The lexer must export 4 functions (On Windows, it is necessary to create a module definition file to export the symbols correctly).  Below are the proto-types for those functions (ExternalLexer.h must be included so that EXT_LEXER_DECL can be resolved):

void EXT_LEXER_DECL Lex(unsigned int lexer, unsigned int startPos, int length, int initStyle, char *words[],
    WindowID window, char *props);
int EXT_LEXER_DECL GetLexerCount();
void EXT_LEXER_DECL GetLexerName(unsigned int Index, char *name, int buflength);
void EXT_LEXER_DECL Fold(unsigned int lexer, unsigned int startPos, int length, int initStyle, char *words[],
    WindowID window, char *props);

Lex - This function is called whenever lexing needs to be done.  The first thing you may notice is the lack of an Accessor object to style with.  A WindowAccessor object can be created from the WindowID and props objects.  A PropSet object must be created from props, first, then that PropSet and the WindowID are used to create a WindowAccessor.  You will also need to create your own WordList.  (The last row in the words array is a NULL pointer, so you can safely read 1 past the last row to determine how many rows there are).  Once you have the WordList and Accessor, you can pass them to your lexing function just like using a built-in lexer.  The only other difference is you need to call Accessor::Flush() sometime before Lex returns, or not all text may be updated.  This is due to Scintilla's buffering.

GetLexerCount - This returns the number of individual lexers you want to export from your module.

GetLexerName - Fill in the name field with the name of the lexer.  This is how it is later identified in SciTE properties.

Fold - The function called whenever SciTE requests folding be performed.  The same information found in Lex for creating a WindowAccessor apply here, too.