Skip to content

Commit 48b7eb1

Browse files
jparisechrisbra
authored andcommitted
runtime(python): Highlight classes as structures
Class and function definitions previously shared a single highlight group (pythonFunction). This change gives classes their own highlight group (pythonClass) that's linked to Structure. closes: #17856 Signed-off-by: Jon Parise <[email protected]> Signed-off-by: Zvezdan Petkovic <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e324651 commit 48b7eb1

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

runtime/syntax/python.vim

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim syntax file
22
" Language: Python
33
" Maintainer: Zvezdan Petkovic <[email protected]>
4-
" Last Change: 2025 Jul 17
4+
" Last Change: 2025 Jul 26
55
" Credits: Neil Schemenauer <[email protected]>
66
" Dmitry Vasiliev
77
" Rob B
@@ -97,7 +97,8 @@ endif
9797
syn keyword pythonStatement False None True
9898
syn keyword pythonStatement as assert break continue del global
9999
syn keyword pythonStatement lambda nonlocal pass return with yield
100-
syn keyword pythonStatement class def nextgroup=pythonFunction skipwhite
100+
syn keyword pythonStatement class nextgroup=pythonClass skipwhite
101+
syn keyword pythonStatement def nextgroup=pythonFunction skipwhite
101102
syn keyword pythonConditional elif else if
102103
syn keyword pythonRepeat for while
103104
syn keyword pythonOperator and in is not or
@@ -123,20 +124,21 @@ syn match pythonDecoratorName "@\s*\h\%(\w\|\.\)*" display contains=pythonDeco
123124
" Single line multiplication.
124125
syn match pythonMatrixMultiply
125126
\ "\%(\w\|[])]\)\s*@"
126-
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
127+
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonClass,pythonFunction,pythonDoctestValue
127128
\ transparent
128129
" Multiplication continued on the next line after backslash.
129130
syn match pythonMatrixMultiply
130131
\ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@"
131-
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
132+
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonClass,pythonFunction,pythonDoctestValue
132133
\ transparent
133134
" Multiplication in a parenthesized expression over multiple lines with @ at
134135
" the start of each continued line; very similar to decorators and complex.
135136
syn match pythonMatrixMultiply
136137
\ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*"
137-
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
138+
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonClass,pythonFunction,pythonDoctestValue
138139
\ transparent
139140

141+
syn match pythonClass "\h\w*" display contained
140142
syn match pythonFunction "\h\w*" display contained
141143

142144
syn match pythonComment "#.*$" contains=pythonTodo,@Spell
@@ -279,7 +281,7 @@ if !exists("python_no_builtin_highlight")
279281
syn keyword pythonBuiltin tuple type vars zip __import__
280282
" avoid highlighting attributes as builtins
281283
syn match pythonAttribute /\.\h\w*/hs=s+1
282-
\ contains=ALLBUT,pythonBuiltin,pythonFunction,pythonAsync
284+
\ contains=ALLBUT,pythonBuiltin,pythonClass,pythonFunction,pythonAsync
283285
\ transparent
284286
endif
285287

@@ -336,7 +338,7 @@ if !exists("python_no_doctest_highlight")
336338
if !exists("python_no_doctest_code_highlight")
337339
syn region pythonDoctest
338340
\ start="^\s*>>>\s" end="^\s*$"
339-
\ contained contains=ALLBUT,pythonDoctest,pythonFunction,@Spell
341+
\ contained contains=ALLBUT,pythonDoctest,pythonClass,pythonFunction,@Spell
340342
syn region pythonDoctestValue
341343
\ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
342344
\ contained
@@ -360,6 +362,7 @@ hi def link pythonInclude Include
360362
hi def link pythonAsync Statement
361363
hi def link pythonDecorator Define
362364
hi def link pythonDecoratorName Function
365+
hi def link pythonClass Structure
363366
hi def link pythonFunction Function
364367
hi def link pythonComment Comment
365368
hi def link pythonTodo Todo

0 commit comments

Comments
 (0)