Function List for language with External Lexer



  • In the past (6.x series npp), I have been able to use the FunctionList feature for a language parsed by the GedcomLexer plugin. This required using the langID=“nn” for the external lexer. At that time it wasn’t possible to associate a parser definition with the language’s file extension - and that appears to still be the case.

    My question is, how does an external lexer plugin determine its langID through the plugin/lexer interface? In general, its value should be L_EXTERNAL plus some offset, but the offset could be affected by loading multiple lexers and if Scintilla adds more languages in the future. The message NPPM_GETBUFFERLANGTYPE seems to do the trick but it requires a BufferID. You would think that the langID would be available somehow to the plugin as a constant.



  • So after digging into this, a solution did materialize. I’ll share it in case someone else may need it some day…

    The message NPPM_GETLANGUAGENAME can be sent to Npp to request the language name string for a value of the LangType enumeration. This enumeration ends with the value L_EXTERNAL which corresponds to the first external lexer. By iterating from L_EXTERNAL to the limit of external lexers (+15), the (non-localized) name of each external lexer is retrieved and compared to the desired lexer’s name - on finding a match the LangType (or langId) is known. If the supplied LangType value exceeds the range of defined lexers, the string “Normal text” is returned as the language name.

    NPPM_GETLANGUAGENAME was added to Npp in version 5.9.3


Log in to reply