CustomStyle.lua example file
--[[ An example fileproc clip(int a)« Clip into the positive zone »if (a > 0) a0end ]]-- Define style numbersS_DEFAULT=0S_IDENTIFIER=1S_KEYWORD=2S_UNICODECOMMENT=3-- Anytime a file is switched, check to see if it needs stylednpp.AddEventHandler("OnSwitchFile", function(filename, bufferid)
ifnpp:GetExtPart() ==".abc" then-- Add the event handler for our custom style functionnpp.AddEventHandler("OnStyle", CustomStyle)
-- Make sure to set the lexer as a custom containereditor.Lexer=SCLEX_CONTAINER-- Set up the styles as appropriateeditor.StyleFore[S_DEFAULT] =0x7f007feditor.StyleBold[S_DEFAULT] =trueeditor.StyleFore[S_IDENTIFIER] =0x000000editor.StyleFore[S_KEYWORD] =0x800000editor.StyleBold[S_KEYWORD] =trueeditor.StyleFore[S_UNICODECOMMENT] =0x008000editor.StyleFont[S_UNICODECOMMENT] ="Georgia"editor.StyleItalic[S_UNICODECOMMENT] =trueeditor.StyleSize[S_UNICODECOMMENT] =9-- Clear any style and re-lex the entire documenteditor:ClearDocumentStyle()
editor:Colourise(0, -1)
else-- Can remove the handler if it's not needednpp.RemoveEventHandler("OnStyle", CustomStyle)
endreturnfalseend)
-- Style the document. Handles UTF-8 charactersfunctionCustomStyle(styler)
identifierCharacters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"styler:StartStyling(styler.startPos, styler.lengthDoc, styler.initStyle)
whilestyler:More() do-- Exit state if neededifstyler:State() ==S_IDENTIFIERthenifnotidentifierCharacters:find(styler:Current(), 1, true) thenidentifier=styler:Token()
ifidentifier=="if" oridentifier=="end" thenstyler:ChangeState(S_KEYWORD)
endstyler:SetState(S_DEFAULT)
endelseifstyler:State() ==S_UNICODECOMMENTthenifstyler:Match("»") thenstyler:ForwardSetState(S_DEFAULT)
endend-- Enter state if neededifstyler:State() ==S_DEFAULTthenifstyler:Match("«") thenstyler:SetState(S_UNICODECOMMENT)
elseifidentifierCharacters:find(styler:Current(), 1, true) thenstyler:SetState(S_IDENTIFIER)
endendstyler:Forward()
endstyler:EndStyling()
end- This source defines a function for callback
OnSwitchFile. It declares to call CustomStyle for the event OnStyle if the file extension is abc. - My understanding is that
editor:Colourise(0, -1) should lead to invocation of callback OnStyle. - Handling the callback
OnStyle and thus calling CustomStyle should colorize the document as a consequence. - By adding
print() statements and opening the Lua Console, one can observe which functions are actually run.
Expected behavior:
- Callback
OnSwitchFile is handled. - Callback
OnStyle is handled.
Actual behavior:
- Callback
OnSwitchFile is handled. - Callback
OnStyle is never handled, thus the function CustomStyle is never called.
This can be confirmed by the resulting styling. The given example document (stored with a filepath ending with .abc) leads to the following coloring:

This coloring (every foreground text color is purple) can be explained by the editor.StyleFore[S_DEFAULT] = 0x7f007f which is run and sets the default color to purple. But the actual styling function CustomStyle is not run.
Environment:
- Windows 10
- LuaScript v0.12 (64 bit). Lua 5.3.5
- Seems like the OnStyle handling should be triggered here but SCN_STYLENEEDED does not seem to be a received Scintilla notification.
CustomStyle.lua example file
OnSwitchFile. It declares to callCustomStylefor the eventOnStyleif the file extension isabc.editor:Colourise(0, -1)should lead to invocation of callbackOnStyle.OnStyleand thus callingCustomStyleshould colorize the document as a consequence.print()statements and opening the Lua Console, one can observe which functions are actually run.Expected behavior:
OnSwitchFileis handled.OnStyleis handled.Actual behavior:
OnSwitchFileis handled.OnStyleis never handled, thus the functionCustomStyleis never called.This can be confirmed by the resulting styling. The given example document (stored with a filepath ending with
.abc) leads to the following coloring:This coloring (every foreground text color is purple) can be explained by the
editor.StyleFore[S_DEFAULT] = 0x7f007fwhich is run and sets the default color to purple. But the actual styling functionCustomStyleis not run.Environment: