Browse Source

Final retouch for README and options

Joongi Kim 7 years ago
parent
commit
e257b1d89e
2 changed files with 18 additions and 10 deletions
  1. 4
    1
      README.rst
  2. 14
    9
      syntax/python.vim

+ 4
- 1
README.rst View File

24
 
24
 
25
 Changes from the original ``python.vim`` are:
25
 Changes from the original ``python.vim`` are:
26
 
26
 
27
-- Added support for Python 3 syntax highlighting
27
+- Added support for Python 3.5/3.6+ syntax highlighting, including f-string
28
+  literals and type annotations.
28
 - Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
29
 - Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
29
   switch between Python 2 and Python 3 syntaxes respectively without
30
   switch between Python 2 and Python 3 syntaxes respectively without
30
   reloads/restarts
31
   reloads/restarts
101
   Highlight builtin objects only
102
   Highlight builtin objects only
102
 ``python_highlight_builtin_funcs``
103
 ``python_highlight_builtin_funcs``
103
   Highlight builtin functions only
104
   Highlight builtin functions only
105
+``python_highlight_type_annotations``
106
+  Highlight Python 3.5+ type annotations
104
 ``python_highlight_exceptions``
107
 ``python_highlight_exceptions``
105
   Highlight standard exceptions
108
   Highlight standard exceptions
106
 ``python_highlight_string_formatting``
109
 ``python_highlight_string_formatting``

+ 14
- 9
syntax/python.vim View File

136
     call s:EnableByDefault("g:python_highlight_builtin_objs")
136
     call s:EnableByDefault("g:python_highlight_builtin_objs")
137
     call s:EnableByDefault("g:python_highlight_builtin_funcs")
137
     call s:EnableByDefault("g:python_highlight_builtin_funcs")
138
   endif
138
   endif
139
+  call s:EnableByDefault("g:python_highlight_type_annotations")
139
   call s:EnableByDefault("g:python_highlight_exceptions")
140
   call s:EnableByDefault("g:python_highlight_exceptions")
140
   call s:EnableByDefault("g:python_highlight_string_formatting")
141
   call s:EnableByDefault("g:python_highlight_string_formatting")
141
   call s:EnableByDefault("g:python_highlight_string_format")
142
   call s:EnableByDefault("g:python_highlight_string_format")
171
 syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
172
 syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
172
 syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=pythonTypeAnno,@pythonExpression
173
 syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=pythonTypeAnno,@pythonExpression
173
 
174
 
174
-syn match pythonTypeAnno ":\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"hs=s+1 display contained contains=pythonType nextgroup=pythonTypeArgs
175
-syn match pythonTypeAnnoReturn "->\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contains=pythonType nextgroup=pythonTypeArgs
176
-syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonTypeArgs
177
-syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
178
-syn keyword pythonType AbstractSet MutableSet Mapping MutableMapping Sequence MutableSequence ByteString Deque List contained
179
-syn keyword pythonType Set FrozenSet MappingView KeysView ItemsView ValuesView Awaitable Coroutine AsyncIterable contained
180
-syn keyword pythonType AsyncIterator ContextManager Dict DefaultDict Generator AsyncGenerator Text NamedTuple contained
181
-syn keyword pythonType Iterable Iterator Reversible SupportsInt SupportsFloat SupportsAbs SupportsRound Container contained
182
-syn keyword pythonType Hashable Sized Collection contained
175
+if !s:Python2Syntax()
176
+  if s:Enabled("g:python_highlight_type_annotations")
177
+    syn match pythonTypeAnno ":\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"hs=s+1 display contained contains=pythonType nextgroup=pythonTypeArgs
178
+    syn match pythonTypeAnnoReturn "->\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contains=pythonType nextgroup=pythonTypeArgs
179
+    syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonTypeArgs
180
+    syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
181
+    syn keyword pythonType AbstractSet MutableSet Mapping MutableMapping Sequence MutableSequence ByteString Deque List contained
182
+    syn keyword pythonType Set FrozenSet MappingView KeysView ItemsView ValuesView Awaitable Coroutine AsyncIterable contained
183
+    syn keyword pythonType AsyncIterator ContextManager Dict DefaultDict Generator AsyncGenerator Text NamedTuple contained
184
+    syn keyword pythonType Iterable Iterator Reversible SupportsInt SupportsFloat SupportsAbs SupportsRound Container contained
185
+    syn keyword pythonType Hashable Sized Collection contained
186
+  endif
187
+endif
183
 
188
 
184
 syn match pythonStatement   "\<yield\>" display
189
 syn match pythonStatement   "\<yield\>" display
185
 syn match pythonImport      "\<from\>" display
190
 syn match pythonImport      "\<from\>" display