userDefineLangs for .txt
-
Ho can (already?) made custom .txt like in Akelpad, where latin, cyrillic, numbers and characters are have their own highlight?
-
If you create your own User Defined language, and put
txt
in the User Exts box for that language, Notepad++ will apply the defined highlighting to all.txt
filesHere is an example where I put the word “latin” as red keyword1, the word “cyrillic” as green keyword2, and each individual cyrillic letter I copied from somewhere in magenta-on-yellow keyword3 with “prefix mode” enabled; the “Number” style on the “Comment & Number” tab is set to blue:
Without “prefix mode” being checked, it won’t highlight the cyrillic characters when there are more than one adjacent:
Note that, because of the limitations of the UDL parser, if I have a mixed-alphabet “word” like
Дabcd
, it will highlight the whole thing as keyword3, but if I use a non-keyword3 character as the first character, likeabДcd
, it will not highlight as keyword3:
If you want more fine-grained control, use @Ekopalypse’s EnhanceAnyLexer plugin (you can install it from Plugins Admin): you don’t even need a UDL for this version: in the
EnhanceAnyLexerConfig.ini
file (Plugins > Enhance Any Lexer > Open Configuration file), just add a section at the end and save it:[Normal text] 0xFFFF00 = [АА́А̀БВГҐДЂЃЕЀЁЄЖЗЗ́ЅИІЇИ́ЍЙЈКЛЉМНЊОŌПРСС́ТЋЌУӮЎФХЦЧЏШЩЪЫЬЭЮЯ] 0xFF0000 = [+-]?\d*\.?\d+
This will highlight any of those cyrillic characters as cyan and a variety of numeric formats as blue:
You can add as many regex rules as you want for any lexer (normal text, builtin lexer, or UDL)
Ekopalypse’s plugin is awesome!
-
okey, I tried through EnhanceAnyLexerConfig and it works
BUT! features of different themes are not taken into account, for example, dark and light
green is always green -
The answer is simple: currently there is no official way to determine the theme used and their colors, and therefore a plugin does not know which color to assign to which “theme color”.
@PeterJones - thx for the kind words.
-
@kozakmak said in userDefineLangs for .txt:
BUT! features of different themes are not taken into account, for example, dark and light
Out of curiosity, do you really change themes or light/dark that often? Everyone I know just picks their favorite theme and just leaves it like that for normal usage. If you have a use case (other than the few minutes, hours, or days required to say, “no, I like theme/mode X better than theme/mode Y”) where you frequently change themes or light/dark, I’d love to hear it… because I’ve occasionally seen people complain about things not following theme/mode changes, but whenever I’ve asked for a use case where changing is necessary, I’ve never seen a reason that makes sense to me: maybe you will be the first. (And if I know of use cases where it’s important, either I can figure out workarounds in such situations, or if it makes sense, I could start lobbying the developers to expose new API that will give information about the theme – the Dark-vs-Light mode is now in the API, thankfully)
If you aren’t changing themes or light/dark modes, then just put in the colors that work well with your theme. If you are changing themes often, then as Ekopalypse says, there isn’t a way for the plugin to know what theme you are using for now, so you’ll unfortunately have to live with that mild annoyance of editing and saving the EnhanceAnyLexer config whenever you do change theme. (If you are changing themes enough that it goes beyond mild annoyance, maybe you should consider which is a higher priority to you: changing themes, or the custom “normal text” highlighting.)