From 8ab778e013b9e4b4f03d2433727186d2e0e499aa Mon Sep 17 00:00:00 2001 From: wklken Date: Sat, 12 Aug 2017 16:31:10 +0800 Subject: [PATCH 1/5] add highlight for self/cls and more operators, include , and : --- syntax/python.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/syntax/python.vim b/syntax/python.vim index e963628..b314995 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -169,6 +169,16 @@ syn keyword pythonOperator and in is not or syn match pythonStatement "\" display syn match pythonImport "\" display +" ========================================= +" reference https://github.com/kh3phr3n/python-syntax +" self, cls +syn keyword pythonSelf self cls +" operators +" pythonExtra(*)Operator +syn match pythonExtraOperator "\%([~!^&|*/%+-]\|\%(class\s*\)\@\|<=\|\%(<\|\>\|>=\|=\@\|\*\*\|\.\.\.\|\.\.\|::\|=\|:\|,\)" +syn match pythonExtraPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)" +" ========================================= + if s:Python2Syntax() if !s:Enabled("g:python_print_as_function") syn keyword pythonStatement print @@ -562,6 +572,11 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonExClass Structure + " HiLink pythonSelf Identifier + HiLink pythonSelf Boolean + " operator + HiLink pythonExtraOperator Operator + HiLink pythonExtraPseudoOperator Operator delcommand HiLink endif From 1e4aba65c872d9614716dcb24c2f02b963607d7c Mon Sep 17 00:00:00 2001 From: wklken Date: Sun, 13 Aug 2017 01:35:56 +0800 Subject: [PATCH 2/5] do some change, fit for pycharm monokai --- README.rst | 28 ++++++++++++++++++++++++ syntax/python.vim | 55 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 73 insertions(+), 10 deletions(-) diff --git a/README.rst b/README.rst index f9cd20d..e6e882c 100644 --- a/README.rst +++ b/README.rst @@ -1,6 +1,34 @@ Python syntax highlighting script for Vim ========================================= +update: + +``` +" in your .vimrc +let g:python_highlight_pycharm_monokai=1 +``` + +.. reference + +from https://github.com/hdima/python-syntax + +- origin + +from https://github.com/kh3phr3n/python-syntax + +- highlight: self/cls +- hightlight all operator + +.. changelog + +- highlight: ':' +- highlight: ',' +- highlight: None +- highlight: @ + + +---- + .. contents:: About diff --git a/syntax/python.vim b/syntax/python.vim index b314995..75e39fc 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -82,6 +82,7 @@ " python_highlight_file_headers_as_comments " Highlight shebang and coding " headers as comments +" python_highlight_magic_methods Highlight magic methods " " python_highlight_all Enable all the options above " NOTE: This option don't override @@ -144,6 +145,8 @@ if s:Enabled("g:python_highlight_all") call s:EnableByDefault("g:python_highlight_space_errors") call s:EnableByDefault("g:python_highlight_doctests") call s:EnableByDefault("g:python_print_as_function") + call s:EnableByDefault("g:python_highlight_magic_methods") + " call s:EnableByDefault("g:python_highlight_pycharm_monokai") endif " @@ -155,8 +158,9 @@ syn keyword pythonStatement exec return syn keyword pythonStatement pass raise syn keyword pythonStatement global assert syn keyword pythonStatement lambda -syn keyword pythonStatement with -syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite +" syn keyword pythonStatement with +syn keyword pythonConditional with +syn keyword pythonStatement def class nextgroup=pythonFunction,pythonMagicMethod skipwhite syn keyword pythonRepeat for while syn keyword pythonConditional if elif else " The standard pyrex.vim unconditionally removes the pythonInclude group, so @@ -175,8 +179,9 @@ syn match pythonImport "\" display syn keyword pythonSelf self cls " operators " pythonExtra(*)Operator -syn match pythonExtraOperator "\%([~!^&|*/%+-]\|\%(class\s*\)\@\|<=\|\%(<\|\>\|>=\|=\@\|\*\*\|\.\.\.\|\.\.\|::\|=\|:\|,\)" +syn match pythonExtraOperator "\%([~!^&|*/%+-]\|\%(class\s*\)\@\|<=\|\%(<\|\>\|>=\|=\@\|\*\*\|\.\.\.\|\.\.\|::\|=\|:\)" syn match pythonExtraPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)" +syn match pythonComma "," " ========================================= if s:Python2Syntax() @@ -186,7 +191,9 @@ if s:Python2Syntax() syn keyword pythonImport as syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained else - syn keyword pythonStatement as nonlocal None + syn keyword pythonNone None + " syn keyword pythonStatement as nonlocal None + syn keyword pythonStatement as nonlocal syn match pythonStatement "\" display syn keyword pythonBoolean True False syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained @@ -409,7 +416,7 @@ syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display if s:Enabled("g:python_highlight_builtin_objs") if s:Python2Syntax() - syn keyword pythonBuiltinObj None + " syn keyword pythonBuiltinObj None syn keyword pythonBoolean True False endif syn keyword pythonBuiltinObj Ellipsis NotImplemented @@ -487,6 +494,22 @@ if s:Enabled("g:python_highlight_exceptions") syn keyword pythonExClass ImportWarning UnicodeWarning endif + +if s:Enabled("g:python_highlight_magic_methods") +syn keyword pythonMagicMethod contained + \ __new__ __init__ __del__ + \ __str__ __repr__ __unicode__ __hash__ + \ __len__ __nonzero__ + \ __getitem__ __setitem__ __delitem__ + \ __cmp__ __rcmp__ + \ __lt__ __le__ __eq__ __ne__ __gt__ __ge__ + \ __add__ __iadd__ __sub__ __isub__ + \ __contains__ __iter__ + \ __call__ + \ __getattr__ __setattr__ __delattr__ __getattribute__ + \ __get__ __set__ __delete__ +endif + if s:Enabled("g:python_slow_sync") syn sync minlines=2000 else @@ -505,15 +528,13 @@ if version >= 508 || !exists("did_python_syn_inits") command -nargs=+ HiLink hi def link endif - HiLink pythonStatement Statement - HiLink pythonImport Include HiLink pythonFunction Function HiLink pythonConditional Conditional HiLink pythonRepeat Repeat HiLink pythonException Exception + HiLink pythonOperator Operator - HiLink pythonDecorator Define HiLink pythonDottedName Function HiLink pythonDot Normal @@ -572,11 +593,25 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonExClass Structure - " HiLink pythonSelf Identifier - HiLink pythonSelf Boolean " operator HiLink pythonExtraOperator Operator HiLink pythonExtraPseudoOperator Operator + HiLink pythonComma Identifier + HiLink pythonNone Identifier + HiLink pythonMagicMethod Identifier + + if !s:Enabled("g:python_highlight_pycharm_monokai") + HiLink pythonStatement Statement + HiLink pythonImport Include + HiLink pythonDecorator Define + HiLink pythonSelf Identifier + else + HiLink pythonStatement Define + HiLink pythonImport Define + HiLink pythonDecorator Keyword + HiLink pythonSelf Boolean + endif + delcommand HiLink endif From 1f39ff87767f1fe3b8a0909791d7fb3341ca24fd Mon Sep 17 00:00:00 2001 From: wklken Date: Sun, 13 Aug 2017 02:31:52 +0800 Subject: [PATCH 3/5] add class / def func params highlight support --- README.rst | 3 ++- syntax/python.vim | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index e6e882c..e367f48 100644 --- a/README.rst +++ b/README.rst @@ -17,7 +17,8 @@ from https://github.com/hdima/python-syntax from https://github.com/kh3phr3n/python-syntax - highlight: self/cls -- hightlight all operator +- highlight; all operator +- highlight: class/func def params .. changelog diff --git a/syntax/python.vim b/syntax/python.vim index 75e39fc..8189539 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -160,7 +160,10 @@ syn keyword pythonStatement global assert syn keyword pythonStatement lambda " syn keyword pythonStatement with syn keyword pythonConditional with -syn keyword pythonStatement def class nextgroup=pythonFunction,pythonMagicMethod skipwhite +" syn keyword pythonStatement def class nextgroup=pythonFunction,pythonMagicMethod skipwhite +syn keyword pythonStatement class nextgroup=pythonClass skipwhite +syn keyword pythonStatement def nextgroup=pythonFunction,pythonMagicMethod skipwhite + syn keyword pythonRepeat for while syn keyword pythonConditional if elif else " The standard pyrex.vim unconditionally removes the pythonInclude group, so @@ -183,20 +186,41 @@ syn match pythonExtraOperator "\%([~!^&|*/%+-]\|\%(class\s*\)\@\| syn match pythonExtraPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)" syn match pythonComma "," " ========================================= +" Bracket symbols +syn match pythonBrackets "[(|)]" contained skipwhite +" Class parameters +syn match pythonClass "\%(\%(def\s\|class\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained nextgroup=pythonClassVars +syn region pythonClassVars start="(" end=")" contained contains=pythonClassParameters transparent keepend +syn match pythonClassParameters "[^,]*" contained contains=pythonExtraOperator,pythonBoolean,pythonNone,pythonBuiltinObj,pythonComma,pythonBuiltinFunc,pythonConstant,pythonStatement,pythonNumber,pythonString,pythonBrackets skipwhite + +" Function parameters +" syn match pythonFunction "\%(\%(def\s\|class\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained nextgroup=pythonFunctionVars +syn region pythonFunctionVars start="(" end=")" contained contains=pythonFunctionParameters transparent keepend +syn match pythonFunctionParameters "[^,]*" contained contains=pythonSelf,pythonExtraOperator,pythonBoolean,pythonNone,pythonComma,pythonBuiltinObj,pythonBuiltinFunc,pythonConstant,pythonStatement,pythonNumber,pythonString,pythonBrackets skipwhite + +" Function call +" syn region FCall start='[[:alpha:]_]\i*\s*(' end=')' contains=FCall,FCallKeyword +" syn region FCall start='[[:alpha:]_]\i*\s*(' end=')' contains=FCall,FCallKeyword,pythonExtraOperator,pythonBoolean,pythonNone,pythonComma,pythonBuiltinObj,pythonBuiltinFunc,pythonStatement,pythonNumber,pythonString +" syn region FCall start='[[:alpha:]_]\i*\s*(' end=')' contains=FCall,FCallKeyword,pythonExtraOperator,pythonBoolean,pythonNone,pythonComma,pythonBuiltinObj,pythonBuiltinFunc,pythonStatement,pythonNumber,pythonString +" syn match FCallKeyword /\i*\ze\s*=[^=]/ contained +" ========================================= + if s:Python2Syntax() if !s:Enabled("g:python_print_as_function") syn keyword pythonStatement print endif syn keyword pythonImport as - syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained + " syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained + syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" contained nextgroup=pythonFunctionVars else syn keyword pythonNone None " syn keyword pythonStatement as nonlocal None syn keyword pythonStatement as nonlocal syn match pythonStatement "\" display syn keyword pythonBoolean True False - syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained + " syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained + syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" contained nextgroup=pythonFunctionVars syn keyword pythonStatement await syn match pythonStatement "\" nextgroup=pythonFunction skipwhite syn match pythonStatement "\" display @@ -597,9 +621,10 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonExtraOperator Operator HiLink pythonExtraPseudoOperator Operator HiLink pythonComma Identifier - HiLink pythonNone Identifier + HiLink pythonNone Keyword HiLink pythonMagicMethod Identifier + if !s:Enabled("g:python_highlight_pycharm_monokai") HiLink pythonStatement Statement HiLink pythonImport Include @@ -612,6 +637,11 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonSelf Boolean endif + HiLink pythonClass Type + HiLink pythonBrackets Normal + HiLink pythonClassParameters Identifier + HiLink pythonFunctionParameters Identifier + " HiLink FCallKeyword Identifier delcommand HiLink endif From c24d6df50e492e41ca2d87ff64eda00c18ac91da Mon Sep 17 00:00:00 2001 From: wklken Date: Sun, 13 Aug 2017 11:46:45 +0800 Subject: [PATCH 4/5] change some color to blue --- syntax/python.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 8189539..bf7bb83 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -553,11 +553,8 @@ if version >= 508 || !exists("did_python_syn_inits") endif HiLink pythonFunction Function - HiLink pythonConditional Conditional - HiLink pythonRepeat Repeat HiLink pythonException Exception - HiLink pythonOperator Operator HiLink pythonDottedName Function HiLink pythonDot Normal @@ -627,10 +624,19 @@ if version >= 508 || !exists("did_python_syn_inits") if !s:Enabled("g:python_highlight_pycharm_monokai") HiLink pythonStatement Statement + HiLink pythonConditional Conditional + HiLink pythonRepeat Repeat + HiLink pythonOperator Operator HiLink pythonImport Include HiLink pythonDecorator Define HiLink pythonSelf Identifier else + + " plan 1 + HiLink pythonConditional Define + HiLink pythonRepeat Define + HiLink pythonOperator Define + HiLink pythonStatement Define HiLink pythonImport Define HiLink pythonDecorator Keyword From 7b3c6b16792d376a1b8e78d2947fa7893e0115df Mon Sep 17 00:00:00 2001 From: wklken Date: Sun, 20 Aug 2017 15:19:56 +0800 Subject: [PATCH 5/5] update func --- syntax/python.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index bf7bb83..1412af8 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -610,7 +610,6 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonBoolean Boolean HiLink pythonBuiltinObj Structure - HiLink pythonBuiltinFunc Function HiLink pythonExClass Structure @@ -630,6 +629,7 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonImport Include HiLink pythonDecorator Define HiLink pythonSelf Identifier + HiLink pythonBuiltinFunc Function else " plan 1 @@ -641,6 +641,7 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonImport Define HiLink pythonDecorator Keyword HiLink pythonSelf Boolean + HiLink pythonBuiltinFunc Define endif HiLink pythonClass Type