1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-17 11:30:29 +01:00

Update matchtag plugin and python syntax

This commit is contained in:
2013-03-11 21:49:51 +01:00
parent 6f15bec6df
commit a8f1365f18
4 changed files with 399 additions and 234 deletions

3
.vimrc
View File

@@ -201,6 +201,9 @@ map <Leader>b :CtrlPBuffer<CR>
"NERDCommenter {{{2 "NERDCommenter {{{2
let g:NERDSpaceDelims=1 let g:NERDSpaceDelims=1
"}}} "}}}
"Python indent{{{2
let g:python_version_2=1
"}}}
"}}} "}}}
"KEYS: User defined keyboard shortcuts {{{ "KEYS: User defined keyboard shortcuts {{{

View File

@@ -40,8 +40,8 @@ fu! s:GetCurrentCursorTag()
let c_col = col('.') let c_col = col('.')
let matched = matchstr(getline('.'), '\(<[^<>]*\%'.c_col.'c.\{-}>\)\|\(\%'.c_col.'c<.\{-}>\)') let matched = matchstr(getline('.'), '\(<[^<>]*\%'.c_col.'c.\{-}>\)\|\(\%'.c_col.'c<.\{-}>\)')
if matched == "" if matched == "" || matched =~ '/>$'
return matched return ""
endif endif
let tagname = matchstr(matched, '<\zs.\{-}\ze[ >]') let tagname = matchstr(matched, '<\zs.\{-}\ze[ >]')
@@ -51,9 +51,9 @@ endfu
fu! s:SearchForMatchingTag(tagname, forwards) fu! s:SearchForMatchingTag(tagname, forwards)
"returns the position of a matching tag or [0 0] "returns the position of a matching tag or [0 0]
let starttag = '<'.a:tagname.'.\{-}>' let starttag = '<'.a:tagname.'.\{-}/\@<!>'
let midtag = '' let midtag = ''
let endtag = '</'.a:tagname.'.\{-}>'.(a:forwards?'':'\zs') let endtag = '</'.a:tagname.'.\{-}'.(a:forwards?'':'\zs').'>'
let flags = 'nW'.(a:forwards?'':'b') let flags = 'nW'.(a:forwards?'':'b')
" When not in a string or comment ignore matches inside them. " When not in a string or comment ignore matches inside them.
@@ -65,7 +65,12 @@ fu! s:SearchForMatchingTag(tagname, forwards)
let stopline = a:forwards ? line('w$') : line('w0') let stopline = a:forwards ? line('w$') : line('w0')
let timeout = 300 let timeout = 300
" The searchpairpos() timeout parameter was added in 7.2
if v:version >= 702
return searchpairpos(starttag, midtag, endtag, flags, skip, stopline, timeout) return searchpairpos(starttag, midtag, endtag, flags, skip, stopline, timeout)
else
return searchpairpos(starttag, midtag, endtag, flags, skip, stopline)
endif
endfu endfu
fu! s:HighlightTagAtPosition(position) fu! s:HighlightTagAtPosition(position)

View File

@@ -0,0 +1,2 @@
runtime! ftplugin/html.vim

View File

@@ -2,117 +2,138 @@
" Language: Python " Language: Python
" Maintainer: Dmitry Vasiliev <dima at hlabs dot org> " Maintainer: Dmitry Vasiliev <dima at hlabs dot org>
" URL: https://github.com/hdima/vim-scripts/blob/master/syntax/python/python.vim " URL: https://github.com/hdima/vim-scripts/blob/master/syntax/python/python.vim
" Last Change: 2012-02-11 " Last Change: 2013-03-10
" Filenames: *.py " Filenames: *.py
" Version: 2.6.7 " Version: 3.3.0
" "
" Based on python.vim (from Vim 6.1 distribution) " Based on python.vim (from Vim 6.1 distribution)
" by Neil Schemenauer <nas at python dot ca> " by Neil Schemenauer <nas at python dot ca>
" "
" Thanks: " Bugs and feature requests can be reported through email
" <dima at hlabs dot org>, GitHub at:
"
" https://github.com/hdima/vim-scripts/issues
"
" , or Twitter:
"
" https://twitter.com/hdima
"
" Contributors
" ============
" "
" Jeroen Ruigrok van der Werven " Jeroen Ruigrok van der Werven
" for the idea to highlight erroneous operators
" Pedro Algarvio " Pedro Algarvio
" for the patch to enable spell checking only for the right spots
" (strings and comments)
" John Eikenberry " John Eikenberry
" for the patch fixing small typo
" Caleb Adamantine " Caleb Adamantine
" for the patch fixing highlighting for decorators
" Andrea Riciputi " Andrea Riciputi
" for the patch with new configuration options " Anton Butanaev
" Marc Weber
" "
" Options: " Options
" =======
" "
" For set option do: let OPTION_NAME = 1 " :let OPTION_NAME = 1 Enable option
" For clear option do: let OPTION_NAME = 0 " :let OPTION_NAME = 0 Disable option
" "
" Option names:
" "
" For highlight builtin functions and objects: " Option to select Python version
" python_highlight_builtins " -------------------------------
" "
" For highlight builtin objects: " python_version_2 Enable highlighting for Python 2
" python_highlight_builtin_objs " (Python 3 highlighting is enabled
" by default). Can also be set as
" a buffer (b:python_version_2)
" variable.
" "
" For highlight builtin funtions: " You can also use the following local to buffer commands to switch
" python_highlight_builtin_funcs " between two highlighting modes:
" "
" For highlight standard exceptions: " :Python2Syntax Switch to Python 2 highlighting
" python_highlight_exceptions " mode
" :Python3Syntax Switch to Python 3 highlighting
" mode
" "
" For highlight string formatting: " Option names used by the script
" python_highlight_string_formatting " -------------------------------
" "
" For highlight str.format syntax: " python_highlight_builtins Highlight builtin functions and
" python_highlight_string_format " 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
" "
" For highlight string.Template syntax: " python_highlight_all Enable all the options above
" python_highlight_string_templates " NOTE: This option don't override
" any previously set options
" "
" For highlight indentation errors: " python_slow_sync Can be set to 0 for slow machines
" python_highlight_indent_errors
" "
" For highlight trailing spaces:
" python_highlight_space_errors
"
" For highlight doc-tests:
" python_highlight_doctests
"
" If you want all Python highlightings above:
" python_highlight_all
" (This option not override previously set options)
"
" For fast machines:
" python_slow_sync
"
" For "print" builtin as function:
" python_print_as_function
" For version 5.x: Clear all syntax items " For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded " For versions greater than 6.x: Quit when a syntax file was already loaded
if version < 600 if version < 600
syntax clear syntax clear
elseif exists("b:current_syntax") elseif exists("b:current_syntax")
finish finish
endif endif
if exists("python_highlight_all") && python_highlight_all != 0 "
" Not override previously set options " Commands
if !exists("python_highlight_builtins") "
if !exists("python_highlight_builtin_objs") command! -buffer Python2Syntax let b:python_version_2 = 1 | if exists("g:syntax_on") | syn off | endif | syn enable
let python_highlight_builtin_objs = 1 command! -buffer Python3Syntax let b:python_version_2 = 0 | if exists("g:syntax_on") | syn off | endif | syn enable
" Enable option if it's not defined
function! s:EnableByDefault(name)
if !exists(a:name)
let {a:name} = 1
endif endif
if !exists("python_highlight_builtin_funcs") endfunction
let python_highlight_builtin_funcs = 1
endif " Check if option is enabled
endif function! s:Enabled(name)
if !exists("python_highlight_exceptions") return exists(a:name) && {a:name} != 0
let python_highlight_exceptions = 1 endfunction
endif
if !exists("python_highlight_string_formatting") " Is it Python 2 syntax?
let python_highlight_string_formatting = 1 function! s:Python2Syntax()
endif return s:Enabled("b:python_version_2") || s:Enabled("g:python_version_2")
if !exists("python_highlight_string_format") endfunction
let python_highlight_string_format = 1
endif "
if !exists("python_highlight_string_templates") " Default options
let python_highlight_string_templates = 1 "
endif
if !exists("python_highlight_indent_errors") call s:EnableByDefault("g:python_slow_sync")
let python_highlight_indent_errors = 1
endif if s:Enabled("g:python_highlight_all")
if !exists("python_highlight_space_errors") call s:EnableByDefault("g:python_highlight_builtins")
let python_highlight_space_errors = 1 if s:Enabled("g:python_highlight_builtins")
endif call s:EnableByDefault("g:python_highlight_builtin_objs")
if !exists("python_highlight_doctests") call s:EnableByDefault("g:python_highlight_builtin_funcs")
let python_highlight_doctests = 1
endif endif
call s:EnableByDefault("g:python_highlight_exceptions")
call s:EnableByDefault("g:python_highlight_string_formatting")
call s:EnableByDefault("g:python_highlight_string_format")
call s:EnableByDefault("g:python_highlight_string_templates")
call s:EnableByDefault("g:python_highlight_indent_errors")
call s:EnableByDefault("g:python_highlight_space_errors")
call s:EnableByDefault("g:python_highlight_doctests")
call s:EnableByDefault("g:python_print_as_function")
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
@@ -120,65 +141,89 @@ syn keyword pythonStatement global assert
syn keyword pythonStatement lambda yield syn keyword pythonStatement lambda yield
syn keyword pythonStatement with syn keyword pythonStatement with
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
syn keyword pythonRepeat for while syn keyword pythonRepeat for while
syn keyword pythonConditional if elif else syn keyword pythonConditional if elif else
syn keyword pythonPreCondit import from as syn keyword pythonPreCondit import from
syn keyword pythonException try except finally syn keyword pythonException try except finally
syn keyword pythonOperator and in is not or syn keyword pythonOperator and in is not or
if !exists("python_print_as_function") || python_print_as_function == 0 if s:Python2Syntax()
if !s:Enabled("g:python_print_as_function")
syn keyword pythonStatement print syn keyword pythonStatement print
endif
syn keyword pythonPreCondit as
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
else
syn keyword pythonStatement as nonlocal False None True
syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
endif endif
"
" Decorators (new in Python 2.4) " Decorators (new in Python 2.4)
"
" gryf: match also name of the decorator not only at sign. " gryf: match also name of the decorator not only at sign.
syn match pythonDecorator "@[a-zA-Z_][a-zA-Z0-9_]*" display nextgroup=pythonDottedName skipwhite syn match pythonDecorator "@[a-zA-Z_][a-zA-Z0-9_]*" display nextgroup=pythonDottedName skipwhite
"syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite "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 pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
syn match pythonDot "\." display containedin=pythonDottedName syn match pythonDot "\." display containedin=pythonDottedName
"
" Comments " Comments
"
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell 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-_.]\+.*$"
syn keyword pythonTodo TODO FIXME XXX contained syn keyword pythonTodo TODO FIXME XXX contained
"
" Errors " Errors
"
syn match pythonError "\<\d\+\D\+\>" display syn match pythonError "\<\d\+\D\+\>" display
syn match pythonError "[$?]" display syn match pythonError "[$?]" display
syn match pythonError "[&|]\{2,}" display syn match pythonError "[&|]\{2,}" display
syn match pythonError "[=]\{3,}" display syn match pythonError "[=]\{3,}" display
" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline " Mixing spaces and tabs also may be used for pretty formatting multiline
" statements. For now I don't know how to work around this. " statements
if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0 if s:Enabled("g:python_highlight_indent_errors")
syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display
endif endif
" Trailing space errors " Trailing space errors
if exists("python_highlight_space_errors") && python_highlight_space_errors != 0 if s:Enabled("g:python_highlight_space_errors")
syn match pythonSpaceError "\s\+$" display syn match pythonSpaceError "\s\+$" display
endif endif
"
" Strings " 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 if s:Python2Syntax()
syn match pythonEscape "\\\o\o\=\o\=" display contained " Python 2 strings
syn match pythonEscapeError "\\\o\{,2}[89]" display contained syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn match pythonEscape "\\x\x\{2}" display contained syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn match pythonEscapeError "\\x\x\=\X" display contained syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
syn match pythonEscape "\\$" 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
" Unicode strings syn match pythonBytesError ".\+" display contained
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError,@Spell endif
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 pythonBytesEscape +\\[abfnrtv'"\\]+ display contained
syn match pythonBytesEscape "\\\o\o\=\o\=" display contained
syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained
syn match pythonBytesEscape "\\x\x\{2}" display contained
syn match pythonBytesEscapeError "\\x\x\=\X" display contained
syn match pythonBytesEscape "\\$"
syn match pythonUniEscape "\\u\x\{4}" display contained syn match pythonUniEscape "\\u\x\{4}" display contained
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
@@ -187,96 +232,197 @@ syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
" Raw strings if s:Python2Syntax()
syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell " Python 2 Unicode strings
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
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()
" Python 2 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 "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
endif
" Python 2/3 raw strings
if s:Python2Syntax()
syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
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 syn match pythonRawEscape +\\['"]+ display transparent contained
" Unicode raw strings if s:Enabled("g:python_highlight_string_formatting")
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell " % operator string formatting
syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell if s:Python2Syntax()
syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
else
syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
endif
if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
" String formatting
syn match pythonStrFormatting "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
syn match pythonStrFormatting "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString
endif endif
if exists("python_highlight_string_format") && python_highlight_string_format != 0 if s:Enabled("g:python_highlight_string_format")
" str.format syntax " str.format syntax
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString if s:Python2Syntax()
syn match pythonStrFormat "{\([a-zA-Z_][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 "{{\|}}" contained containedin=pythonString,pythonUniString,pythonUniRawString,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,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 exists("python_highlight_string_templates") && python_highlight_string_templates != 0 if s:Enabled("g:python_highlight_string_templates")
" String templates " string.Template format
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonRawString,pythonUniRawString if s:Python2Syntax()
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" 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,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 exists("python_highlight_doctests") && python_highlight_doctests != 0 if s:Enabled("g:python_highlight_doctests")
" DocTests " 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 endif
"
" Numbers (ints, longs, floats, complex) " Numbers (ints, longs, floats, complex)
syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*[lL]\=\>" display "
syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display if s:Python2Syntax()
syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display
syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display syn match pythonOctError "\<0[oO]\=\o*\D\+\d*[lL]\=\>" display
syn match pythonBinError "\<0[bB][01]*\D\+\d*[lL]\=\>" display
syn match pythonNumber "\<\d\+[lLjJ]\=\>" 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 pythonFloat "\.\d\+\([eE][+-]\=\d\+\)\=[jJ]\=\>" 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\+[eE][+-]\=\d\+[jJ]\=\>" display
syn match pythonFloat "\<\d\+\.\d*\([eE][+-]\=\d\+\)\=[jJ]\=" display syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display "
syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display " Builtin objects and types
"
if exists("python_highlight_builtin_objs") && python_highlight_builtin_objs != 0 if s:Enabled("g:python_highlight_builtin_objs")
" Builtin objects and types if s:Python2Syntax()
syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented syn keyword pythonBuiltinObj True False None
endif
syn keyword pythonBuiltinObj Ellipsis NotImplemented
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
endif endif
if exists("python_highlight_builtin_funcs") && python_highlight_builtin_funcs != 0 "
" Builtin functions " Builtin functions
syn keyword pythonBuiltinFunc __import__ abs all any apply "
syn keyword pythonBuiltinFunc basestring bin bool buffer bytearray bytes callable
syn keyword pythonBuiltinFunc chr classmethod cmp coerce compile complex
syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
syn keyword pythonBuiltinFunc execfile file filter float format frozenset getattr
syn keyword pythonBuiltinFunc globals hasattr hash help hex id
syn keyword pythonBuiltinFunc input int intern isinstance
syn keyword pythonBuiltinFunc issubclass iter len list locals long map max
syn keyword pythonBuiltinFunc min next object oct open ord
syn keyword pythonBuiltinFunc pow property range
syn keyword pythonBuiltinFunc raw_input reduce reload repr
syn keyword pythonBuiltinFunc reversed round set setattr
syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
syn keyword pythonBuiltinFunc type unichr unicode vars xrange zip
if exists("python_print_as_function") && python_print_as_function != 0 if s:Enabled("g:python_highlight_builtin_funcs")
if s:Python2Syntax()
syn keyword pythonBuiltinFunc apply basestring buffer callable coerce
syn keyword pythonBuiltinFunc execfile file help intern long raw_input
syn keyword pythonBuiltinFunc reduce reload unichr unicode xrange
if s:Enabled("g:python_print_as_function")
syn keyword pythonBuiltinFunc print syn keyword pythonBuiltinFunc print
endif endif
else
syn keyword pythonBuiltinFunc ascii exec memoryview print
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 endif
if exists("python_highlight_exceptions") && python_highlight_exceptions != 0 "
" Builtin exceptions and warnings " Builtin exceptions and warnings
"
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 StandardError ArithmeticError syn keyword pythonExClass Exception 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
@@ -298,7 +444,7 @@ if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
syn keyword pythonExClass ImportWarning UnicodeWarning syn keyword pythonExClass ImportWarning UnicodeWarning
endif endif
if exists("python_slow_sync") && python_slow_sync != 0 if s:Enabled("g:python_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
@@ -338,16 +484,24 @@ if version >= 508 || !exists("did_python_syn_inits")
HiLink pythonSpaceError Error HiLink pythonSpaceError Error
HiLink pythonString String HiLink pythonString String
HiLink pythonUniString String
HiLink pythonRawString String HiLink pythonRawString String
HiLink pythonUniRawString String
HiLink pythonEscape Special
HiLink pythonEscapeError Error
HiLink pythonUniEscape Special HiLink pythonUniEscape Special
HiLink pythonUniEscapeError Error HiLink pythonUniEscapeError Error
if s:Python2Syntax()
HiLink pythonUniString String
HiLink pythonUniRawString String
HiLink pythonUniRawEscape Special HiLink pythonUniRawEscape Special
HiLink pythonUniRawEscapeError Error HiLink pythonUniRawEscapeError Error
else
HiLink pythonBytes String
HiLink pythonRawBytes String
HiLink pythonBytesContent String
HiLink pythonBytesError Error
HiLink pythonBytesEscape Special
HiLink pythonBytesEscapeError Error
endif
HiLink pythonStrFormatting Special HiLink pythonStrFormatting Special
HiLink pythonStrFormat Special HiLink pythonStrFormat Special
@@ -361,6 +515,7 @@ if version >= 508 || !exists("did_python_syn_inits")
HiLink pythonOctNumber Number HiLink pythonOctNumber Number
HiLink pythonBinNumber Number HiLink pythonBinNumber Number
HiLink pythonFloat Float HiLink pythonFloat Float
HiLink pythonNumberError Error
HiLink pythonOctError Error HiLink pythonOctError Error
HiLink pythonHexError Error HiLink pythonHexError Error
HiLink pythonBinError Error HiLink pythonBinError Error