New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add python f-string and string-prefix highlight #14048
base: master
Are you sure you want to change the base?
Conversation
Following up on comments in #14033
I don't know, but I suspect that the likelihood of collection literal matches in the expression is much lower than computed format specs. I found some of the latter and none of the former in a quick search. Simply containing it recursively would probably only result in highlighted braces in the expression, in the worst case, which might be worth living with. I just skimmed the PEP (not a Python user, take with a grain of salt) and it seems that this could be matched properly with a bit of effort. You could create a series of regions contained in Unfortunately, the syntax file doesn't match other brace delimited syntax but those could be added and mixed with I'm not suggesting that this should be done, just that it's possible. |
I don't want incorrect highlighting like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't want incorrect highlighting like
f'{exec("if 1:{}")}'
, and if I want to contains it myself, I won't be able to use TOP because it can only be excluded
None of my suggestions would highlight that example incorrectly. The exec
argument would just be matched as a plain string.
TOP
is just a convenience. It would be nice if the contains
syntax was a bit more expressive to allow groups to be added as well but you can define a new cluster including only the required expression groups. Technically, of course, TOP
matches too much anyway.
syn match pythonEscape "\\\r\=$" | ||
|
||
syn region pythonFStringValue matchgroup=pythonFStringBrace | ||
\ start=+{+ end=+=\=\%(![rsa]\)\=\%(:[^{}]*\%({[^{}]*\%({[^{}]*}[^{}]*\)*}[^{}]*\)*\)\=}+ contains=TOP contained excludenl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excludenl
shouldn't be needed here as the pattern doesn't match EOL.
hi def link pythonQuotes String | ||
hi def link pythonTripleQuotes pythonQuotes | ||
hi def link pythonEscape Special | ||
hi def link pythonFStringEscapedBrace Special | ||
hi def link pythonFStringValue Normal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't usually specified as it is the default if no highlight group is linked but does no harm.
close #14033