Implement function call highlighting

Closes #63
This commit is contained in:
antoinemadec
2020-02-19 16:17:14 -08:00
committed by nfnty
parent 1df5e5aaf8
commit 53ea235863
4 changed files with 29 additions and 5 deletions

View File

@@ -71,6 +71,7 @@ let g:python_highlight_all = 1
| `g:python_highlight_indent_errors` | Highlight indentation errors | `0` | | `g:python_highlight_indent_errors` | Highlight indentation errors | `0` |
| `g:python_highlight_space_errors` | Highlight trailing spaces | `0` | | `g:python_highlight_space_errors` | Highlight trailing spaces | `0` |
| `g:python_highlight_doctests` | Highlight doc-tests | `0` | | `g:python_highlight_doctests` | Highlight doc-tests | `0` |
| `g:python_highlight_func_calls` | Highlight functions calls | `0` |
| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` | | `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` |
| `g:python_highlight_operators` | Highlight all operators | `0` | | `g:python_highlight_operators` | Highlight all operators | `0` |
| `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` | | `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` |

View File

@@ -92,6 +92,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: >
`g:python_highlight_doctests` (default `0`) `g:python_highlight_doctests` (default `0`)
Highlight doc-tests Highlight doc-tests
`g:python_highlight_func_calls` (default `0`)
Highlight functions calls
`g:python_highlight_class_vars` (default `0`) `g:python_highlight_class_vars` (default `0`)
Highlight class variables `self` and `cls` Highlight class variables `self` and `cls`

View File

@@ -54,6 +54,7 @@ if s:Enabled('g:python_highlight_all')
call s:EnableByDefault('g:python_highlight_space_errors') call s:EnableByDefault('g:python_highlight_space_errors')
call s:EnableByDefault('g:python_highlight_doctests') call s:EnableByDefault('g:python_highlight_doctests')
call s:EnableByDefault('g:python_print_as_function') call s:EnableByDefault('g:python_print_as_function')
call s:EnableByDefault('g:python_highlight_func_calls')
call s:EnableByDefault('g:python_highlight_class_vars') call s:EnableByDefault('g:python_highlight_class_vars')
call s:EnableByDefault('g:python_highlight_operators') call s:EnableByDefault('g:python_highlight_operators')
endif endif
@@ -64,7 +65,7 @@ endif
syn keyword pythonStatement break continue del return pass yield global assert lambda with syn keyword pythonStatement break continue del return pass yield global assert lambda with
syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite syn keyword pythonStatement def class nextgroup=pythonFunctionContained skipwhite
if s:Enabled('g:python_highlight_class_vars') if s:Enabled('g:python_highlight_class_vars')
syn keyword pythonClassVar self cls syn keyword pythonClassVar self cls
endif endif
@@ -85,12 +86,12 @@ if s:Python2Syntax()
endif endif
syn keyword pythonStatement exec syn keyword pythonStatement exec
syn keyword pythonImport as syn keyword pythonImport as
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained syn match pythonFunctionContained '[a-zA-Z_][a-zA-Z0-9_]*' display contained
else else
syn keyword pythonStatement as nonlocal syn keyword pythonStatement as nonlocal
syn match pythonStatement '\v\.@<!<await>' syn match pythonStatement '\v\.@<!<await>'
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonFunctionContained '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunctionContained skipwhite
syn match pythonStatement '\<async\s\+with\>' syn match pythonStatement '\<async\s\+with\>'
syn match pythonStatement '\<async\s\+for\>' syn match pythonStatement '\<async\s\+for\>'
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType
@@ -394,6 +395,18 @@ if s:Enabled('g:python_highlight_exceptions')
unlet s:exs_re unlet s:exs_re
endif endif
"
" Function calls
"
if s:Enabled('g:python_highlight_func_calls')
syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)'
endif
"
" Misc
"
if s:Enabled('g:python_slow_sync') if s:Enabled('g:python_slow_sync')
syn sync minlines=2000 syn sync minlines=2000
else else
@@ -415,7 +428,8 @@ if v:version >= 508 || !exists('did_python_syn_inits')
HiLink pythonStatement Statement HiLink pythonStatement Statement
HiLink pythonRaiseFromStatement Statement HiLink pythonRaiseFromStatement Statement
HiLink pythonImport Include HiLink pythonImport Include
HiLink pythonFunction Function HiLink pythonFunctionContained Function
HiLink pythonFunctionCall Function
HiLink pythonConditional Conditional HiLink pythonConditional Conditional
HiLink pythonRepeat Repeat HiLink pythonRepeat Repeat
HiLink pythonException Exception HiLink pythonException Exception

View File

@@ -18,8 +18,14 @@ raise Exception from ex
yield from yield from
def functionname def functionname
functionname()
functionname ()
functionname ()
test.functionname()
test.functionname ()
class Classname class Classname
def функция def функция
функция()
class Класс class Класс
# Keywords: Python 2 # Keywords: Python 2