Skip to content

Commit 0a92527

Browse files
cdonovicknfnty
authored andcommitted
Split builtin objects / types
Closes vim-python#55
1 parent 7ecb80f commit 0a92527

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ let g:python_highlight_all = 1
6161
| `b:python_version_2` | Python 2 mode (buffer local) | `0` |
6262
| `g:python_highlight_builtins` | Highlight builtin functions and objects | `0` |
6363
| `g:python_highlight_builtin_objs` | Highlight builtin objects only | `0` |
64+
| `g:python_highlight_builtin_types` | Highlight builtin types only | `0` |
6465
| `g:python_highlight_builtin_funcs` | Highlight builtin functions only | `0` |
6566
| `g:python_highlight_builtin_funcs_kwarg` | Highlight builtin functions when used as kwarg | `1` |
6667
| `g:python_highlight_exceptions` | Highlight standard exceptions | `0` |

doc/python-syntax.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: >
6262
`g:python_highlight_builtin_objs` (default `0`)
6363
Highlight builtin objects only
6464

65+
`g:python_highlight_builtin_types` (default `0`)
66+
Highlight builtin types only
67+
6568
`g:python_highlight_builtin_funcs` (default `0`)
6669
Highlight builtin functions only
6770

syntax/python.vim

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ if s:Enabled('g:python_highlight_all')
4444
if s:Enabled('g:python_highlight_builtins')
4545
call s:EnableByDefault('g:python_highlight_builtin_objs')
4646
call s:EnableByDefault('g:python_highlight_builtin_funcs')
47+
call s:EnableByDefault('g:python_highlight_builtin_types')
4748
endif
4849
call s:EnableByDefault('g:python_highlight_exceptions')
4950
call s:EnableByDefault('g:python_highlight_string_formatting')
@@ -92,7 +93,7 @@ else
9293
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
9394
syn match pythonStatement '\<async\s\+with\>'
9495
syn match pythonStatement '\<async\s\+for\>'
95-
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonBuiltinObj,pythonBuiltinFunc
96+
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType
9697
endif
9798

9899

@@ -330,14 +331,13 @@ else
330331
endif
331332

332333
"
333-
" Builtin objects and types
334+
" Builtin objects
334335
"
335336

336337
if s:Enabled('g:python_highlight_builtin_objs')
337338
syn keyword pythonNone None
338339
syn keyword pythonBoolean True False
339-
syn keyword pythonBuiltinObj Ellipsis NotImplemented
340-
syn match pythonBuiltinObj '\v\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
340+
syn keyword pythonSingleton Ellipsis NotImplemented
341341
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
342342
syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__
343343
endif
@@ -368,6 +368,15 @@ if s:Enabled('g:python_highlight_builtin_funcs')
368368
unlet s:funcs_re
369369
endif
370370

371+
"
372+
" Builtin types
373+
"
374+
375+
if s:Enabled('g:python_highlight_builtin_types')
376+
syn match pythonBuiltinType '\v\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
377+
endif
378+
379+
371380
"
372381
" Builtin exceptions and warnings
373382
"
@@ -469,9 +478,11 @@ if v:version >= 508 || !exists('did_python_syn_inits')
469478

470479
HiLink pythonBoolean Boolean
471480
HiLink pythonNone Constant
481+
HiLink pythonSingleton Constant
472482

473-
HiLink pythonBuiltinObj Structure
483+
HiLink pythonBuiltinObj Identifier
474484
HiLink pythonBuiltinFunc Function
485+
HiLink pythonBuiltinType Structure
475486

476487
HiLink pythonExClass Structure
477488
HiLink pythonClassVar Identifier

tests/test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ async def Test
3838

3939
True False Ellipsis None NotImplemented
4040

41+
__debug__ __doc__ __file__ __name__ __package__ __loader__ __spec__ __path__ __cached__
42+
4143
# Bultin types
4244

4345
bool bytearray dict float frozenset int list object set str tuple

0 commit comments

Comments
 (0)