How to add additional styles to an existing Languages in Style configurator?
-
i’am using the in-build syntax highlighting feature for the lua language. i have written some lua “util” libs with custom functions. In this case i have tried to add a new style “utils” to the existing lua in-build language to get an own colormanagement for these util functions but all trials fails. I tried to modify the “langs.xml / langs.model.xml” and “stylers.xml / stylers.model.xml” and of course i can see a new “utils” entry in the “styles configurator/lua” language but this entry has absolutely no effects…
What i do wrong? How can i add an additional style to the existing in-build lua language?
PS: sry for the double posting, i tried to edit my first question but i can’t find a way to do this.
-
If you want to add new keywords that should be highlighted, you edit
langs.xml
file.
stylers.xml
file contains the colors for the default theme. Custom themes you edit the correct one in /themes dir.
I hope it is what you need. -
no, sorry.
you said: “If you want to add new keywords that should be highlighted, you edit langs.xml file.”
i know that, but if i add my additional keywords to an existing style/category then the keywords using the same color.
Therefore i tried to add a new style/category to use a new/different colormanagement:These are the default styles/categories for the lua language in “stylers.xml”:
DEFAULT
COMMENT
COMMENT LINE
COMMENT DOC
LITERALSTRING
PREPROCESSOR
INSTRUCTION WORD -> using: keywordClass=“instre1”
NUMBER
STRING
CHARACTER
OPERATOR
FUNC1 -> using: keywordClass=“instre2”
FUNC2 -> using: keywordClass=“type1”
FUNC3 -> using: keywordClass=“type2”i tried to add a new one:
EXTRA1 -> my new style, i tried to use: keywordClass=“type3” because some other languages use this too.my additional line:
<WordsStyle name=“EXTRA1” styleID=“20” fgColor=“BFBF00” bgColor=“232C31” fontName=“Lucida Console” fontStyle=“0” fontSize=“” keywordClass=“type3”>and in the “langs.xml” i tried to add this new line:
<Keywords name=“type3”>i add my new keywords here</Keywords>when i restart my n++ then all looks good and my new “EXTRA1” style/category definition is in the list but whatever i try to add it has no effects.
-
Have spent great time looking at this – even inside that hard and dirty Np++ source-code – to no definitive conclusion, but…
I see that in some languages it works a bit better (eg. Javascript), PHP otherwise nothing…
I think
styleID="16"
is a magic number, a style with that id may have effect or not (two with same Id, the later prevails).I could not see any
keywordClass
effect, even though there are functions that supposedly should handle them.getKwClassFromName
reads it, then, it should populate an array:_styleArray[index]._keywordClass = getKwClassFromName(str);
There are many functions to handle each language type, it is very hard to track the order they execute and what they do.
This function for example, seems to allow only “instre1” and “type1” for keywordClass (for the languages it handles):
void ScintillaEditView::setCppLexer(LangType langType) ... if (pKwArray[LANG_INDEX_INSTR]) { basic_string<wchar_t> kwlW = pKwArray[LANG_INDEX_INSTR]; keywordListInstruction = wstring2string(kwlW, CP_ACP); } cppInstrs = getCompleteKeywordList(keywordListInstruction, langType, LANG_INDEX_INSTR); if (pKwArray[LANG_INDEX_TYPE]) { basic_string<wchar_t> kwlW = pKwArray[LANG_INDEX_TYPE]; keywordListType = wstring2string(kwlW, CP_ACP); } cppTypes = getCompleteKeywordList(keywordListType, langType, LANG_INDEX_TYPE);
This one may allow “instre1”,“instre1”,“type1”,“type2” for LUA:
void setLuaLexer() { setLexer(SCLEX_LUA, L_LUA, LIST_0 | LIST_1 | LIST_2 | LIST_3); };
Because we some somewhere else:
if (whichList & LIST_0) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_INSTR], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_INSTR); } if (whichList & LIST_1) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_INSTR2], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_INSTR2); } if (whichList & LIST_2) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_TYPE); } if (whichList & LIST_3) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE2], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_TYPE2); } if (whichList & LIST_4) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE3], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_TYPE3); } if (whichList & LIST_5) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE4], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_TYPE4); } if (whichList & LIST_6) { const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE5], CP_ACP); setKeywords(langType, keyWords_char, LANG_INDEX_TYPE5); }
Appendix
I see that Syntilla lexers¹ use predefined numbers for coloring things (these are the "styleID"s), but I don’t know how they handle unknown keyword list or how they receive it from Np++ (above functions). Eg:
#define SCE_HPHP_COMPLEX_VARIABLE 104 #define SCE_HPHP_DEFAULT 118 #define SCE_HPHP_HSTRING 119 #define SCE_HPHP_SIMPLESTRING 120 #define SCE_HPHP_WORD 121 #define SCE_HPHP_NUMBER 122 #define SCE_HPHP_VARIABLE 123 #define SCE_HPHP_COMMENT 124 #define SCE_HPHP_COMMENTLINE 125 #define SCE_HPHP_HSTRING_VARIABLE 126 #define SCE_HPHP_OPERATOR 127 ... #define SCE_LUA_DEFAULT 0 #define SCE_LUA_COMMENT 1 #define SCE_LUA_COMMENTLINE 2 #define SCE_LUA_COMMENTDOC 3 #define SCE_LUA_NUMBER 4 #define SCE_LUA_WORD 5 #define SCE_LUA_STRING 6 #define SCE_LUA_CHARACTER 7 #define SCE_LUA_LITERALSTRING 8 #define SCE_LUA_PREPROCESSOR 9 #define SCE_LUA_OPERATOR 10 #define SCE_LUA_IDENTIFIER 11 #define SCE_LUA_STRINGEOL 12 #define SCE_LUA_WORD2 13 #define SCE_LUA_WORD3 14 #define SCE_LUA_WORD4 15 #define SCE_LUA_WORD5 16 #define SCE_LUA_WORD6 17 #define SCE_LUA_WORD7 18 #define SCE_LUA_WORD8 19 #define SCE_LUA_LABEL 20
¹ there’s one for every group of languages – PHP is handled by HTML lexer, Javascript uses CPP, and so on.
-
I had lots of trouble with getting custom colors to work too. Today I finally found out the cause is due to using global defaults. Global defaults, I think, are supposed to be applied across all schemes, but I suspect when there are specific settings that are not defined in the global set, specific color schemes “bleed through”. So say you have a custom language setting for your favorite language Z#++ and a keyword defined for “iffin”, as in:
iffin (thissaHappened) {
…
}Since “iffin” is not already defined in Globals the color you set for “iffin” shows through. Just a speculation, but it seems to follow what I’m seeing.
Here is what I did to get specific language defs to work:
. Select theme: Default.xml
. Set Language: Global Styles
. Set Style: Global override
. Turn off ALL global settings. You can leave the font selection enabled since that doesn’t affect colors.
. Click Save & Close
. Now go into Settings > Style Configurator and select your language-specific settings. When you make changes they will be visible in the editor.