浏览代码

Final retouch for README and options

Joongi Kim 7 年前
父节点
当前提交
e257b1d89e
共有 2 个文件被更改,包括 18 次插入10 次删除
  1. 4
    1
      README.rst
  2. 14
    9
      syntax/python.vim

+ 4
- 1
README.rst 查看文件

@@ -24,7 +24,8 @@ Features
24 24
 
25 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 29
 - Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
29 30
   switch between Python 2 and Python 3 syntaxes respectively without
30 31
   reloads/restarts
@@ -101,6 +102,8 @@ Options used by the script
101 102
   Highlight builtin objects only
102 103
 ``python_highlight_builtin_funcs``
103 104
   Highlight builtin functions only
105
+``python_highlight_type_annotations``
106
+  Highlight Python 3.5+ type annotations
104 107
 ``python_highlight_exceptions``
105 108
   Highlight standard exceptions
106 109
 ``python_highlight_string_formatting``

+ 14
- 9
syntax/python.vim 查看文件

@@ -136,6 +136,7 @@ if s:Enabled("g:python_highlight_all")
136 136
     call s:EnableByDefault("g:python_highlight_builtin_objs")
137 137
     call s:EnableByDefault("g:python_highlight_builtin_funcs")
138 138
   endif
139
+  call s:EnableByDefault("g:python_highlight_type_annotations")
139 140
   call s:EnableByDefault("g:python_highlight_exceptions")
140 141
   call s:EnableByDefault("g:python_highlight_string_formatting")
141 142
   call s:EnableByDefault("g:python_highlight_string_format")
@@ -171,15 +172,19 @@ syn region pythonDictSetExpr matchgroup=pythonDictSetExpr start='{' end='}' cont
171 172
 syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
172 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 189
 syn match pythonStatement   "\<yield\>" display
185 190
 syn match pythonImport      "\<from\>" display