From 0a925278f7444ce28bfccfabeabee65d706da531 Mon Sep 17 00:00:00 2001 From: Caleb Donovick Date: Tue, 18 Dec 2018 15:29:50 -0800 Subject: [PATCH] Split builtin objects / types Closes #55 --- README.md | 1 + doc/python-syntax.txt | 3 +++ syntax/python.vim | 21 ++++++++++++++++----- tests/test.py | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8c35ec2..c1b6b0d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ let g:python_highlight_all = 1 | `b:python_version_2` | Python 2 mode (buffer local) | `0` | | `g:python_highlight_builtins` | Highlight builtin functions and objects | `0` | | `g:python_highlight_builtin_objs` | Highlight builtin objects only | `0` | +| `g:python_highlight_builtin_types` | Highlight builtin types only | `0` | | `g:python_highlight_builtin_funcs` | Highlight builtin functions only | `0` | | `g:python_highlight_builtin_funcs_kwarg` | Highlight builtin functions when used as kwarg | `1` | | `g:python_highlight_exceptions` | Highlight standard exceptions | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index a1ccf16..01bd1fe 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -62,6 +62,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > `g:python_highlight_builtin_objs` (default `0`) Highlight builtin objects only +`g:python_highlight_builtin_types` (default `0`) + Highlight builtin types only + `g:python_highlight_builtin_funcs` (default `0`) Highlight builtin functions only diff --git a/syntax/python.vim b/syntax/python.vim index 3f4c967..2f9a47e 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -44,6 +44,7 @@ if s:Enabled('g:python_highlight_all') if s:Enabled('g:python_highlight_builtins') call s:EnableByDefault('g:python_highlight_builtin_objs') call s:EnableByDefault('g:python_highlight_builtin_funcs') + call s:EnableByDefault('g:python_highlight_builtin_types') endif call s:EnableByDefault('g:python_highlight_exceptions') call s:EnableByDefault('g:python_highlight_string_formatting') @@ -92,7 +93,7 @@ else syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonBuiltinObj,pythonBuiltinFunc + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType endif @@ -330,14 +331,13 @@ else endif " -" Builtin objects and types +" Builtin objects " if s:Enabled('g:python_highlight_builtin_objs') syn keyword pythonNone None syn keyword pythonBoolean True False - syn keyword pythonBuiltinObj Ellipsis NotImplemented - syn match pythonBuiltinObj '\v\.@' + syn keyword pythonSingleton Ellipsis NotImplemented syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ endif @@ -368,6 +368,15 @@ if s:Enabled('g:python_highlight_builtin_funcs') unlet s:funcs_re endif +" +" Builtin types +" + +if s:Enabled('g:python_highlight_builtin_types') + syn match pythonBuiltinType '\v\.@' +endif + + " " Builtin exceptions and warnings " @@ -469,9 +478,11 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBoolean Boolean HiLink pythonNone Constant + HiLink pythonSingleton Constant - HiLink pythonBuiltinObj Structure + HiLink pythonBuiltinObj Identifier HiLink pythonBuiltinFunc Function + HiLink pythonBuiltinType Structure HiLink pythonExClass Structure HiLink pythonClassVar Identifier diff --git a/tests/test.py b/tests/test.py index 6f00b26..0f75ead 100644 --- a/tests/test.py +++ b/tests/test.py @@ -38,6 +38,8 @@ async for True False Ellipsis None NotImplemented +__debug__ __doc__ __file__ __name__ __package__ __loader__ __spec__ __path__ __cached__ + # Bultin types bool bytearray dict float frozenset int list object set str tuple