Skip to content

syntax: highlight function calls #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ let g:python_highlight_all = 1
| --------------------------------------------- | -------------------------------------------------------------- | ------- |
| `g:python_version_2` | Python 2 mode | `0` |
| `b:python_version_2` | Python 2 mode (buffer local) | `0` |
| `g:python_highlight_func_calls` | Highlight functions calls | `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` |
Expand Down
3 changes: 3 additions & 0 deletions doc/python-syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: >
`b:python_version_2` (default `0`)
Python 2 mode (buffer local)

`g:python_highlight_func_calls` (default `0`)
Highlight functions calls

`g:python_highlight_builtins` (default `0`)
Highlight builtin functions and objects

Expand Down
17 changes: 15 additions & 2 deletions syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ call s:EnableByDefault('g:python_slow_sync')
call s:EnableByDefault('g:python_highlight_builtin_funcs_kwarg')

if s:Enabled('g:python_highlight_all')
call s:EnableByDefault('g:python_highlight_func_calls')
call s:EnableByDefault('g:python_highlight_builtins')
if s:Enabled('g:python_highlight_builtins')
call s:EnableByDefault('g:python_highlight_builtin_objs')
Expand All @@ -58,6 +59,14 @@ if s:Enabled('g:python_highlight_all')
call s:EnableByDefault('g:python_highlight_operators')
endif

"
" Function calls
"

if s:Enabled('g:python_highlight_func_calls')
syntax match pythonFunction /\v([^[:cntrl:][:space:][:punct:][:digit:]]|_)([^[:cntrl:][:punct:][:space:]]|_)*\ze(\s?\()/
endif

"
" Keywords
"
Expand Down Expand Up @@ -85,11 +94,15 @@ if s:Python2Syntax()
endif
syn keyword pythonStatement exec
syn keyword pythonImport as
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained
if !s:Enabled('g:python_highlight_func_calls')
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained
endif
else
syn keyword pythonStatement as nonlocal
syn match pythonStatement '\v\.@<!<await>'
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
if !s:Enabled('g:python_highlight_func_calls')
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
endif
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
syn match pythonStatement '\<async\s\+with\>'
syn match pythonStatement '\<async\s\+for\>'
Expand Down