Просмотр исходного кода

Add support for string formating, format and template highlight

Pedro Algarvio 10 лет назад
Родитель
Сommit
0e5301a644
1 измененных файлов: 57 добавлений и 19 удалений
  1. 57
    19
      syntax/python.vim

+ 57
- 19
syntax/python.vim Просмотреть файл

@@ -30,6 +30,9 @@
30 30
 "   let python_no_doctest_highlight = 1
31 31
 "   let python_no_exception_highlight = 1
32 32
 "   let python_no_number_highlight = 1
33
+"   let python_no_string_format_highlight = 1
34
+"   let python_no_string_formatting_highlight = 1
35
+"   let python_no_string_template_highlight = 1
33 36
 "   let python_space_error_highlight = 1
34 37
 "   let python_shebang_header_highlight = 1
35 38
 "   let python_coding_header_highlight = 1
@@ -52,6 +55,36 @@ endif
52 55
 let s:cpo_save = &cpo
53 56
 set cpo&vim
54 57
 
58
+if exists("python_highlight_all")
59
+  if exists("python_no_builtin_highlight")
60
+    unlet python_no_builtin_highlight
61
+  endif
62
+  if exists("python_no_doctest_code_highlight")
63
+    unlet python_no_doctest_code_highlight
64
+  endif
65
+  if exists("python_no_doctest_highlight")
66
+    unlet python_no_doctest_highlight
67
+  endif
68
+  if exists("python_no_exception_highlight")
69
+    unlet python_no_exception_highlight
70
+  endif
71
+  if exists("python_no_number_highlight")
72
+    unlet python_no_number_highlight
73
+  endif
74
+  if exists("python_no_string_format_highlight")
75
+    unlet python_no_string_format_highlight
76
+  endif
77
+  if exists("python_no_string_formatting_highlight")
78
+    unlet python_no_string_formatting_highlight
79
+  endif
80
+  if exists("python_no_string_template_highlight")
81
+    unlet python_no_string_template_highlight
82
+  endif
83
+  let python_space_error_highlight = 1
84
+  let python_shebang_header_highlight = 1
85
+  let python_coding_header_highlight = 1
86
+endif
87
+
55 88
 " Keep Python keywords in alphabetical order inside groups for easy
56 89
 " comparison with the table in the 'Python Language Reference'
57 90
 " http://docs.python.org/reference/lexical_analysis.html#keywords.
@@ -123,25 +156,21 @@ syn match   pythonEscape	"\%(\\u\x\{4}\|\\U\x\{8}\)" contained
123 156
 syn match   pythonEscape	"\\N{.\{-}}" contained
124 157
 syn match   pythonEscape	"\\$"
125 158
 
126
-if exists("python_highlight_all")
127
-  if exists("python_no_builtin_highlight")
128
-    unlet python_no_builtin_highlight
129
-  endif
130
-  if exists("python_no_doctest_code_highlight")
131
-    unlet python_no_doctest_code_highlight
132
-  endif
133
-  if exists("python_no_doctest_highlight")
134
-    unlet python_no_doctest_highlight
135
-  endif
136
-  if exists("python_no_exception_highlight")
137
-    unlet python_no_exception_highlight
138
-  endif
139
-  if exists("python_no_number_highlight")
140
-    unlet python_no_number_highlight
141
-  endif
142
-  let python_space_error_highlight = 1
143
-  let python_shebang_header_highlight = 1
144
-  let python_coding_header_highlight = 1
159
+
160
+if !exists("python_no_string_format_highlight")
161
+  syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
162
+  syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
163
+endif
164
+
165
+if !exists("python_no_string_formatting_highlight")
166
+  syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
167
+  syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
168
+endif
169
+
170
+if !exists("python_no_string_template_highlight")
171
+  syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString
172
+  syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
173
+  syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
145 174
 endif
146 175
 
147 176
 " It is very important to understand all details before changing the
@@ -297,6 +326,15 @@ if version >= 508 || !exists("did_python_syn_inits")
297 326
   HiLink pythonTodo		Todo
298 327
   HiLink pythonString		String
299 328
   HiLink pythonRawString	String
329
+  if !exists("python_no_string_format_highlight")
330
+    HiLink pythonStrFormat	Special
331
+  endif
332
+  if !exists("python_no_string_formatting_highlight")
333
+    HiLink pythonStrFormatting	Special
334
+  endif
335
+  if !exists("python_no_string_template_highlight")
336
+    HiLink pythonStrTemplate	Special
337
+  endif
300 338
   HiLink pythonEscape		Special
301 339
   if !exists("python_no_number_highlight")
302 340
     HiLink pythonNumber		Number