simple UDL highlighting Apostrophes & Quotation Marks
I copy and paste lot’s of different little text snippets to check the straight Apostrophes & Quotation Marks and the ‘open and close curly’ variants.
How can I give each type a different color in an UDL? (not with style tokens, cause that takes too much time)
Unfortunately, ‘single’ and “double” smart quotes are at unicode codepoints beyond 255. And the UDL doesn’t handle codepoints above 255 in the Operators & Delimiters inputs… and unfortunately, that’s the most natural place. This will be expounded in the next version of the usermanual:
The UDL interface and underlying lexer was designed in the early days of Notepad++, before good Unicode support was implemented, so the User Defined Language system does not fully support Unicode characters beyond what’s available in the current ANSI codepage (255 characters). Unicode can be used in some locations, like the keywords and the Numbers-style Extras 1; but many other places, like Operators & Delimiters, or Comments, or Folding, do not work with characters beyond codepoint 255. If Unicode characters in your operators or delimiters is a requirement for you, you should consider using a existing plugin (such as a scripting plugin or EnhanceAnyLexer) to add additional text highlighting based on the active langauge, or write your own plugin to add highlighting in any way you choose. (Also, if you have the coding skills necessary to update Notepad++'s codebase to allow UDL to use Unicode, without causing any regressions, you might consider submitting a PR, as it could close multiple open issues.)
using Keywords list in prefix mode would work for the opening quote marks, which will always be at the beginning of a word… so you could put open single ‘ in group 7 with one color, and open double “ in group 8 with a different color; if you checkmarked “prefix mode”, it will highlight the whole word that starts with that character. But since there is no suffix mode, you cannot do the same for the end quotes ’ and ”.
The plugin Enhance Any Lexer could come to your rescue, however. Undo the Keywords for both of the open quotes. Instead (after installing the plugin and making sure your imported file has your current UDL as the active language), Plugins > Enhance Any Lexer > Enhance current langauge: it will open a config file and create a new section named after your UDL: if you called it FindWeirdQuotes, you would see a new section,
[findweirdquotes] ; color each word, 0x66ad1 is the color used, see the description above for more information on the color coding. 0x66ad1 = \w+ ; check in the respective styler xml if the following IDs are valid excluded_styles = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20,21,22,23
Go in and edit that to have four different colors mapped to the four weird quotes:
[findweirdquotes] ; color each word, 0x66ad1 is the color used, see the description above for more information on the color coding. 0xFFFF00 = ‘ 0xFF7F00 = ’ 0xFF00FF = “ 0xFF007F = ” ; check in the respective styler xml if the following IDs are valid ;excluded_styles = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,20,21,22,23
Once you save that, any time you activate a tab that has the UDL language set to FindWeirdQuotes, it will highlight them in the four colors (bright cyan, more bluish cyan, bright magenta, darker purple were my choices)
(You only have to do the setup once; once it’s saved, the plugin will automatically apply those colors whenever the active file is in the named UDL.)
(And you can choose whether to also use the normal UDL features to color normal quotes and apostrophes, whether as operators or delimiter pairs, as those normal ones work in UDL just the way you’d expect.
This does exactly what I want, thank you very much.