From 41088b9730ce1c98863f2a412ae5703de96dd04c Mon Sep 17 00:00:00 2001 From: "simon@turintech.ai" Date: Sat, 21 Dec 2019 20:28:14 +0000 Subject: [PATCH 1/3] Conceal for operators, type hint highlighting --- syntax/python.vim | 90 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index b7666d86..ba11d33d 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -75,14 +75,18 @@ endif syn keyword pythonStatement pass raise syn keyword pythonStatement global nonlocal assert syn keyword pythonStatement yield - syn keyword pythonLambdaExpr lambda syn keyword pythonStatement with as + " ------------------ conceal lambda ------------------ " + "syn keyword pythonLambdaExpr lambda + syn match pythonLambdaExpr "\" conceal cchar=λ + " ---------------------------------------------------- " + syn keyword pythonStatement def nextgroup=pythonFunction skipwhite syn match pythonFunction "\%(\%(def\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained nextgroup=pythonVars syn region pythonVars start="(" skip=+\(".*"\|'.*'\)+ end=")" contained contains=pythonParameters transparent keepend syn match pythonParameters "[^,]*" contained contains=pythonParam skipwhite - syn match pythonParam "[^,]*" contained contains=pythonExtraOperator,pythonLambdaExpr,pythonBuiltinObj,pythonBuiltinType,pythonConstant,pythonString,pythonNumber,pythonBrackets,pythonSelf,pythonComment skipwhite + syn match pythonParam "[^,]*" contained contains=pythonExtraOperator,pythonLambdaExpr,pythonBuiltinObj,pythonBuiltinType,pythonConstant,pythonString,pythonNumber,pythonBrackets,pythonSelf,pythonComment,pythonTypeHint skipwhite syn match pythonBrackets "{[(|)]}" contained skipwhite syn keyword pythonStatement class nextgroup=pythonClass skipwhite @@ -93,12 +97,36 @@ endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else syn keyword pythonInclude import from + syn keyword pythonOperator is syn keyword pythonException try except finally - syn keyword pythonOperator and in is not or - syn match pythonExtraOperator "\%([~!^&|/%+-]\|\%(class\s*\)\@\|<=\|\%(<\|\>\|>=\|=\@\|\.\.\.\|\.\.\|::\)" + " --------------------- conceal ---------------------- " + syn keyword pythonOperator and conceal cchar=∧ + syn keyword pythonOperator or conceal cchar=∨ + + syn match pythonOperator "\" + syn match pythonOperator "\%(is \)\@\)" conceal cchar=¬ + syn match pythonOperator "\" conceal cchar=∈ + syn match pythonOperator "\" conceal cchar=∉ + " ---------------------------------------------------- " + + syn match pythonExtraOperator "\%([~!^&|/%+-][^>]\@\|<=\|\%(<\|\>\|>=\|[=-]\@\|\.\.\.\|\.\.\|::\)" syn match pythonExtraPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)" + " ---------------------- custom ---------------------- " + "syn match pythonArrow "->" contained + syn match pythonTypeHint "\v: .{-}(\[.*\])? ?[,\)=]"ms=s+2,me=e-1 contains=pythonBuiltinTypeHint contained + syn match pythonReturnHint "\v-\> *.{-}(\[.*\])?:$"ms=s+2,me=e-1 contains=pythonBuiltinTypeHint + " ---------------------------------------------------- " + + + " --------------------- conceal ---------------------- " + syn match pythonExtraOperator "<=" conceal cchar=≤ + syn match pythonExtraOperator ">=" conceal cchar=≥ + syn match pythonExtraOperator "=\@" conceal cchar=∅ + syn match N1 "Non" conceal contained cchar=∅ + syn match N2 "e:"me=e-1 conceal contained cchar= + syn match pythonBuiltinObj "\:"me=e-1 contains=N1,N2 + syn match pythonConstant "\<\%(math\.\)\?pi\>" conceal cchar=π + " ------------------------------------------------ " + " endif if g:pymode_syntax_builtin_types syn keyword pythonBuiltinType type object syn keyword pythonBuiltinType str basestring unicode buffer bytearray bytes chr unichr - syn keyword pythonBuiltinType dict int long bool float complex set frozenset list tuple + syn keyword pythonBuiltinType dict long bool set frozenset list tuple syn keyword pythonBuiltinType file super + + " ------------------ type hints ------------------ " + syn keyword pythonBuiltinTypeHint type object contained + syn keyword pythonBuiltinTypeHint str basestring unicode contained + syn keyword pythonBuiltinTypeHint buffer bytearray bytes chr unichr contained + syn keyword pythonBuiltinTypeHint dict long bool set frozenset list tuple contained + syn keyword pythonBuiltinTypeHint file super contained + " ------------------------------------------------ " + + " ------------------- conceal -------------------- " + syn match pythonOperator "\" conceal cchar=∑ + + syn match pythonStatement "\<\%(math\.\)\?sqrt\>" conceal cchar=√ + syn match pythonStatement "\<\%(math\.\)ceil\>" conceal cchar=⌈ + syn match pythonStatement "\<\%(math\.\)\?floor\>" conceal cchar=⌊ + + syn match pythonStatement "\" conceal cchar=ℤ + syn match pythonStatement "\" conceal cchar=ℝ + syn match pythonStatement "\" conceal cchar=ℂ + " ------------------------------------------------ " + endif " Builtin functions if g:pymode_syntax_builtin_funcs - syn keyword pythonBuiltinFunc __import__ abs all any apply + syn keyword pythonBuiltinFunc __import__ abs apply syn keyword pythonBuiltinFunc bin callable classmethod cmp coerce compile syn keyword pythonBuiltinFunc delattr dir divmod enumerate eval execfile filter syn keyword pythonBuiltinFunc format getattr globals locals hasattr hash help hex id - syn keyword pythonBuiltinFunc input intern isinstance issubclass iter len map max min + syn keyword pythonBuiltinFunc input intern isinstance issubclass iter map max min syn keyword pythonBuiltinFunc next oct open ord pow property range xrange syn keyword pythonBuiltinFunc raw_input reduce reload repr reversed round setattr syn keyword pythonBuiltinFunc slice sorted staticmethod sum vars zip + " ------------------- conceal -------------------- " + syn match pythonBuiltinFunc "\" conceal cchar=∀ + syn match pythonBuiltinFunc "\" conceal cchar=∃ + + syn match pythonBuiltinFunc "\" conceal cchar=# + " ------------------------------------------------ " + if g:pymode_syntax_print_as_function syn keyword pythonBuiltinFunc print endif @@ -344,6 +409,12 @@ endif hi def link pythonBrackets Normal hi def link pythonClassParameters Normal hi def link pythonSelf Identifier + hi def link pythonTypeHint Structure + hi def link pythonReturnHint Structure + hi def link pythonBuiltinTypeHint Type + + hi def link H1 pythonBuiltinType + hi def link H2 pythonBuiltinType hi def link pythonConditional Conditional hi def link pythonRepeat Repeat @@ -399,4 +470,7 @@ endif hi def link pythonExClass Structure + hi! def link Conceal Operator + hi! link Conceal Operator + " }}} From c1dd86669162ca73e701c28db1a3b3d31a76db4c Mon Sep 17 00:00:00 2001 From: simonTurintech Date: Tue, 24 Dec 2019 11:55:37 +0000 Subject: [PATCH 2/3] [bugfix] int and floats inside type hint --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index ba11d33d..861cbcb2 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -314,7 +314,7 @@ endif syn keyword pythonBuiltinTypeHint str basestring unicode contained syn keyword pythonBuiltinTypeHint buffer bytearray bytes chr unichr contained syn keyword pythonBuiltinTypeHint dict long bool set frozenset list tuple contained - syn keyword pythonBuiltinTypeHint file super contained + syn keyword pythonBuiltinTypeHint int float file super contained " ------------------------------------------------ " " ------------------- conceal -------------------- " From da6d2336217dd67c3c376792508bc05d8e009edd Mon Sep 17 00:00:00 2001 From: simonTurintech Date: Wed, 26 Feb 2020 11:43:23 +0000 Subject: [PATCH 3/3] Addition of variables type hints --- syntax/python.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax/python.vim b/syntax/python.vim index 861cbcb2..319a1305 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -116,6 +116,7 @@ endif " ---------------------- custom ---------------------- " "syn match pythonArrow "->" contained syn match pythonTypeHint "\v: .{-}(\[.*\])? ?[,\)=]"ms=s+2,me=e-1 contains=pythonBuiltinTypeHint contained + syn match pythonTypeHint "\v^\s*(\a|_|\.)+\s*:\s*\zs(\a|\.)+\ze\s*\=" contains=pythonBuiltinTypeHint syn match pythonReturnHint "\v-\> *.{-}(\[.*\])?:$"ms=s+2,me=e-1 contains=pythonBuiltinTypeHint " ---------------------------------------------------- "