Languages: Formatting rest of line after keyword
-
I work with a niche language and am developing my own coloring rules. Curly braces are widely used for any arguments that have a space in them.
One element I haven’t yet properly specified is the the call to print out a progress message to the console. The syntax is the keyword “RequiredInfo” followed by an output message. No quotes or braces are required unless the console message has spaces. For instance, I could include have these lines (Where InvokeCLR is a command call that takes an argument "Exchange#):
InvokeCLR Exchange1 RequiredInfo Breakpoint1 InvokeCLR {Exchange 2} RequiredInfo {Breakpoint 2}
I would like the display of this to be:
InvokeCLR Exchange1
RequiredInfo Here_is_Breakpoint1
InvokeCLR {Exchange 2}
RequiredInfo {Here is Breakpoint 2}
(Except with each argument in blue)
It is easy to make anything inside braces blue. (Delimiter Open/Close styling)
It is easy to make each of the keywords (InvokeDMI & RequiredInfo) bold. (Keyword Lists)
I can’t crack how to turn the non-braced arguments blue, or how to make the two breakpoint messages turn italic.
Any tips?
-
@Pigankle ,
It would be a good idea for you to check out the section of the online user manual with regards to the UDL for Keywords, which allow specific words to be handled by the UDL parser and color syntax highlighted. You can find that here:
https://npp-user-manual.org/
…and in addition, this link that shows how to work with each tab of the UDL here:
https://npp-user-manual.org/docs/user-defined-language-system/
and here:
https://ivan-radic.github.io/udl-documentation/
Good luck.Edit: Looks like @PeterJones and I responded at the same time almost…so use his advise first. ;-)
-
The User Defined Language (UDL) feature alone will not be sufficient for your desires, because it cannot handle things like “text after a certain keyword should be some different style”.
The plugin “Enhance Any Lexer” (install it via Plugins > Plugins Admin) will allow you to set the foreground colour for text matching a regex. So with a regex like
(?-s)^\h*(InvokeClr|RequiredInfo) \K.*$
will color text after those two prefixes until the end of the line.EnhanceAnyLexer.ini excerpt:
[udf] ; color each word, 0x66ad1 is the color used, see the description above for more information on the color coding. 0xFF7700 = (?-s)^\h*(InvokeClr|RequiredInfo) \K.*$ ; 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
(though yours will have the name of your UDL, insteead of
udf
, inside the[]
in the ini file)highlight screenshot:
(I used navy blue for the brace Delimiter 1 pair, and a slightly brighter blue-with-some-green (0xFF7700 in blue-green-red order) for the EnhanceAnyLexer, so you could tell which was highlighting which)Unfortunately, EnhanceAnyLexer does not do italics (nor bold nor underline nor background color – only foreground color), so I don’t know how to accomplish your goal of italics, sorry.
I might recommend, instead of italics, doing two different foreground colors for the arguments after InvokeCRL vs RequiredInfo.
And, once you’ve involved EnhanceAnyLexer, and if you want the braced and non-braced arguments to be the same shade of blue, then you could get rid of the Delimiters 1 pair for the braces, and just let the plugin do any arguments, braced or not, for those lines.
-
@PeterJones That’s very helpful - thank you!