From 3eb597c9997019da4789a2d93271b51d7736680a Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 14 Jul 2025 23:04:17 +0200 Subject: [PATCH] vim-patch:baa781a: runtime(python2): highlight unicode strings in python2 fixes: vim/vim#14033 fixes: vim/vim#17726 closes: vim/vim#17729 https://github.com/vim/vim/commit/baa781a4c35d7cc07d28bb6f0062c7fddf8e8556 Co-authored-by: Rob B --- runtime/syntax/python2.vim | 44 ++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/runtime/syntax/python2.vim b/runtime/syntax/python2.vim index 3b30eabbae..90c8dcaa33 100644 --- a/runtime/syntax/python2.vim +++ b/runtime/syntax/python2.vim @@ -2,8 +2,10 @@ " Language: Python 2 " Maintainer: Zvezdan Petkovic " Last Change: 2016 Oct 29 +" 2025 Jul 14 by Vim project: highlight unicode strings " Credits: Neil Schemenauer " Dmitry Vasiliev +" Rob B " " This version is a major rewrite by Zvezdan Petkovic. " @@ -141,24 +143,53 @@ 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=+\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" \ contains=pythonEscape,@Spell syn region pythonString matchgroup=pythonTripleQuotes - \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend + \ start=+\z('''\|"""\)+ end="\z1" keepend \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell syn region pythonRawString matchgroup=pythonQuotes - \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" + \ start=+[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1" \ contains=@Spell syn region pythonRawString matchgroup=pythonTripleQuotes - \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend + \ start=+[rR]\z('''\|"""\)+ end="\z1" keepend \ contains=pythonSpaceError,pythonDoctest,@Spell +" Unicode strings +syn region pythonString + \ matchgroup=pythonQuotes + \ start=+[uU]\z(['"]\)+ + \ end="\z1" + \ skip="\\\\\|\\\z1" + \ contains=pythonEscape,pythonUnicodeEscape,@Spell +syn region pythonString + \ matchgroup=pythonTripleQuotes + \ start=+[uU]\z('''\|"""\)+ + \ end="\z1" + \ keepend + \ contains=pythonEscape,pythonUnicodeEscape,pythonSpaceError,pythonDoctest,@Spell + +" Raw Unicode strings recognize Unicode escape sequences +" https://docs.python.org/2.7/reference/lexical_analysis.html#string-literals +syn region pythonRawString + \ matchgroup=pythonQuotes + \ start=+[uU][rR]\z(['"]\)+ + \ end="\z1" + \ skip="\\\\\|\\\z1" + \ contains=pythonUnicodeEscape,@Spell +syn region pythonRawString + \ matchgroup=pythonTripleQuotes + \ start=+[uU][rR]\z('''\|"""\)+ + \ end="\z1" + \ keepend + \ contains=pythonUnicodeEscape,pythonSpaceError,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 +syn match pythonUnicodeEscape "\%(\\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 pythonUnicodeEscape "\\N{\a\+\%(\s\a\+\)*}" contained syn match pythonEscape "\\$" " It is very important to understand all details before changing the @@ -320,6 +351,7 @@ hi def link pythonRawString String hi def link pythonQuotes String hi def link pythonTripleQuotes pythonQuotes hi def link pythonEscape Special +hi def link pythonUnicodeEscape pythonEscape if !exists("python_no_number_highlight") hi def link pythonNumber Number endif