Custom Api highlighting (for Lua. And other languages?)



  • I have been trying to add some additional highlighting for a specific Lua API keywords. I found that doing the following mostly works:

    1. In langs.xml in the “lua” Language node I can add
      <Keywords name=“type3”>[Keywords from api 1]</Keywords>
      <Keywords name=“type4”>[Keywords from api 2]</Keywords>

    2. In stylers.xml in the “lua” LexerType node I can add
      <WordsStyle name=“API 1” styleID=“16” fgColor=“FF0000” bgColor=“FFFFFF” fontName="" fontStyle=“2” fontSize="" keywordClass=“type3” />
      <WordsStyle name=“API 2” styleID=“17” fgColor=“0000FF” bgColor=“FFFFFF” fontName="" fontStyle=“4” fontSize="" keywordClass=“type4” />

    Doing the above makes the new highlighting options and related keywords to appear under “Settings/Style Configurator/Lua”.

    PROBLEM: These new keywords are never actually highlighted properly. Looking in the source code this SHOULD work in the Lua lexer everywhere except a single line in the file PowerEditor/src/ScitillaComponent/ScintillaEditView.h, line 708, only a max of four lists are hardcoded to be read:

    setLexer(SCLEX_LUA, L_LUA, LIST_0 | LIST_1 | LIST_2 | LIST_3);

    If it were changed to

    setLexer(SCLEX_LUA, L_LUA, LIST_0 | LIST_1 | LIST_2 | LIST_3|LIST_4|LIST_5);

    then I think it would work. I haven’t compiled it to see because I really don’t want to customize NPP at that level (yet) and have to continually add that feature after future updates to NPP.

    Can such a thing be added to NPP? I can see that similar things occur with many of the built-in lexers. It would be nice if there were a more general way across the board to add new highlighting styles and keywords easily added by a user or through the Style Configurator itself.

    I know there are workarounds such as

    • re-using existing keyword groups and adding user keywords to them. But then you can’t differentiate highlighting between default keywords and the “new” keywords.
    • Creating a user defined language with the desired keywords and highlighting. But then you have to re-implement all the default languages features as well and might not be able to duplicate some of the nuances that are in the scintilla lexer.

Log in to reply