Skip to content

Commit 53ea235

Browse files
antoinemadecnfnty
authored andcommitted
Implement function call highlighting
Closes #63
1 parent 1df5e5a commit 53ea235

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ let g:python_highlight_all = 1
7171
| `g:python_highlight_indent_errors` | Highlight indentation errors | `0` |
7272
| `g:python_highlight_space_errors` | Highlight trailing spaces | `0` |
7373
| `g:python_highlight_doctests` | Highlight doc-tests | `0` |
74+
| `g:python_highlight_func_calls` | Highlight functions calls | `0` |
7475
| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` |
7576
| `g:python_highlight_operators` | Highlight all operators | `0` |
7677
| `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` |

doc/python-syntax.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: >
9292
`g:python_highlight_doctests` (default `0`)
9393
Highlight doc-tests
9494

95+
`g:python_highlight_func_calls` (default `0`)
96+
Highlight functions calls
97+
9598
`g:python_highlight_class_vars` (default `0`)
9699
Highlight class variables `self` and `cls`
97100

syntax/python.vim

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ if s:Enabled('g:python_highlight_all')
5454
call s:EnableByDefault('g:python_highlight_space_errors')
5555
call s:EnableByDefault('g:python_highlight_doctests')
5656
call s:EnableByDefault('g:python_print_as_function')
57+
call s:EnableByDefault('g:python_highlight_func_calls')
5758
call s:EnableByDefault('g:python_highlight_class_vars')
5859
call s:EnableByDefault('g:python_highlight_operators')
5960
endif
@@ -64,7 +65,7 @@ endif
6465

6566
syn keyword pythonStatement break continue del return pass yield global assert lambda with
6667
syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite
67-
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
68+
syn keyword pythonStatement def class nextgroup=pythonFunctionContained skipwhite
6869
if s:Enabled('g:python_highlight_class_vars')
6970
syn keyword pythonClassVar self cls
7071
endif
@@ -85,12 +86,12 @@ if s:Python2Syntax()
8586
endif
8687
syn keyword pythonStatement exec
8788
syn keyword pythonImport as
88-
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained
89+
syn match pythonFunctionContained '[a-zA-Z_][a-zA-Z0-9_]*' display contained
8990
else
9091
syn keyword pythonStatement as nonlocal
9192
syn match pythonStatement '\v\.@<!<await>'
92-
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
93-
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
93+
syn match pythonFunctionContained '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
94+
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunctionContained skipwhite
9495
syn match pythonStatement '\<async\s\+with\>'
9596
syn match pythonStatement '\<async\s\+for\>'
9697
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')
394395
unlet s:exs_re
395396
endif
396397

398+
"
399+
" Function calls
400+
"
401+
402+
if s:Enabled('g:python_highlight_func_calls')
403+
syn match pythonFunctionCall '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\ze\%(\s*(\)'
404+
endif
405+
406+
"
407+
" Misc
408+
"
409+
397410
if s:Enabled('g:python_slow_sync')
398411
syn sync minlines=2000
399412
else
@@ -415,7 +428,8 @@ if v:version >= 508 || !exists('did_python_syn_inits')
415428
HiLink pythonStatement Statement
416429
HiLink pythonRaiseFromStatement Statement
417430
HiLink pythonImport Include
418-
HiLink pythonFunction Function
431+
HiLink pythonFunctionContained Function
432+
HiLink pythonFunctionCall Function
419433
HiLink pythonConditional Conditional
420434
HiLink pythonRepeat Repeat
421435
HiLink pythonException Exception

tests/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
yield from
1919

2020
def functionname
21+
functionname()
22+
functionname ()
23+
functionname ()
24+
test.functionname()
25+
test.functionname ()
2126
class Classname
2227
def функция
28+
функция()
2329
class Класс
2430

2531
# Keywords: Python 2

0 commit comments

Comments
 (0)