diff --git a/README.rst b/README.rst index f9cd20d..f669d64 100644 --- a/README.rst +++ b/README.rst @@ -3,6 +3,13 @@ Python syntax highlighting script for Vim .. contents:: +ScreenShot +---------- + +Coupled with `onedark theme `_ , this syntax hightlight reproduces 95% of what you get from Atom. + +.. image:: ScreenShot.png + About ----- @@ -11,19 +18,14 @@ Enhanced version of the original Python syntax highlighting script. Based on ca). Check also `python.vim page on vim.org `_. -Please use the following channels for reporting bugs, offering suggestions or -feedback: - -- python.vim issue tracker: https://github.com/hdima/python-syntax/issues -- Email: Dmitry Vasiliev (dima at hlabs.org) -- Send a message or follow me for updates on Twitter: `@hdima - `__ - Features -------- Changes from the original ``python.vim`` are: +- Highlight function calls +- Highlight keyword arguments in function definition and function calls +- Highlight commone python operators like `>=`, `<=`, `|=`, etc - Added support for Python 3 syntax highlighting - Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to switch between Python 2 and Python 3 syntaxes respectively without diff --git a/ScreenShot.png b/ScreenShot.png new file mode 100644 index 0000000..2987ffe Binary files /dev/null and b/ScreenShot.png differ diff --git a/folding-ideas/python.vim.1.13 b/folding-ideas/python.vim.1.13 deleted file mode 100644 index e5ea668..0000000 --- a/folding-ideas/python.vim.1.13 +++ /dev/null @@ -1,237 +0,0 @@ -" Vim syntax file -" Language: Python -" Maintainer: Neil Schemenauer -" Updated: $Date: 2003/01/12 14:17:34 $ -" Updated by: Dmitry Vasiliev -" Filenames: *.py -" $Revision: 1.13 $ -" -" Options: -" For folded functions and classes: -" -" let python_folding = 1 -" -" For highlighted builtin functions: -" -" let python_highlight_builtins = 1 -" -" For highlighted standard exceptions: -" -" let python_highlight_exceptions = 1 -" -" For highlighted string formatting: -" -" let python_highlight_string_formatting = 1 -" -" If you want all possible Python highlighting: -" -" let python_highlight_all = 1 -" -" TODO: Check more errors? - -" For version 5.x: Clear all syntax items -" For version 6.x: Quit when a syntax file was already loaded -if version < 600 - syntax clear -elseif exists("b:current_syntax") - finish -endif - -if exists("python_highlight_all") - let python_folding = 1 - let python_highlight_builtins = 1 - let python_highlight_exceptions = 1 - let python_highlight_string_formatting = 1 -endif - -" Keywords -syn keyword pythonStatement break continue del -syn keyword pythonStatement exec return -syn keyword pythonStatement pass print raise -syn keyword pythonStatement global assert -syn keyword pythonStatement lambda yield -if exists("python_folding") && has("folding") - syn match pythonStatement "\<\(def\|class\)\>" display nextgroup=pythonFunction skipwhite -else - syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite -endif -syn match pythonFunction "\h\w*" display contained -syn keyword pythonRepeat for while -syn keyword pythonConditional if elif else -syn keyword pythonImport import from as -syn keyword pythonException try except finally -syn keyword pythonOperator and in is not or - -" Comments -syn match pythonComment "#.*$" display contains=pythonTodo -syn keyword pythonTodo TODO FIXME XXX contained - -" Erroneous characters that cannont be in a python program -syn match pythonError "[@$?]" display -" Mixing spaces and tabs is bad -syn match pythonIndentError "^\s*\(\t \| \t\)\s*" display - -" Strings -syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"""+ end=+"""+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+'''+ end=+'''+ contains=pythonEscape,pythonEscapeError - -syn match pythonEscape +\\[abfnrtv'"\\]+ display contained -syn match pythonEscapeError +\\[^abfnrtv'"\\]+ display contained -syn match pythonEscape "\\\o\o\=\o\=" display contained -syn match pythonEscapeError "\\\o\{,2}[89]" display contained -syn match pythonEscape "\\x\x\{2}" display contained -syn match pythonEscapeError "\\x\x\=\X" display contained -syn match pythonEscape "\\$" - -" Unicode strings -syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"""+ end=+"""+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]'''+ end=+'''+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError - -syn match pythonUniEscape "\\u\x\{4}" display contained -syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained -syn match pythonUniEscape "\\U\x\{8}" display contained -syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained -syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained -syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained - -" Raw strings -syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"""+ end=+"""+ -syn region pythonRawString start=+[rR]'''+ end=+'''+ - -syn match pythonRawEscape +\\['"]+ display transparent contained - -" Unicode raw strings -syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ contains=pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ contains=pythonUniRawEscape,pythonUniRawEscapeError - -syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained -syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained - -if exists("python_highlight_string_formatting") - " String formatting - syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]\=\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString - syn match pythonStrFormat "%[-#0 +]\=\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString -endif - -" Numbers (ints, longs, floats, complex) -syn match pythonNumber "\<0[xX]\x\+[lL]\=\>" display -syn match pythonNumber "\<\d\+[lLjJ]\=\>" display -syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display -syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display -syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display -syn match pythonOctalError "\<0\o*[89]\d*[lLjJ]\=\>" display - -if exists("python_highlight_builtins") - " Builtin functions, types and objects, not really part of the syntax - syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented - syn keyword pythonBuiltinFunc bool __import__ abs - syn keyword pythonBuiltinFunc apply buffer callable chr classmethod cmp - syn keyword pythonBuiltinFunc coerce compile complex delattr dict dir divmod - syn keyword pythonBuiltinFunc eval execfile file filter float getattr globals - syn keyword pythonBuiltinFunc hasattr hash hex id input int intern isinstance - syn keyword pythonBuiltinFunc issubclass iter len list locals long map max - syn keyword pythonBuiltinFunc min object oct open ord pow property range - syn keyword pythonBuiltinFunc raw_input reduce reload repr round setattr - syn keyword pythonBuiltinFunc slice staticmethod str super tuple type unichr - syn keyword pythonBuiltinFunc unicode vars xrange zip -endif - -if exists("python_highlight_exceptions") - " Builtin exceptions and warnings - syn keyword pythonExClass ArithmeticError AssertionError AttributeError - syn keyword pythonExClass DeprecationWarning EOFError EnvironmentError - syn keyword pythonExClass Exception FloatingPointError IOError - syn keyword pythonExClass ImportError IndentiationError IndexError - syn keyword pythonExClass KeyError KeyboardInterrupt LookupError - syn keyword pythonExClass MemoryError NameError NotImplementedError - syn keyword pythonExClass OSError OverflowError OverflowWarning - syn keyword pythonExClass ReferenceError RuntimeError RuntimeWarning - syn keyword pythonExClass StandardError StopIteration SyntaxError - syn keyword pythonExClass SyntaxWarning SystemError SystemExit TabError - syn keyword pythonExClass TypeError UnboundLocalError UnicodeError - syn keyword pythonExClass UserWarning ValueError Warning WindowsError - syn keyword pythonExClass ZeroDivisionError -endif - -syn sync clear -if exists("python_folding") && has("folding") - syn sync fromstart - - "syn match pythonFold "^\(\s*\)\(class\|def\)\s.*\(\(\n\s*\)*\n\1\s\+\S.*\)\+" transparent fold - syn region pythonFold start="^\z(\s*\)\(class\|def\)\s" skip="^\z1\s\+\S" end="^\s*\S"me=s-1 transparent fold - syn region pythonFold start="{" end="}" transparent fold - syn region pythonFold start="\[" end="\]" transparent fold -else - " This is fast but code inside triple quoted strings screws it up. It - " is impossible to fix because the only way to know if you are inside a - " triple quoted string is to start from the beginning of the file. If - " you have a fast machine you can try uncommenting the "sync minlines" - " and commenting out the rest. - syn sync match pythonSync grouphere NONE "):$" - syn sync maxlines=200 - "syn sync minlines=2000 -endif - -if version >= 508 || !exists("did_python_syn_inits") - if version <= 508 - let did_python_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - - HiLink pythonStatement Statement - HiLink pythonImport Statement - HiLink pythonFunction Function - HiLink pythonConditional Conditional - HiLink pythonRepeat Repeat - HiLink pythonException Exception - HiLink pythonOperator Operator - - HiLink pythonComment Comment - HiLink pythonTodo Todo - - HiLink pythonError Error - HiLink pythonIndentError Error - - HiLink pythonString String - HiLink pythonUniString String - HiLink pythonRawString String - HiLink pythonUniRawString String - - HiLink pythonEscape Special - HiLink pythonEscapeError Error - HiLink pythonUniEscape Special - HiLink pythonUniEscapeError Error - HiLink pythonUniRawEscape Special - HiLink pythonUniRawEscapeError Error - - if exists("python_highlight_string_formatting") - HiLink pythonStrFormat Special - endif - - HiLink pythonNumber Number - HiLink pythonFloat Float - HiLink pythonOctalError Error - - if exists("python_highlight_builtins") - HiLink pythonBuiltinObj Structure - HiLink pythonBuiltinFunc Function - endif - - if exists("python_highlight_exceptions") - HiLink pythonExClass Structure - endif - - delcommand HiLink -endif - -let b:current_syntax = "python" diff --git a/folding-ideas/python.vim.1.14 b/folding-ideas/python.vim.1.14 deleted file mode 100644 index 9027838..0000000 --- a/folding-ideas/python.vim.1.14 +++ /dev/null @@ -1,236 +0,0 @@ -" Vim syntax file -" Language: Python -" Maintainer: Neil Schemenauer -" Updated: $Date: 2003/01/12 15:35:02 $ -" Updated by: Dmitry Vasiliev -" Filenames: *.py -" $Revision: 1.14 $ -" -" Options: -" For folded functions and classes: -" -" let python_folding = 1 -" -" For highlighted builtin functions: -" -" let python_highlight_builtins = 1 -" -" For highlighted standard exceptions: -" -" let python_highlight_exceptions = 1 -" -" For highlighted string formatting: -" -" let python_highlight_string_formatting = 1 -" -" If you want all possible Python highlighting: -" -" let python_highlight_all = 1 -" -" TODO: Check more errors? - -" For version 5.x: Clear all syntax items -" For version 6.x: Quit when a syntax file was already loaded -if version < 600 - syntax clear -elseif exists("b:current_syntax") - finish -endif - -if exists("python_highlight_all") - let python_folding = 1 - let python_highlight_builtins = 1 - let python_highlight_exceptions = 1 - let python_highlight_string_formatting = 1 -endif - -" Keywords -syn keyword pythonStatement break continue del -syn keyword pythonStatement exec return -syn keyword pythonStatement pass print raise -syn keyword pythonStatement global assert -syn keyword pythonStatement lambda yield -if exists("python_folding") && has("folding") - syn match pythonStatement "\<\(def\|class\)\>" display nextgroup=pythonFunction skipwhite -else - syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite -endif -syn match pythonFunction "\h\w*" display contained -syn keyword pythonRepeat for while -syn keyword pythonConditional if elif else -syn keyword pythonImport import from as -syn keyword pythonException try except finally -syn keyword pythonOperator and in is not or - -" Comments -syn match pythonComment "#.*$" display contains=pythonTodo -syn keyword pythonTodo TODO FIXME XXX contained - -" Erroneous characters that cannont be in a python program -syn match pythonError "[@$?]" display -" Mixing spaces and tabs is bad -syn match pythonError "^\s*\(\t \| \t\)\s*" display - -" Strings -syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"""+ end=+"""+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+'''+ end=+'''+ contains=pythonEscape,pythonEscapeError - -syn match pythonEscape +\\[abfnrtv'"\\]+ display contained -syn match pythonEscapeError +\\[^abfnrtv'"\\]+ display contained -syn match pythonEscape "\\\o\o\=\o\=" display contained -syn match pythonEscapeError "\\\o\{,2}[89]" display contained -syn match pythonEscape "\\x\x\{2}" display contained -syn match pythonEscapeError "\\x\x\=\X" display contained -syn match pythonEscape "\\$" - -" Unicode strings -syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"""+ end=+"""+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]'''+ end=+'''+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError - -syn match pythonUniEscape "\\u\x\{4}" display contained -syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained -syn match pythonUniEscape "\\U\x\{8}" display contained -syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained -syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained -syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained - -" Raw strings -syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"""+ end=+"""+ -syn region pythonRawString start=+[rR]'''+ end=+'''+ - -syn match pythonRawEscape +\\['"]+ display transparent contained - -" Unicode raw strings -syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ contains=pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ contains=pythonUniRawEscape,pythonUniRawEscapeError - -syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained -syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained - -if exists("python_highlight_string_formatting") - " String formatting - syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]\=\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString - syn match pythonStrFormat "%[-#0 +]\=\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString -endif - -" Numbers (ints, longs, floats, complex) -syn match pythonNumber "\<0[xX]\x\+[lL]\=\>" display -syn match pythonNumber "\<\d\+[lLjJ]\=\>" display -syn match pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" display -syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display -syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display -syn match pythonOctalError "\<0\o*[89]\d*[lLjJ]\=\>" display - -if exists("python_highlight_builtins") - " Builtin functions, types and objects, not really part of the syntax - syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented - syn keyword pythonBuiltinFunc bool __import__ abs - syn keyword pythonBuiltinFunc apply buffer callable chr classmethod cmp - syn keyword pythonBuiltinFunc coerce compile complex delattr dict dir divmod - syn keyword pythonBuiltinFunc eval execfile file filter float getattr globals - syn keyword pythonBuiltinFunc hasattr hash hex id input int intern isinstance - syn keyword pythonBuiltinFunc issubclass iter len list locals long map max - syn keyword pythonBuiltinFunc min object oct open ord pow property range - syn keyword pythonBuiltinFunc raw_input reduce reload repr round setattr - syn keyword pythonBuiltinFunc slice staticmethod str super tuple type unichr - syn keyword pythonBuiltinFunc unicode vars xrange zip -endif - -if exists("python_highlight_exceptions") - " Builtin exceptions and warnings - syn keyword pythonExClass ArithmeticError AssertionError AttributeError - syn keyword pythonExClass DeprecationWarning EOFError EnvironmentError - syn keyword pythonExClass Exception FloatingPointError IOError - syn keyword pythonExClass ImportError IndentiationError IndexError - syn keyword pythonExClass KeyError KeyboardInterrupt LookupError - syn keyword pythonExClass MemoryError NameError NotImplementedError - syn keyword pythonExClass OSError OverflowError OverflowWarning - syn keyword pythonExClass ReferenceError RuntimeError RuntimeWarning - syn keyword pythonExClass StandardError StopIteration SyntaxError - syn keyword pythonExClass SyntaxWarning SystemError SystemExit TabError - syn keyword pythonExClass TypeError UnboundLocalError UnicodeError - syn keyword pythonExClass UserWarning ValueError Warning WindowsError - syn keyword pythonExClass ZeroDivisionError -endif - -syn sync clear -if exists("python_folding") && has("folding") - syn sync fromstart - - "syn match pythonFold "^\(\s*\)\(class\|def\)\s.*\(\(\n\s*\)*\n\1\s\+\S.*\)\+" transparent fold - syn region pythonFold start="^\z(\s*\)\(class\|def\)\s" skip="\(\s*\n\)\+\z1\s\+\(\S\|\%$\)" end="\(\s*\n\)\+\s*\(\S\|\%$\)"me=s-1 transparent fold - syn region pythonFold start="{" end="}" transparent fold - syn region pythonFold start="\[" end="\]" transparent fold -else - " This is fast but code inside triple quoted strings screws it up. It - " is impossible to fix because the only way to know if you are inside a - " triple quoted string is to start from the beginning of the file. If - " you have a fast machine you can try uncommenting the "sync minlines" - " and commenting out the rest. - syn sync match pythonSync grouphere NONE "):$" - syn sync maxlines=200 - "syn sync minlines=2000 -endif - -if version >= 508 || !exists("did_python_syn_inits") - if version <= 508 - let did_python_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - - HiLink pythonStatement Statement - HiLink pythonImport Statement - HiLink pythonFunction Function - HiLink pythonConditional Conditional - HiLink pythonRepeat Repeat - HiLink pythonException Exception - HiLink pythonOperator Operator - - HiLink pythonComment Comment - HiLink pythonTodo Todo - - HiLink pythonError Error - - HiLink pythonString String - HiLink pythonUniString String - HiLink pythonRawString String - HiLink pythonUniRawString String - - HiLink pythonEscape Special - HiLink pythonEscapeError Error - HiLink pythonUniEscape Special - HiLink pythonUniEscapeError Error - HiLink pythonUniRawEscape Special - HiLink pythonUniRawEscapeError Error - - if exists("python_highlight_string_formatting") - HiLink pythonStrFormat Special - endif - - HiLink pythonNumber Number - HiLink pythonFloat Float - HiLink pythonOctalError Error - - if exists("python_highlight_builtins") - HiLink pythonBuiltinObj Structure - HiLink pythonBuiltinFunc Function - endif - - if exists("python_highlight_exceptions") - HiLink pythonExClass Structure - endif - - delcommand HiLink -endif - -let b:current_syntax = "python" diff --git a/syntax/python.vim b/syntax/python.vim index e963628..d5ed4c9 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -149,14 +149,16 @@ endif " " Keywords " - +syn keyword pythonClassVar self cls +syn keyword pythonLogLevel CRITICAL DEBUG INFO WARN ERROR syn keyword pythonStatement break continue del 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 pythonDefine def nextgroup=pythonFunction skipwhite +syn keyword pythonDefine class nextgroup=pythonClass skipwhite syn keyword pythonRepeat for while syn keyword pythonConditional if elif else " The standard pyrex.vim unconditionally removes the pythonInclude group, so @@ -166,7 +168,26 @@ syn keyword pythonImport import syn keyword pythonException try except finally syn keyword pythonOperator and in is not or -syn match pythonStatement "\" display +syn match pythonOperator "\v\=" +syn match pythonOperator "\v\>" +syn match pythonOperator "\v\<" +syn match pythonOperator "\v\&" +syn match pythonOperator "\v\|" +syn match pythonOperator "\v\+" +syn match pythonOperator "\v\-" +syn match pythonOperator "\v\*" +syn match pythonOperator "\v\/" +syn match pythonOperator "\v\~" +syn match pythonOperator "\v\=\=" +syn match pythonOperator "\v\!\=" +syn match pythonOperator "\v\+\=" +syn match pythonOperator "\v\-\=" +syn match pythonOperator "\v\*\=" +syn match pythonOperator "\v\/\=" +syn match pythonOperator "\v\|\=" +syn match pythonOperator "\v\>\=" +syn match pythonOperator "\v\<\=" +syn match pythonOperator "\" display syn match pythonImport "\" display if s:Python2Syntax() @@ -175,27 +196,27 @@ if s:Python2Syntax() endif syn keyword pythonImport as syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained + syn match pythonClass "[a-zA-Z_][a-zA-Z0-9_]*" display contained else - syn keyword pythonStatement as nonlocal None + syn keyword pythonStatement as nonlocal + syn keyword pythonFloat None object syn match pythonStatement "\" display syn keyword pythonBoolean True False syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained + syn match pythonClass "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained syn keyword pythonStatement await syn match pythonStatement "\" nextgroup=pythonFunction skipwhite syn match pythonStatement "\" display syn match pythonStatement "\" display endif + " " Decorators (new in Python 2.4) " syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite -if s:Python2Syntax() - syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained -else - syn match pythonDottedName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*" display contained -endif +syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained syn match pythonDot "\." display containedin=pythonDottedName " @@ -399,7 +420,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 pythonFloat None syn keyword pythonBoolean True False endif syn keyword pythonBuiltinObj Ellipsis NotImplemented @@ -429,7 +450,7 @@ if s:Enabled("g:python_highlight_builtin_funcs") syn keyword pythonBuiltinFunc globals hasattr hash hex id syn keyword pythonBuiltinFunc input int isinstance syn keyword pythonBuiltinFunc issubclass iter len list locals map max - syn keyword pythonBuiltinFunc min next object oct open ord + syn keyword pythonBuiltinFunc min next oct open ord syn keyword pythonBuiltinFunc pow property range syn keyword pythonBuiltinFunc repr reversed round set setattr syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple @@ -487,6 +508,16 @@ else syn sync maxlines=200 endif +" keywords +syn match pythonModule '\.*[a-zA-Z_]\i*[a-zA-Z0-9_]\i*\.' contains=pythonDot +syn match pythonCappedVariable '\<[A-Z0-9_]\+\>' + +syn match pythonFunctionCall '[a-zA-Z0-9_]\i*(' contains=pythonFunctionVariable +syn region pythonFunctionVariable matchgroup=pythonParenthesis start='(' end=')' contains=pythonFunctionCall,pythonKeyword,pythonBoolean,pythonFloat,pythonNumber,pythonString,pythonOperator,pythonModule,pythonLogLevel,pythonConditional,pythonRepeat,pythonStatement,pythonBuiltinObj,pythonBuiltinFunc,pythonClassVar,pythonCappedVariable +syn match pythonKeyword /\i*\ze=[^=]/ contained +" syn match pythonEqual "=" contained + + if version >= 508 || !exists("did_python_syn_inits") if version <= 508 let did_python_syn_inits = 1 @@ -495,6 +526,12 @@ if version >= 508 || !exists("did_python_syn_inits") command -nargs=+ HiLink hi def link endif + HiLink pythonEqual Operator + HiLink pythonFunctionCall Function + HiLink pythonCappedVariable Constant + HiLink pythonKeyword Number + HiLink pythonLogLevel Identifier + HiLink pythonClassVar Identifier HiLink pythonStatement Statement HiLink pythonImport Include HiLink pythonFunction Function @@ -502,10 +539,12 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonRepeat Repeat HiLink pythonException Exception HiLink pythonOperator Operator - + + HiLink pythonDefine Define HiLink pythonDecorator Define HiLink pythonDottedName Function HiLink pythonDot Normal + HiLink pythonModule Identifier HiLink pythonComment Comment if !s:Enabled("g:python_highlight_file_headers_as_comments")