Skip to content

Commit

Permalink
Split builtin objects / types
Browse files Browse the repository at this point in the history
Closes #55
  • Loading branch information
cdonovick authored and nfnty committed Jan 9, 2019
1 parent 7ecb80f commit 0a92527
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
3 changes: 3 additions & 0 deletions doc/python-syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 16 additions & 5 deletions syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -92,7 +93,7 @@ else
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
syn match pythonStatement '\<async\s\+with\>'
syn match pythonStatement '\<async\s\+for\>'
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


Expand Down Expand Up @@ -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\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
syn keyword pythonSingleton Ellipsis NotImplemented
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__
endif
Expand Down Expand Up @@ -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\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
endif


"
" Builtin exceptions and warnings
"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ async def Test

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
Expand Down

0 comments on commit 0a92527

Please sign in to comment.