[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/IBMHUA/python-mode/develop/syntax/python.vim [Back]  [Original]

" vim: ft=vim:fdm=marker

" Enable pymode syntax for python files
call pymode#default('g:pymode', 1)
call pymode#default('g:pymode_syntax', g:pymode)

" DESC: Disable script loading
if !g:pymode || !g:pymode_syntax || pymode#default('b:current_syntax', 'pymode')
    finish
endif

" OPTIONS: {{{

" Highlight all by default
call pymode#default('g:pymode_syntax_all', 1)

" Highlight 'print' as function
call pymode#default("g:pymode_syntax_print_as_function", 0)
"
" Highlight 'async/await' keywords
call pymode#default("g:pymode_syntax_highlight_async_await", g:pymode_syntax_all)

" Highlight '=' operator
call pymode#default('g:pymode_syntax_highlight_equal_operator', g:pymode_syntax_all)

" Highlight '*' operator
call pymode#default('g:pymode_syntax_highlight_stars_operator', g:pymode_syntax_all)

" Highlight 'self' keyword
call pymode#default('g:pymode_syntax_highlight_self', g:pymode_syntax_all)

" Highlight indent's errors
call pymode#default('g:pymode_syntax_indent_errors', g:pymode_syntax_all)

" Highlight space's errors
call pymode#default('g:pymode_syntax_space_errors', g:pymode_syntax_all)

" Highlight string formatting
call pymode#default('g:pymode_syntax_string_formatting', g:pymode_syntax_all)
call pymode#default('g:pymode_syntax_string_format', g:pymode_syntax_all)
call pymode#default('g:pymode_syntax_string_templates', g:pymode_syntax_all)
call pymode#default('g:pymode_syntax_doctests', g:pymode_syntax_all)

" Support docstrings in syntax highlighting
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

" Keywords {{{
" ============

    syn keyword pythonStatement break continue del
    syn keyword pythonStatement exec return
    syn keyword pythonStatement pass raise
    syn keyword pythonStatement global nonlocal assert
    syn keyword pythonStatement yield
    syn keyword pythonLambdaExpr lambda
    syn keyword pythonStatement with as

    syn keyword pythonStatement def nextgroup=pythonFunction skipwhite
    syn match pythonFunction "\%(\%(def\s\|@\)\s*\)\@\|>=\|=\@\|\.\.\.\|\.\.\|::\)"
    syn match pythonExtraPseudoOperator "\%(-=\|/=\|\*\*=\|\*=\|&&=\|&=\|&&\|||=\||=\|||\|%=\|+=\|!\~\|!=\)"

    if !g:pymode_syntax_print_as_function
        syn keyword pythonStatement print
    endif

    if g:pymode_syntax_highlight_async_await
        syn keyword pythonStatement async await
        syn match pythonStatement "\" nextgroup=pythonFunction skipwhite
        syn match pythonStatement "\" display
        syn match pythonStatement "\" nextgroup=pythonRepeat skipwhite
    endif

    if g:pymode_syntax_highlight_equal_operator
        syn match pythonExtraOperator "\%(=\)"
    endif

    if g:pymode_syntax_highlight_stars_operator
        syn match pythonExtraOperator "\%(\*\|\*\*\)"
    endif
    
    if g:pymode_syntax_highlight_self
        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   pythonCoding    "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
    syn keyword pythonTodo      TODO FIXME XXX contained

" }}}


" Errors {{{
" ==========

    syn match pythonError       "\" display
    syn match pythonError       "[$?]" display
    syn match pythonError       "[&|]\{2,}" display
    syn match pythonError       "[=]\{3,}" display

    " Indent errors (mix space and tabs)
    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
    endif

" }}}


" Strings {{{
" ===========

    syn region pythonString     start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
    syn region pythonString     start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
    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  pythonEscape     +\\[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
    syn region pythonUniString  start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
    syn region pythonUniString  start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell
    syn region pythonUniString  start=+[uU]"""+ end=+"""+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
    syn region pythonUniString  start=+[uU]'''+ end=+'''+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell

    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=+$+ 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]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
    syn region pythonUniRawString   start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell

    syn match  pythonUniRawEscape   "\([^\\]\(\\\\\)*\)\@>" end=+'''+he=s-1 end="^\s*$" contained
        syn region pythonDocTest2   start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
    endif

    " 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  "\" display
    syn match   pythonHexNumber "\" display
    syn match   pythonOctNumber "\" display
    syn match   pythonBinNumber "\" display
    syn match   pythonNumber    "\" display
    syn match   pythonFloat "\.[0-9_]*[0-9][0-9_]*\([eE][+-]\=[0-9_]*[0-9][0-9_]*\)\=[jJ]\=\>" display
    syn match   pythonFloat "\" display
    syn match   pythonFloat "\

Web Proxy Viewer  |  New URL  |  Original Page