Skip to content

Commit 07c654e

Browse files
committed
Added support for str.format syntax
1 parent ed21c2f commit 07c654e

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Revision 2.6.1 (unknown):
1111
- Added support for new integer literal syntax "0o" and "0b";
1212
- Added support for string.Template syntax controlled by
1313
"python_highlight_string_templates" option;
14+
- Added support for str.format syntax controlled by
15+
"python_highlight_string_format" option;
1416

1517
Revision 2.5.6 (2007-02-04):
1618

TODO.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Now
22
===
33

4-
- Python 3.0 string formatting
5-
64
Later
75
=====
86

python.vim

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@
3737
" For highlight string formatting:
3838
" python_highlight_string_formatting
3939
"
40-
" For highlight string.Template templates:
40+
" For highlight str.format syntax:
41+
" python_highlight_string_format
42+
"
43+
" For highlight string.Template syntax:
4144
" python_highlight_string_templates
4245
"
4346
" For highlight indentation errors:
@@ -78,6 +81,9 @@ if exists("python_highlight_all") && python_highlight_all != 0
7881
if !exists("python_highlight_string_formatting")
7982
let python_highlight_string_formatting = 1
8083
endif
84+
if !exists("python_highlight_string_format")
85+
let python_highlight_string_format = 1
86+
endif
8187
if !exists("python_highlight_string_templates")
8288
let python_highlight_string_templates = 1
8389
endif
@@ -182,8 +188,13 @@ syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display
182188

183189
if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
184190
" String formatting
185-
syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
186-
syn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
191+
syn match pythonStrFormatting "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
192+
syn match pythonStrFormatting "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
193+
endif
194+
195+
if exists("python_highlight_string_format") && python_highlight_string_format != 0
196+
" str.format syntax
197+
syn match pythonStrFormat "{\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rs]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
187198
endif
188199

189200
if exists("python_highlight_string_templates") && python_highlight_string_templates != 0
@@ -311,8 +322,9 @@ if version >= 508 || !exists("did_python_syn_inits")
311322
HiLink pythonUniRawEscape Special
312323
HiLink pythonUniRawEscapeError Error
313324

314-
HiLink pythonStrFormat Special
315-
HiLink pythonStrTemplate Special
325+
HiLink pythonStrFormatting Special
326+
HiLink pythonStrFormat Special
327+
HiLink pythonStrTemplate Special
316328

317329
HiLink pythonDocTest Special
318330
HiLink pythonDocTest2 Special

0 commit comments

Comments
 (0)