Browse Source

Add support for string formating, format and template highlight

Pedro Algarvio 10 years ago
parent
commit
0e5301a644
1 changed files with 57 additions and 19 deletions
  1. 57
    19
      syntax/python.vim

+ 57
- 19
syntax/python.vim View File

30
 "   let python_no_doctest_highlight = 1
30
 "   let python_no_doctest_highlight = 1
31
 "   let python_no_exception_highlight = 1
31
 "   let python_no_exception_highlight = 1
32
 "   let python_no_number_highlight = 1
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
 "   let python_space_error_highlight = 1
36
 "   let python_space_error_highlight = 1
34
 "   let python_shebang_header_highlight = 1
37
 "   let python_shebang_header_highlight = 1
35
 "   let python_coding_header_highlight = 1
38
 "   let python_coding_header_highlight = 1
52
 let s:cpo_save = &cpo
55
 let s:cpo_save = &cpo
53
 set cpo&vim
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
 " Keep Python keywords in alphabetical order inside groups for easy
88
 " Keep Python keywords in alphabetical order inside groups for easy
56
 " comparison with the table in the 'Python Language Reference'
89
 " comparison with the table in the 'Python Language Reference'
57
 " http://docs.python.org/reference/lexical_analysis.html#keywords.
90
 " http://docs.python.org/reference/lexical_analysis.html#keywords.
123
 syn match   pythonEscape	"\\N{.\{-}}" contained
156
 syn match   pythonEscape	"\\N{.\{-}}" contained
124
 syn match   pythonEscape	"\\$"
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
 endif
174
 endif
146
 
175
 
147
 " It is very important to understand all details before changing the
176
 " It is very important to understand all details before changing the
297
   HiLink pythonTodo		Todo
326
   HiLink pythonTodo		Todo
298
   HiLink pythonString		String
327
   HiLink pythonString		String
299
   HiLink pythonRawString	String
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
   HiLink pythonEscape		Special
338
   HiLink pythonEscape		Special
301
   if !exists("python_no_number_highlight")
339
   if !exists("python_no_number_highlight")
302
     HiLink pythonNumber		Number
340
     HiLink pythonNumber		Number