-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Open
A4-Tacks
wants to merge
1
commit into
vim:master
Choose a base branch
from
A4-Tacks:python-f-string-highlight
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,25 +143,47 @@ syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained | |
|
||
" Triple-quoted strings can contain doctests. | ||
syn region pythonString matchgroup=pythonQuotes | ||
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" | ||
\ start=+[uUbB]\=\z(['"]\)+ end="$\|\z1" skip="\\\\\|\\\z1" | ||
\ contains=pythonEscape,@Spell | ||
syn region pythonString matchgroup=pythonTripleQuotes | ||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend | ||
\ start=+[uUbB]\=\z('''\|"""\)+ end="\z1" keepend | ||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell | ||
syn region pythonRawString matchgroup=pythonQuotes | ||
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" | ||
\ start=+\%([bB][rR]\=\|[rR][bB]\=\)\z(['"]\)+ | ||
\ end="$\|\z1" skip="\\\\\|\\\r\=$\|\\\z1" | ||
\ contains=@Spell | ||
syn region pythonRawString matchgroup=pythonTripleQuotes | ||
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend | ||
\ start=+\%([bB][rR]\=\|[rR][bB]\=\)\z('''\|"""\)+ | ||
\ end="\z1" keepend | ||
\ contains=pythonSpaceError,pythonDoctest,@Spell | ||
syn region pythonFString matchgroup=pythonQuotes | ||
\ start=+[fF]\z(['"]\)+ | ||
\ end="$\|\z1" skip="\\\\\|\\\z1" | ||
\ contains=pythonEscape,pythonFStringEscapedBrace,pythonFStringValue,@Spell | ||
syn region pythonFString matchgroup=pythonTripleQuotes | ||
\ start=+[fF]\z('''\|"""\)+ | ||
\ end="\z1" keepend | ||
\ contains=pythonEscape,pythonSpaceError,pythonFStringEscapedBrace,pythonFStringValue,pythonDoctest,@Spell | ||
syn region pythonRawFString matchgroup=pythonQuotes | ||
\ start=+\%([fF][rR]\|[rR][fF]\)\z(['"]\)+ | ||
\ end="$\|\z1" skip="\\\\\|\\\r\=$\|\\\z1" | ||
\ contains=pythonFStringEscapedBrace,pythonFStringValue,@Spell | ||
syn region pythonRawFString matchgroup=pythonTripleQuotes | ||
\ start=+\%([fF][rR]\|[rR][fF]\)\z('''\|"""\)+ | ||
\ end="\z1" keepend | ||
\ contains=pythonSpaceError,pythonFStringEscapedBrace,pythonFStringValue,pythonDoctest,@Spell | ||
|
||
syn match pythonEscape +\\[abfnrtv'"\\]+ contained | ||
syn match pythonEscape "\\\o\{1,3}" contained | ||
syn match pythonEscape "\\x\x\{2}" contained | ||
syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained | ||
" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/ | ||
syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained | ||
syn match pythonEscape "\\$" | ||
syn match pythonEscape "\\\r\=$" | ||
|
||
syn region pythonFStringValue matchgroup=pythonFStringBrace | ||
\ start=+{+ end=+=\=\%(![rsa]\)\=\%(:[^{}]*\%({[^{}]*\%({[^{}]*}[^{}]*\)*}[^{}]*\)*\)\=}+ contains=TOP contained excludenl | ||
syn match pythonFStringEscapedBrace "{{\|}}" contained | ||
|
||
" It is very important to understand all details before changing the | ||
" regular expressions below or their order. | ||
|
@@ -312,9 +334,14 @@ hi def link pythonComment Comment | |
hi def link pythonTodo Todo | ||
hi def link pythonString String | ||
hi def link pythonRawString String | ||
hi def link pythonFString String | ||
hi def link pythonRawFString String | ||
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 commentThe 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. |
||
hi def link pythonFStringBrace Include | ||
if !exists("python_no_number_highlight") | ||
hi def link pythonNumber Number | ||
endif | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.