Skip to content

OnStyle callback is never called (confirmed also in the example file) #108

Description

@meisterluk

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
  1. This source defines a function for callback OnSwitchFile. It declares to call CustomStyle for the event OnStyle if the file extension is abc.
  2. My understanding is that editor:Colourise(0, -1) should lead to invocation of callback OnStyle.
  3. Handling the callback OnStyle and thus calling CustomStyle should colorize the document as a consequence.
  4. By adding print() statements and opening the Lua Console, one can observe which functions are actually run.

Expected behavior:

  1. Callback OnSwitchFile is handled.
  2. Callback OnStyle is handled.

Actual behavior:

  1. Callback OnSwitchFile is handled.
  2. 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:

clip

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions