better python syntax

This commit is contained in:
ManjaroOne666 2018-03-31 12:17:33 +01:00
parent 3d96c5e1c7
commit a2848dde6f
2 changed files with 386 additions and 517 deletions

View File

@ -1,269 +1,206 @@
" Vim syntax file " vim: ft=vim:fdm=marker
" Language: Python " https://github.com/python-mode/python-mode/blob/develop/syntax/python.vim
" Maintainer: Dmitry Vasiliev <dima at hlabs dot org>
" URL: https://github.com/hdima/python-syntax
" Last Change: 2013-11-18
" Filenames: *.py
" Version: 3.3.6
"
" Based on python.vim (from Vim 6.1 distribution)
" by Neil Schemenauer <nas at python dot ca>
"
" Please use the following channels for reporting bugs, offering suggestions or
" feedback:
" - python.vim issue tracker: https://github.com/hdima/python-syntax/issues " Enable pymode syntax for python files
" - Email: Dmitry Vasiliev (dima at hlabs.org) " call pymode#default('g:pymode', 1)
" - Send a message or follow me for updates on Twitter: `@hdima " call pymode#default('g:pymode_syntax', g:pymode)
" <https://twitter.com/hdima>`__
"
" Contributors
" ============
"
" List of the contributors in alphabetical order:
"
" Andrea Riciputi
" Anton Butanaev
" Caleb Adamantine
" Elizabeth Myers
" Jeroen Ruigrok van der Werven
" John Eikenberry
" Marc Weber
" Pedro Algarvio
" pydave at GitHub
" Will Gray
" Yuri Habrusiev
"
" Options
" =======
"
" :let OPTION_NAME = 1 Enable option
" :let OPTION_NAME = 0 Disable option
"
"
" Option to select Python version
" -------------------------------
"
" python_version_2 Enable highlighting for Python 2
" (Python 3 highlighting is enabled
" by default). Can also be set as
" a buffer (b:python_version_2)
" variable.
"
" You can also use the following local to buffer commands to switch
" between two highlighting modes:
"
" :Python2Syntax Switch to Python 2 highlighting
" mode
" :Python3Syntax Switch to Python 3 highlighting
" mode
"
" Option names used by the script
" -------------------------------
"
" python_highlight_builtins Highlight builtin functions and
" objects
" python_highlight_builtin_objs Highlight builtin objects only
" python_highlight_builtin_funcs Highlight builtin functions only
" python_highlight_exceptions Highlight standard exceptions
" python_highlight_string_formatting Highlight % string formatting
" python_highlight_string_format Highlight str.format syntax
" python_highlight_string_templates Highlight string.Template syntax
" python_highlight_indent_errors Highlight indentation errors
" python_highlight_space_errors Highlight trailing spaces
" python_highlight_doctests Highlight doc-tests
" python_print_as_function Highlight 'print' statement as
" function for Python 2
" python_highlight_file_headers_as_comments
" Highlight shebang and coding
" headers as comments
"
" python_highlight_all Enable all the options above
" NOTE: This option don't override
" any previously set options
"
" python_slow_sync Can be set to 0 for slow machines
"
" For version 5.x: Clear all syntax items " DESC: Disable script loading
" For versions greater than 6.x: Quit when a syntax file was already loaded if !g:pymode || !g:pymode_syntax
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish finish
endif endif
" " OPTIONS: {{{
" Commands
"
command! -buffer Python2Syntax let b:python_version_2 = 1 | let &syntax=&syntax
command! -buffer Python3Syntax let b:python_version_2 = 0 | let &syntax=&syntax
" Enable option if it's not defined " Highlight all by default
function! s:EnableByDefault(name) "call pymode#default('g:pymode_syntax_all', 1)
if !exists(a:name)
let {a:name} = 1
endif
endfunction
" Check if option is enabled "" Highlight 'print' as function
function! s:Enabled(name) "call pymode#default("g:pymode_syntax_print_as_function", 0)
return exists(a:name) && {a:name} ""
endfunction "" Highlight 'async/await' keywords
"call pymode#default("g:pymode_syntax_highlight_async_await", g:pymode_syntax_all)
" Is it Python 2 syntax? "" Highlight '=' operator
function! s:Python2Syntax() "call pymode#default('g:pymode_syntax_highlight_equal_operator', g:pymode_syntax_all)
if exists("b:python_version_2")
return b:python_version_2
endif
return s:Enabled("g:python_version_2")
endfunction
" "" Highlight '*' operator
" Default options "call pymode#default('g:pymode_syntax_highlight_stars_operator', g:pymode_syntax_all)
"
call s:EnableByDefault("g:python_slow_sync") "" Highlight 'self' keyword
"call pymode#default('g:pymode_syntax_highlight_self', g:pymode_syntax_all)
if s:Enabled("g:python_highlight_all") "" Highlight indent's errors
call s:EnableByDefault("g:python_highlight_builtins") "call pymode#default('g:pymode_syntax_indent_errors', g:pymode_syntax_all)
if s:Enabled("g:python_highlight_builtins")
call s:EnableByDefault("g:python_highlight_builtin_objs") "" Highlight space's errors
call s:EnableByDefault("g:python_highlight_builtin_funcs") "call pymode#default('g:pymode_syntax_space_errors', g:pymode_syntax_all)
endif
call s:EnableByDefault("g:python_highlight_exceptions") "" Highlight string formatting
call s:EnableByDefault("g:python_highlight_string_formatting") "call pymode#default('g:pymode_syntax_string_formatting', g:pymode_syntax_all)
call s:EnableByDefault("g:python_highlight_string_format") "call pymode#default('g:pymode_syntax_string_format', g:pymode_syntax_all)
call s:EnableByDefault("g:python_highlight_string_templates") "call pymode#default('g:pymode_syntax_string_templates', g:pymode_syntax_all)
call s:EnableByDefault("g:python_highlight_indent_errors") "call pymode#default('g:pymode_syntax_doctests', g:pymode_syntax_all)
call s:EnableByDefault("g:python_highlight_space_errors")
call s:EnableByDefault("g:python_highlight_doctests") "" Support docstrings in syntax highlighting
call s:EnableByDefault("g:python_print_as_function") "call pymode#default('g:pymode_syntax_docstrings', 1)
"" Highlight builtin objects (True, False, ...)
"call pymode#default('g:pymode_syntax_builtin_objs', g:pymode_syntax_all)
"" Highlight builtin types (str, list, ...)
"call pymode#default('g:pymode_syntax_builtin_types', g:pymode_syntax_all)
"" Highlight builtin types (div, eval, ...)
"call pymode#default('g:pymode_syntax_builtin_funcs', g:pymode_syntax_all)
"" Highlight exceptions (TypeError, ValueError, ...)
"call pymode#default('g:pymode_syntax_highlight_exceptions', g:pymode_syntax_all)
"" More slow synchronizing. Disable on the slow machine, but code in docstrings
"" could be broken.
"call pymode#default('g:pymode_syntax_slow_sync', 1)
" }}}
" For version 5.x: Clear all syntax items
if version < 600
syntax clear
endif endif
" " Keywords {{{
" Keywords " ============
"
syn keyword pythonStatement break continue del syn keyword pythonStatement break continue del
syn keyword pythonStatement exec return syn keyword pythonStatement exec return
syn keyword pythonStatement pass raise syn keyword pythonStatement pass raise
syn keyword pythonStatement global assert syn keyword pythonStatement global nonlocal assert
syn keyword pythonStatement lambda syn keyword pythonStatement yield
syn keyword pythonStatement with syn keyword pythonLambdaExpr lambda
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite syn keyword pythonStatement with as
syn keyword pythonRepeat for while
syn keyword pythonConditional if elif else
syn keyword pythonImport import
syn keyword pythonException try except finally
syn keyword pythonOperator and in is not or
syn match pythonStatement "\<yield\>" display syn keyword pythonStatement def nextgroup=pythonFunction skipwhite
syn match pythonImport "\<from\>" display 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 pythonBrackets "{[(|)]}" contained skipwhite
if s:Python2Syntax() syn keyword pythonStatement class nextgroup=pythonClass skipwhite
if !s:Enabled("g:python_print_as_function") syn match pythonClass "\%(\%(class\s\)\s*\)\@<=\h\%(\w\|\.\)*" contained nextgroup=pythonClassVars
syn region pythonClassVars start="(" end=")" contained contains=pythonClassParameters transparent keepend
syn match pythonClassParameters "[^,\*]*" contained contains=pythonBuiltin,pythonBuiltinObj,pythonBuiltinType,pythonExtraOperatorpythonStatement,pythonBrackets,pythonString,pythonComment skipwhite
syn keyword pythonRepeat for while
syn keyword pythonConditional if elif else
syn keyword pythonInclude import from
syn keyword pythonException try except finally
syn keyword pythonOperator and in is not or
syn match pythonExtraOperator "\%([~!^&|/%+-]\|\%(class\s*\)\@<!<<\|<=>\|<=\|\%(<\|\<class\s\+\u\w*\s*\)\@<!<[^<]\@=\|===\|==\|=\~\|>>\|>=\|=\@<!>\|\.\.\.\|\.\.\|::\)"
syn match pythonExtraPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)"
if !g:pymode_syntax_print_as_function
syn keyword pythonStatement print syn keyword pythonStatement print
endif endif
syn keyword pythonImport as
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
else
syn keyword pythonStatement as nonlocal None
syn match pythonStatement "\<yield\s\+from\>" display
syn keyword pythonBoolean True False
syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
endif
" if g:pymode_syntax_highlight_async_await
" Decorators (new in Python 2.4) syn keyword pythonStatement async await
" syn match pythonStatement "\<async\s\+def\>" nextgroup=pythonFunction skipwhite
syn match pythonStatement "\<async\s\+with\>" display
syn match pythonStatement "\<async\s\+for\>" nextgroup=pythonRepeat skipwhite
endif
syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite if g:pymode_syntax_highlight_equal_operator
syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained syn match pythonExtraOperator "\%(=\)"
syn match pythonDot "\." display containedin=pythonDottedName endif
" if g:pymode_syntax_highlight_stars_operator
" Comments syn match pythonExtraOperator "\%(\*\|\*\*\)"
" endif
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell if g:pymode_syntax_highlight_self
if !s:Enabled("g:python_highlight_file_headers_as_comments") syn keyword pythonSelf self cls
endif
" }}}
" Decorators {{{
" ==============
syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite
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
" }}}
" Comments {{{
" ============
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
syn match pythonRun "\%^#!.*$" syn match pythonRun "\%^#!.*$"
syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$" syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
endif syn keyword pythonTodo TODO FIXME XXX contained
syn keyword pythonTodo TODO FIXME XXX contained
" " }}}
" Errors
"
syn match pythonError "\<\d\+\D\+\>" display " Errors {{{
syn match pythonError "[$?]" display " ==========
syn match pythonError "[&|]\{2,}" display
syn match pythonError "[=]\{3,}" display
" Mixing spaces and tabs also may be used for pretty formatting multiline syn match pythonError "\<\d\+\D\+\>" display
" statements syn match pythonError "[$?]" display
if s:Enabled("g:python_highlight_indent_errors") syn match pythonError "[&|]\{2,}" display
syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display syn match pythonError "[=]\{3,}" display
endif
" Trailing space errors " Indent errors (mix space and tabs)
if s:Enabled("g:python_highlight_space_errors") if g:pymode_syntax_indent_errors
syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display
endif
" Trailing space errors
if g:pymode_syntax_space_errors
syn match pythonSpaceError "\s\+$" display syn match pythonSpaceError "\s\+$" display
endif endif
" " }}}
" Strings
"
if s:Python2Syntax() " Strings {{{
" Python 2 strings " ===========
syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
else
" Python 3 byte strings
syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
syn region pythonBytes start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
syn region pythonBytes start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
syn match pythonBytesError ".\+" display contained syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
endif syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest,pythonSpaceError,@Spell
syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained syn match pythonEscape +\\[abfnrtv'"\\]+ display contained
syn match pythonBytesEscape "\\\o\o\=\o\=" display contained syn match pythonEscape "\\\o\o\=\o\=" display contained
syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained syn match pythonEscapeError "\\\o\{,2}[89]" display contained
syn match pythonBytesEscape "\\x\x\{2}" display contained syn match pythonEscape "\\x\x\{2}" display contained
syn match pythonBytesEscapeError "\\x\x\=\X" display contained syn match pythonEscapeError "\\x\x\=\X" display contained
syn match pythonBytesEscape "\\$" syn match pythonEscape "\\$"
syn match pythonUniEscape "\\u\x\{4}" display contained " Unicode
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
syn match pythonUniEscape "\\U\x\{8}" display contained syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
if s:Python2Syntax() syn match pythonUniEscape "\\u\x\{4}" display contained
" Python 2 Unicode strings syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn match pythonUniEscape "\\U\x\{8}" display contained
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
else
" Python 3 strings
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
endif
if s:Python2Syntax() " Raw strings
" Python 2 Unicode raw strings syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
syn match pythonRawEscape +\\['"]+ display transparent contained
" Unicode raw strings
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
@ -271,177 +208,95 @@ if s:Python2Syntax()
syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
endif
" Python 2/3 raw strings " String formatting
if s:Python2Syntax() if g:pymode_syntax_string_formatting
syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell syn match pythonStrFormatting "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell syn match pythonStrFormatting "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn region pythonRawString start=+[bB]\=[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
syn region pythonRawString start=+[bB]\=[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
else
syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
syn region pythonRawBytes start=+[bB][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawBytes start=+[bB][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawBytes start=+[bB][rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
syn region pythonRawBytes start=+[bB][rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
endif
syn match pythonRawEscape +\\['"]+ display transparent contained
if s:Enabled("g:python_highlight_string_formatting")
" % operator string formatting
if s:Python2Syntax()
syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
else
syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
endif endif
endif
if s:Enabled("g:python_highlight_string_format") " Str.format syntax
" str.format syntax if g:pymode_syntax_string_format
if s:Python2Syntax() syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrFormat "{\([a-zA-Z0-9_]*\|\d\+\)\(\.[a-zA-Z_][a-zA-Z0-9_]*\|\[\(\d\+\|[^!:\}]\+\)\]\)*\(![rs]\)\=\(:\({\([a-zA-Z_][a-zA-Z0-9_]*\|\d\+\)}\|\([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*\(\.\d\+\)\=[bcdeEfFgGnoxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
else
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
endif endif
endif
if s:Enabled("g:python_highlight_string_templates") " String templates
" string.Template format if g:pymode_syntax_string_templates
if s:Python2Syntax() syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
else
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
endif endif
endif
if s:Enabled("g:python_highlight_doctests")
" DocTests " DocTests
if g:pymode_syntax_doctests
syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
endif
"
" Numbers (ints, longs, floats, complex)
"
if s:Python2Syntax()
syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display
syn match pythonOctError "\<0[oO]\=\o*\D\+\d*[lL]\=\>" display
syn match pythonBinError "\<0[bB][01]*\D\+\d*[lL]\=\>" display
syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display
syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display
syn match pythonNumberError "\<\d\+\D[lL]\=\>" display
syn match pythonNumber "\<\d[lL]\=\>" display
syn match pythonNumber "\<[0-9]\d\+[lL]\=\>" display
syn match pythonNumber "\<\d\+[lLjJ]\>" display
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display
else
syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*\>" display
syn match pythonOctError "\<0[oO]\=\o*\D\+\d*\>" display
syn match pythonBinError "\<0[bB][01]*\D\+\d*\>" display
syn match pythonHexNumber "\<0[xX]\x\+\>" display
syn match pythonOctNumber "\<0[oO]\o\+\>" display
syn match pythonBinNumber "\<0[bB][01]\+\>" display
syn match pythonNumberError "\<\d\+\D\>" display
syn match pythonNumberError "\<0\d\+\>" display
syn match pythonNumber "\<\d\>" display
syn match pythonNumber "\<[1-9]\d\+\>" display
syn match pythonNumber "\<\d\+[jJ]\>" display
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*\>" display
syn match pythonBinError "\<0[bB][01]*[2-9]\d*\>" display
endif
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
"
" Builtin objects and types
"
if s:Enabled("g:python_highlight_builtin_objs")
if s:Python2Syntax()
syn keyword pythonBuiltinObj None
syn keyword pythonBoolean True False
endif endif
syn keyword pythonBuiltinObj Ellipsis NotImplemented
" DocStrings
if g:pymode_syntax_docstrings
syn region pythonDocstring start=+^\s*[uU]\?[rR]\?"""+ end=+"""+ keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError
syn region pythonDocstring start=+^\s*[uU]\?[rR]\?'''+ end=+'''+ keepend excludenl contains=pythonEscape,@Spell,pythonDoctest,pythonDocTest2,pythonSpaceError
endif
" }}}
" Numbers {{{
" ===========
syn match pythonHexError "\<0[xX][0-9a-fA-F_]*[g-zG-Z][0-9a-fA-F_]*[lL]\=\>" display
syn match pythonHexNumber "\<0[xX][0-9a-fA-F_]*[0-9a-fA-F][0-9a-fA-F_]*[lL]\=\>" display
syn match pythonOctNumber "\<0[oO][0-7_]*[0-7][0-7_]*[lL]\=\>" display
syn match pythonBinNumber "\<0[bB][01_]*[01][01_]*[lL]\=\>" display
syn match pythonNumber "\<[0-9][0-9_]*[lLjJ]\=\>" display
syn match pythonFloat "\.[0-9_]*[0-9][0-9_]*\([eE][+-]\=[0-9_]*[0-9][0-9_]*\)\=[jJ]\=\>" display
syn match pythonFloat "\<[0-9][0-9_]*[eE][+-]\=[0-9_]\+[jJ]\=\>" display
syn match pythonFloat "\<[0-9][0-9_]*\.[0-9_]*\([eE][+-]\=[0-9_]*[0-9][0-9_]*\)\=[jJ]\=" display
syn match pythonOctError "\<0[oO]\=[0-7_]*[8-9][0-9_]*[lL]\=\>" display
syn match pythonBinError "\<0[bB][01_]*[2-9][0-9_]*[lL]\=\>" display
" }}}
" Builtins {{{
" ============
" Builtin objects and types
if g:pymode_syntax_builtin_objs
syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
endif endif
" if g:pymode_syntax_builtin_types
" Builtin functions 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 file super
endif
if s:Enabled("g:python_highlight_builtin_funcs") " Builtin functions
if s:Python2Syntax() if g:pymode_syntax_builtin_funcs
syn keyword pythonBuiltinFunc apply basestring buffer callable coerce syn keyword pythonBuiltinFunc __import__ abs all any apply
syn keyword pythonBuiltinFunc execfile file help intern long raw_input syn keyword pythonBuiltinFunc bin callable classmethod cmp coerce compile
syn keyword pythonBuiltinFunc reduce reload unichr unicode xrange syn keyword pythonBuiltinFunc delattr dir divmod enumerate eval execfile filter
if s:Enabled("g:python_print_as_function") 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 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
if g:pymode_syntax_print_as_function
syn keyword pythonBuiltinFunc print syn keyword pythonBuiltinFunc print
endif endif
else
syn keyword pythonBuiltinFunc ascii exec memoryview print
endif endif
syn keyword pythonBuiltinFunc __import__ abs all any
syn keyword pythonBuiltinFunc bin bool bytearray bytes
syn keyword pythonBuiltinFunc chr classmethod cmp compile complex
syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
syn keyword pythonBuiltinFunc filter float format frozenset getattr
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 pow property range
syn keyword pythonBuiltinFunc repr reversed round set setattr
syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
syn keyword pythonBuiltinFunc type vars zip
endif
" " Builtin exceptions and warnings
" Builtin exceptions and warnings if g:pymode_syntax_highlight_exceptions
"
if s:Enabled("g:python_highlight_exceptions")
if s:Python2Syntax()
syn keyword pythonExClass StandardError
else
syn keyword pythonExClass BlockingIOError ChildProcessError
syn keyword pythonExClass ConnectionError BrokenPipeError
syn keyword pythonExClass ConnectionAbortedError ConnectionRefusedError
syn keyword pythonExClass ConnectionResetError FileExistsError
syn keyword pythonExClass FileNotFoundError InterruptedError
syn keyword pythonExClass IsADirectoryError NotADirectoryError
syn keyword pythonExClass PermissionError ProcessLookupError TimeoutError
syn keyword pythonExClass ResourceWarning
endif
syn keyword pythonExClass BaseException syn keyword pythonExClass BaseException
syn keyword pythonExClass Exception ArithmeticError syn keyword pythonExClass Exception StandardError ArithmeticError
syn keyword pythonExClass LookupError EnvironmentError syn keyword pythonExClass LookupError EnvironmentError
syn keyword pythonExClass AssertionError AttributeError BufferError EOFError syn keyword pythonExClass AssertionError AttributeError BufferError EOFError
syn keyword pythonExClass FloatingPointError GeneratorExit IOError syn keyword pythonExClass FloatingPointError GeneratorExit IOError
syn keyword pythonExClass ImportError IndexError KeyError syn keyword pythonExClass ImportError IndexError KeyError
@ -454,14 +309,15 @@ if s:Enabled("g:python_highlight_exceptions")
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
syn keyword pythonExClass UnicodeTranslateError ValueError VMSError syn keyword pythonExClass UnicodeTranslateError ValueError VMSError
syn keyword pythonExClass WindowsError ZeroDivisionError syn keyword pythonExClass WindowsError ZeroDivisionError
syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning
syn keyword pythonExClass PendingDepricationWarning SyntaxWarning syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
syn keyword pythonExClass RuntimeWarning FutureWarning syn keyword pythonExClass RuntimeWarning FutureWarning
syn keyword pythonExClass ImportWarning UnicodeWarning syn keyword pythonExClass ImportWarning UnicodeWarning
endif endif
if s:Enabled("g:python_slow_sync") " }}}
if g:pymode_syntax_slow_sync
syn sync minlines=2000 syn sync minlines=2000
else else
" This is fast but code inside triple quoted strings screws it up. It " This is fast but code inside triple quoted strings screws it up. It
@ -471,82 +327,73 @@ else
syn sync maxlines=200 syn sync maxlines=200
endif endif
if version >= 508 || !exists("did_python_syn_inits") " Highlight {{{
if version <= 508 " =============
let did_python_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink pythonStatement Statement hi def link pythonStatement Statement
HiLink pythonImport Include hi def link pythonLambdaExpr Statement
HiLink pythonFunction Function hi def link pythonInclude Include
HiLink pythonConditional Conditional hi def link pythonFunction Function
HiLink pythonRepeat Repeat hi def link pythonClass Type
HiLink pythonException Exception hi def link pythonParameters Normal
HiLink pythonOperator Operator hi def link pythonParam Normal
hi def link pythonBrackets Normal
hi def link pythonClassParameters Normal
hi def link pythonSelf Identifier
HiLink pythonDecorator Define hi def link pythonConditional Conditional
HiLink pythonDottedName Function hi def link pythonRepeat Repeat
HiLink pythonDot Normal hi def link pythonException Exception
hi def link pythonOperator Operator
hi def link pythonExtraOperator Operator
hi def link pythonExtraPseudoOperator Operator
HiLink pythonComment Comment hi def link pythonDecorator Define
if !s:Enabled("g:python_highlight_file_headers_as_comments") hi def link pythonDottedName Function
HiLink pythonCoding Special hi def link pythonDot Normal
HiLink pythonRun Special
endif
HiLink pythonTodo Todo
HiLink pythonError Error hi def link pythonComment Comment
HiLink pythonIndentError Error hi def link pythonCoding Special
HiLink pythonSpaceError Error hi def link pythonRun Special
hi def link pythonTodo Todo
HiLink pythonString String hi def link pythonError Error
HiLink pythonRawString String hi def link pythonIndentError Error
hi def link pythonSpaceError Error
HiLink pythonUniEscape Special hi def link pythonString String
HiLink pythonUniEscapeError Error hi def link pythonDocstring String
hi def link pythonUniString String
hi def link pythonRawString String
hi def link pythonUniRawString String
if s:Python2Syntax() hi def link pythonEscape Special
HiLink pythonUniString String hi def link pythonEscapeError Error
HiLink pythonUniRawString String hi def link pythonUniEscape Special
HiLink pythonUniRawEscape Special hi def link pythonUniEscapeError Error
HiLink pythonUniRawEscapeError Error hi def link pythonUniRawEscape Special
else hi def link pythonUniRawEscapeError Error
HiLink pythonBytes String
HiLink pythonRawBytes String
HiLink pythonBytesContent String
HiLink pythonBytesError Error
HiLink pythonBytesEscape Special
HiLink pythonBytesEscapeError Error
endif
HiLink pythonStrFormatting Special hi def link pythonStrFormatting Special
HiLink pythonStrFormat Special hi def link pythonStrFormat Special
HiLink pythonStrTemplate Special hi def link pythonStrTemplate Special
HiLink pythonDocTest Special hi def link pythonDocTest Special
HiLink pythonDocTest2 Special hi def link pythonDocTest2 Special
HiLink pythonNumber Number hi def link pythonNumber Number
HiLink pythonHexNumber Number hi def link pythonHexNumber Number
HiLink pythonOctNumber Number hi def link pythonOctNumber Number
HiLink pythonBinNumber Number hi def link pythonBinNumber Number
HiLink pythonFloat Float hi def link pythonFloat Float
HiLink pythonNumberError Error hi def link pythonOctError Error
HiLink pythonOctError Error hi def link pythonHexError Error
HiLink pythonHexError Error hi def link pythonBinError Error
HiLink pythonBinError Error
HiLink pythonBoolean Boolean hi def link pythonBuiltinType Type
hi def link pythonBuiltinObj Structure
hi def link pythonBuiltinFunc Function
HiLink pythonBuiltinObj Structure hi def link pythonExClass Structure
HiLink pythonBuiltinFunc Function
HiLink pythonExClass Structure " }}}
delcommand HiLink
endif
let b:current_syntax = "python"

22
vimrc.d/pymode.vim Normal file
View File

@ -0,0 +1,22 @@
let g:pymode = 1
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
let g:pymode_syntax_print_as_function = 1
let g:pymode_syntax_highlight_async_await = 1
let g:pymode_syntax_highlight_equal_operator = 1
let g:pymode_syntax_highlight_stars_operator = 1
let g:pymode_syntax_highlight_self = 1
let g:pymode_syntax_indent_errors = 0
let g:pymode_syntax_space_errors = 0
let g:pymode_syntax_string_formatting = 1
let g:pymode_syntax_string_format = 1
let g:pymode_syntax_string_templates = 1
let g:pymode_syntax_doctests = 1
let g:pymode_syntax_docstrings = 1
let g:pymode_syntax_builtin_objs = 1
let g:pymode_syntax_builtin_types = 1
let g:pymode_syntax_builtin_funcs = 1
let g:pymode_syntax_highlight_exceptions = 1
let g:pymode_syntax_slow_sync = 1
" vim: ft=vim:fdm=marker