Skip to content

Commit 044d358

Browse files
committed
Add options and fix some highliting problems
1 parent ad60c23 commit 044d358

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

syntax/python.vim

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ if exists("python_highlight_all") && python_highlight_all != 0
118118
if !exists("python_highlight_doctests")
119119
let python_highlight_doctests = 1
120120
endif
121+
if !exists("python_highlight_keywords")
122+
let python_highlight_keywords = 1
123+
endif
124+
if !exists("python_highlight_operator")
125+
let python_highlight_operator = 1
126+
endif
121127
endif
122128

123129
" Keywords
@@ -148,30 +154,34 @@ syn region pythonFuncParams start="("ms=s+1 end=")"me=e-1 contained transparent
148154
syn region pythonParam start="[a-zA-Z_]" end="\(,\|)\s*:\)" contained contains=pythonParamName,pythonParamDefault,pythonDefaultAssignment transparent nextgroup=pythonParam
149155
syn match pythonParamName "[a-zA-Z_][a-zA-Z0-9_]*" contained nextgroup=pythonDefaultAssignment skipwhite skipnl
150156
syn match pythonDefaultAssignment "=" nextgroup=pythonParamDefault skipwhite contained skipnl
151-
152-
syn region pythonFuncCall start="[a-zA-Z_][a-zA-Z0-9_]*(" end=")" contains=pythonFuncCallName,pythonFuncCallArgs
153-
syn match pythonFuncCallName "[a-zA-Z_][a-zA-Z0-9_]*" display contained nextgroup=pythonFuncCallArgs skipwhite
154-
syn region pythonFuncCallArgs start="("ms=s+1 end=")"me=e-1 contained contains=pythonFuncCall,@pythonStringType,@pythonNumberType,@pythonBuiltin,pythonFuncCallKwargs
155-
156-
syn match pythonFuncCallKwargs "[a-zA-Z_][a-zA-Z0-9_]*\s*=" display contained contains=pythonKey,pythonKeyAssign
157-
syn match pythonKey "[a-zA-Z_][a-zA-Z0-9_]*" display contained nextgroup=pythonKeyAssign skipwhite
158-
syn match pythonKeyAssign "=" display contained skipwhite
159-
160157
syn match pythonParamDefault "=\@<=[^,]*" contained transparent contains=@pythonStringType,@pythonNumberType,@pythonBuiltin,pythonKeyword
161158

162-
syn match pythonAssignment "+=\|-=\|\*=\|/=\|//=\|%=\|&=\||=\|\^=\|>>=\|<<=\|\*\*="
163-
syn match pythonAssignment "="
164-
syn match pythonArithmetic "+\|-\|\*\|\*\*\|/\|//\|%\|<<\|>>\|&\||\|\^\|\~"
165-
syn match pythonComparison "<\|>\|<=\|>=\|==\|!=\|<>"
159+
if exists("python_highlight_operator") && python_highlight_operator != 0
160+
syn match pythonAssignment "+=\|-=\|\*=\|/=\|//=\|%=\|&=\||=\|\^=\|>>=\|<<=\|\*\*="
161+
syn match pythonAssignment "="
162+
syn match pythonArithmetic "+\|-\|\*\|\*\*\|/\|//\|%\|<<\|>>\|&\||\|\^\|\~"
163+
syn match pythonComparison "<\|>\|<=\|>=\|==\|!=\|<>"
164+
endif
166165

167166
if !exists("python_print_as_function") || python_print_as_function == 0
168167
syn keyword pythonStatement print
169168
endif
170169

170+
if exists("python_highlight_keywords") && python_highlight_keywords != 0
171+
syn region pythonCallName start="[a-zA-Z_][a-zA-Z0-9_]*(" end=")" fold contains=pythonCall keepend extend
172+
syn region pythonCall start="("ms=s+1 end=")$"me=e-1 contained contains=pythonCallArgs,@pythonExpression
173+
syn match pythonCallArgs "[^,]" contained contains=pythonCallKeyword,pythonCallName,@pythonExpression skipwhite
174+
syn match pythonCallKeyword "[a-zA-Z_][a-zA-Z0-9_]\+\s*=[^=]\{1\}"me=e-1 display contained contains=pythonKeyAssign skipwhite
175+
syn match pythonKeyAssign "=" display contained
176+
endif
177+
171178
" Decorators (new in Python 2.4)
172179
syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite
173-
syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
180+
syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained nextgroup=pythonDecFac
174181
syn match pythonDot "\." display containedin=pythonDottedName
182+
if exists("python_highlight_keywords") && python_highlight_keywords != 0
183+
syn region pythonDecFac start="(" end=")" contained contains=pythonCall keepend skipwhite
184+
endif
175185

176186
" Comments
177187
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
@@ -282,6 +292,7 @@ syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display
282292
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
283293
syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display
284294

295+
syn cluster pythonExpression contains=pythonComparison,pythonOperator,pythonDot,@pythonStringType,@pythonNumberType,@pythonBuiltin,pythonFuncCall
285296
syn cluster pythonStringType contains=pythonString,pythonUniString,pythonRawString,pythonUniRawString
286297
syn cluster pythonNumberType contains=pythonNumber,pythonHexNumber,pythonFloat
287298
syn cluster pythonBuiltin contains=pythonBuiltinObj,pythonBuiltinFunc
@@ -363,8 +374,11 @@ if version >= 508 || !exists("did_python_syn_inits")
363374
HiLink pythonRepeat Repeat
364375
HiLink pythonException Exception
365376
HiLink pythonOperator Operator
377+
HiLink pythonAssignment Operator
378+
HiLink pythonArithmetic Operator
379+
HiLink pythonComparison Operator
366380

367-
HiLink pythonKey Identifier
381+
HiLink pythonCallKeyword Identifier
368382
HiLink pythonKeyAssign Operator
369383

370384
HiLink pythonFuncDef Special
@@ -378,7 +392,7 @@ if version >= 508 || !exists("did_python_syn_inits")
378392

379393
HiLink pythonDecorator Define
380394
HiLink pythonDottedName Function
381-
HiLink pythonDot Normal
395+
HiLink pythonDot Comment
382396

383397
HiLink pythonComment Comment
384398
HiLink pythonCoding Special

0 commit comments

Comments
 (0)