mirror of
https://github.com/sheerun/vim-polyglot.git
synced 2025-11-09 03:53:52 -05:00
Change python syntax providers, closes #209
This commit is contained in:
@@ -110,7 +110,8 @@ If you need full functionality of any plugin, please use it directly with your p
|
|||||||
- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin)
|
- [puppet](https://github.com/voxpupuli/vim-puppet) (syntax, indent, ftplugin)
|
||||||
- [purescript](https://github.com/purescript-contrib/purescript-vim) (syntax, indent, ftplugin)
|
- [purescript](https://github.com/purescript-contrib/purescript-vim) (syntax, indent, ftplugin)
|
||||||
- [python-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload)
|
- [python-compiler](https://github.com/aliev/vim-compiler-python) (compiler, autoload)
|
||||||
- [python](https://github.com/mitsuhiko/vim-python-combined) (syntax, indent)
|
- [python-ident](https://github.com/Vimjas/vim-python-pep8-indent) (indent)
|
||||||
|
- [python](https://github.com/vim-python/python-syntax) (syntax)
|
||||||
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin)
|
- [qml](https://github.com/peterhoeg/vim-qml) (syntax, indent, ftplugin)
|
||||||
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
- [r-lang](https://github.com/vim-scripts/R.vim) (syntax, ftplugin)
|
||||||
- [racket](https://github.com/wlangstroth/vim-racket) (syntax, indent, autoload, ftplugin)
|
- [racket](https://github.com/wlangstroth/vim-racket) (syntax, indent, autoload, ftplugin)
|
||||||
|
|||||||
3
build
3
build
@@ -181,8 +181,9 @@ PACKS="
|
|||||||
pug:digitaltoad/vim-pug
|
pug:digitaltoad/vim-pug
|
||||||
puppet:voxpupuli/vim-puppet
|
puppet:voxpupuli/vim-puppet
|
||||||
purescript:purescript-contrib/purescript-vim
|
purescript:purescript-contrib/purescript-vim
|
||||||
python:mitsuhiko/vim-python-combined
|
python:vim-python/python-syntax
|
||||||
python-compiler:aliev/vim-compiler-python
|
python-compiler:aliev/vim-compiler-python
|
||||||
|
python-ident:Vimjas/vim-python-pep8-indent
|
||||||
qml:peterhoeg/vim-qml
|
qml:peterhoeg/vim-qml
|
||||||
r-lang:vim-scripts/R.vim
|
r-lang:vim-scripts/R.vim
|
||||||
racket:wlangstroth/vim-racket
|
racket:wlangstroth/vim-racket
|
||||||
|
|||||||
@@ -13,3 +13,5 @@ let g:filetype_euphoria = 'elixir'
|
|||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
let g:python_highlight_all = 1
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ let g:filetype_euphoria = 'elixir'
|
|||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
autocmd BufNewFile,BufReadPost *.vb setlocal filetype=vbnet
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
let g:python_highlight_all = 1
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" apiblueprint:sheerun/apiblueprint.vim
|
" apiblueprint:sheerun/apiblueprint.vim
|
||||||
autocmd BufReadPost,BufNewFile *.apib set filetype=apiblueprint
|
autocmd BufReadPost,BufNewFile *.apib set filetype=apiblueprint
|
||||||
@@ -780,7 +782,7 @@ au FileType purescript let &l:commentstring='{--%s--}'
|
|||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" python:mitsuhiko/vim-python-combined
|
" python:vim-python/python-syntax
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
@@ -793,6 +795,10 @@ augroup filetypedetect
|
|||||||
autocmd FileType python compiler python
|
autocmd FileType python compiler python
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
augroup filetypedetect
|
||||||
|
" python-ident:Vimjas/vim-python-pep8-indent
|
||||||
|
augroup END
|
||||||
|
|
||||||
augroup filetypedetect
|
augroup filetypedetect
|
||||||
" qml:peterhoeg/vim-qml
|
" qml:peterhoeg/vim-qml
|
||||||
autocmd BufRead,BufNewFile *.qml setfiletype qml
|
autocmd BufRead,BufNewFile *.qml setfiletype qml
|
||||||
|
|||||||
433
indent/cython.vim
Normal file
433
indent/cython.vim
Normal file
@@ -0,0 +1,433 @@
|
|||||||
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python-ident') == -1
|
||||||
|
|
||||||
|
" PEP8 compatible Python indent file
|
||||||
|
" Language: Python
|
||||||
|
" Maintainer: Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
" Prev Maintainer: Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Prev Maintainer: Eric Mc Sween <em@tomcom.de> (address invalid)
|
||||||
|
" Original Author: David Bustos <bustos@caltech.edu> (address invalid)
|
||||||
|
" License: CC0
|
||||||
|
"
|
||||||
|
" vim-python-pep8-indent - A nicer Python indentation style for vim.
|
||||||
|
" Written in 2004 by David Bustos <bustos@caltech.edu>
|
||||||
|
" Maintained from 2004-2005 by Eric Mc Sween <em@tomcom.de>
|
||||||
|
" Maintained from 2013 by Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Maintained from 2017 by Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
"
|
||||||
|
" To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
" and related and neighboring rights to this software to the public domain
|
||||||
|
" worldwide. This software is distributed without any warranty.
|
||||||
|
" You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
" with this software. If not, see
|
||||||
|
" <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
|
||||||
|
" Only load this indent file when no other was loaded.
|
||||||
|
if exists('b:did_indent')
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let b:did_indent = 1
|
||||||
|
|
||||||
|
setlocal nolisp
|
||||||
|
setlocal autoindent
|
||||||
|
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
|
||||||
|
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
|
||||||
|
|
||||||
|
if !exists('g:python_pep8_indent_multiline_string')
|
||||||
|
let g:python_pep8_indent_multiline_string = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:block_rules = {
|
||||||
|
\ '^\s*elif\>': ['if', 'elif'],
|
||||||
|
\ '^\s*except\>': ['try', 'except'],
|
||||||
|
\ '^\s*finally\>': ['try', 'except', 'else']
|
||||||
|
\ }
|
||||||
|
let s:block_rules_multiple = {
|
||||||
|
\ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'],
|
||||||
|
\ }
|
||||||
|
" Pairs to look for when searching for opening parenthesis.
|
||||||
|
" The value is the maximum offset in lines.
|
||||||
|
let s:paren_pairs = {'()': 50, '[]': 100, '{}': 1000}
|
||||||
|
|
||||||
|
if &filetype ==# 'pyrex' || &filetype ==# 'cython'
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except|cdef|cpdef)>'
|
||||||
|
else
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except)>'
|
||||||
|
endif
|
||||||
|
let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>'
|
||||||
|
|
||||||
|
" Skip strings and comments. Return 1 for chars to skip.
|
||||||
|
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
|
||||||
|
" are inserted temporarily into the buffer.
|
||||||
|
let s:skip_special_chars = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vstring|comment|jedi\\S"'
|
||||||
|
|
||||||
|
let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vcomment|jedi\\S"'
|
||||||
|
|
||||||
|
" Also ignore anything concealed.
|
||||||
|
" Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI).
|
||||||
|
function! s:is_concealed(line, col)
|
||||||
|
let concealed = synconcealed(a:line, a:col)
|
||||||
|
return len(concealed) && concealed[0]
|
||||||
|
endfunction
|
||||||
|
if has('conceal')
|
||||||
|
let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
let s:skip_search = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "comment"'
|
||||||
|
|
||||||
|
" Use 'shiftwidth()' instead of '&sw'.
|
||||||
|
" (Since Vim patch 7.3.629, 'shiftwidth' can be set to 0 to follow 'tabstop').
|
||||||
|
if exists('*shiftwidth')
|
||||||
|
function! s:sw()
|
||||||
|
return shiftwidth()
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:sw()
|
||||||
|
return &shiftwidth
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:pair_sort(x, y)
|
||||||
|
if a:x[0] == a:y[0]
|
||||||
|
return a:x[1] == a:y[1] ? 0 : a:x[1] > a:y[1] ? 1 : -1
|
||||||
|
else
|
||||||
|
return a:x[0] > a:y[0] ? 1 : -1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find backwards the closest open parenthesis/bracket/brace.
|
||||||
|
function! s:find_opening_paren(...)
|
||||||
|
" optional arguments: line and column (defaults to 1) to search around
|
||||||
|
if a:0 > 0
|
||||||
|
let view = winsaveview()
|
||||||
|
call cursor(a:1, a:0 > 1 ? a:2 : 1)
|
||||||
|
let ret = s:find_opening_paren()
|
||||||
|
call winrestview(view)
|
||||||
|
return ret
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Return if cursor is in a comment.
|
||||||
|
exe 'if' s:skip_search '| return [0, 0] | endif'
|
||||||
|
|
||||||
|
let nearest = [0, 0]
|
||||||
|
for [p, maxoff] in items(s:paren_pairs)
|
||||||
|
let stopline = max([0, line('.') - maxoff, nearest[0]])
|
||||||
|
let next = searchpairpos(
|
||||||
|
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline)
|
||||||
|
if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1]))
|
||||||
|
let nearest = next
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return nearest
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find the start of a multi-line statement
|
||||||
|
function! s:find_start_of_multiline_statement(lnum)
|
||||||
|
let lnum = a:lnum
|
||||||
|
while lnum > 0
|
||||||
|
if getline(lnum - 1) =~# '\\$'
|
||||||
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
else
|
||||||
|
let [paren_lnum, _] = s:find_opening_paren(lnum)
|
||||||
|
if paren_lnum < 1
|
||||||
|
return lnum
|
||||||
|
else
|
||||||
|
let lnum = paren_lnum
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Find possible indent(s) of the block starter that matches the current line.
|
||||||
|
function! s:find_start_of_block(lnum, types, multiple)
|
||||||
|
let r = []
|
||||||
|
let types = copy(a:types)
|
||||||
|
let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>'
|
||||||
|
let lnum = a:lnum
|
||||||
|
let last_indent = indent(lnum) + 1
|
||||||
|
while lnum > 0 && last_indent > 0
|
||||||
|
let indent = indent(lnum)
|
||||||
|
if indent < last_indent
|
||||||
|
for type in types
|
||||||
|
let re = '\v^\s*'.type.'>'
|
||||||
|
if getline(lnum) =~# re
|
||||||
|
if !a:multiple
|
||||||
|
return [indent]
|
||||||
|
endif
|
||||||
|
if index(r, indent) == -1
|
||||||
|
let r += [indent]
|
||||||
|
endif
|
||||||
|
" Remove any handled type, e.g. 'if'.
|
||||||
|
call remove(types, index(types, type))
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
let last_indent = indent(lnum)
|
||||||
|
endif
|
||||||
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
endwhile
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is "expr" true for every position in "lnum", beginning at "start"?
|
||||||
|
" (optionally up to a:1 / 4th argument)
|
||||||
|
function! s:match_expr_on_line(expr, lnum, start, ...)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
let end = a:0 ? a:1 : len(text)
|
||||||
|
if a:start > end
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
let save_pos = getpos('.')
|
||||||
|
let r = 1
|
||||||
|
for i in range(a:start, end)
|
||||||
|
call cursor(a:lnum, i)
|
||||||
|
if !(eval(a:expr) || text[i-1] =~# '\s')
|
||||||
|
let r = 0
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call setpos('.', save_pos)
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Line up with open parenthesis/bracket/brace.
|
||||||
|
function! s:indent_like_opening_paren(lnum)
|
||||||
|
let [paren_lnum, paren_col] = s:find_opening_paren(a:lnum)
|
||||||
|
if paren_lnum <= 0
|
||||||
|
return -2
|
||||||
|
endif
|
||||||
|
let text = getline(paren_lnum)
|
||||||
|
let base = indent(paren_lnum)
|
||||||
|
|
||||||
|
let nothing_after_opening_paren = s:match_expr_on_line(
|
||||||
|
\ s:skip_after_opening_paren, paren_lnum, paren_col+1)
|
||||||
|
let starts_with_closing_paren = getline(a:lnum) =~# '^\s*[])}]'
|
||||||
|
|
||||||
|
if nothing_after_opening_paren
|
||||||
|
if starts_with_closing_paren
|
||||||
|
let res = base
|
||||||
|
else
|
||||||
|
let res = base + s:sw()
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
" Indent to match position of opening paren.
|
||||||
|
let res = paren_col
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if text =~# b:control_statement && res == base + s:sw()
|
||||||
|
return base + s:sw() * 2
|
||||||
|
else
|
||||||
|
return res
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Match indent of first block of this type.
|
||||||
|
function! s:indent_like_block(lnum)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
for [multiple, block_rules] in [
|
||||||
|
\ [0, s:block_rules],
|
||||||
|
\ [1, s:block_rules_multiple]]
|
||||||
|
for [line_re, blocks] in items(block_rules)
|
||||||
|
if text !~# line_re
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indents = s:find_start_of_block(a:lnum - 1, blocks, multiple)
|
||||||
|
if !len(indents)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
if len(indents) == 1
|
||||||
|
return indents[0]
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Multiple valid indents, e.g. for 'else' with both try and if.
|
||||||
|
let indent = indent(a:lnum)
|
||||||
|
if index(indents, indent) != -1
|
||||||
|
" The indent is valid, keep it.
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
" Fallback to the first/nearest one.
|
||||||
|
return indents[0]
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
return -2
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:indent_like_previous_line(lnum)
|
||||||
|
let lnum = prevnonblank(a:lnum - 1)
|
||||||
|
|
||||||
|
" No previous line, keep current indent.
|
||||||
|
if lnum < 1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
let text = getline(lnum)
|
||||||
|
let start = s:find_start_of_multiline_statement(lnum)
|
||||||
|
let base = indent(start)
|
||||||
|
let current = indent(a:lnum)
|
||||||
|
|
||||||
|
" Jump to last character in previous line.
|
||||||
|
call cursor(lnum, len(text))
|
||||||
|
let ignore_last_char = eval(s:skip_special_chars)
|
||||||
|
|
||||||
|
" Search for final colon that is not inside something to be ignored.
|
||||||
|
while 1
|
||||||
|
let curpos = getpos('.')[2]
|
||||||
|
if curpos == 1 | break | endif
|
||||||
|
if eval(s:skip_special_chars) || text[curpos-1] =~# '\s'
|
||||||
|
normal! h
|
||||||
|
continue
|
||||||
|
elseif text[curpos-1] ==# ':'
|
||||||
|
return base + s:sw()
|
||||||
|
endif
|
||||||
|
break
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if text =~# '\\$' && !ignore_last_char
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if getline(start) =~# b:control_statement
|
||||||
|
return base + s:sw() * 2
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Nest (other) explicit continuations only one level deeper.
|
||||||
|
return base + s:sw()
|
||||||
|
endif
|
||||||
|
|
||||||
|
let empty = getline(a:lnum) =~# '^\s*$'
|
||||||
|
|
||||||
|
" Current and prev line are empty, next is not -> indent like next.
|
||||||
|
if empty && a:lnum > 1 &&
|
||||||
|
\ (getline(a:lnum - 1) =~# '^\s*$') &&
|
||||||
|
\ !(getline(a:lnum + 1) =~# '^\s*$')
|
||||||
|
return indent(a:lnum + 1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If the previous statement was a stop-execution statement or a pass
|
||||||
|
if getline(start) =~# s:stop_statement
|
||||||
|
" Remove one level of indentation if the user hasn't already dedented
|
||||||
|
if empty || current > base - s:sw()
|
||||||
|
return base - s:sw()
|
||||||
|
endif
|
||||||
|
" Otherwise, trust the user
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if !empty && s:is_dedented_already(current, base)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
" In all other cases, line up with the start of the previous statement.
|
||||||
|
return base
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" If this line is dedented and the number of indent spaces is valid
|
||||||
|
" (multiple of the indentation size), trust the user.
|
||||||
|
function! s:is_dedented_already(current, base)
|
||||||
|
let dedent_size = a:current - a:base
|
||||||
|
return (dedent_size < 0 && a:current % s:sw() == 0) ? 1 : 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is the syntax at lnum (and optionally cnum) a python string?
|
||||||
|
function! s:is_python_string(lnum, ...)
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let linelen = len(line)
|
||||||
|
if linelen < 1
|
||||||
|
let linelen = 1
|
||||||
|
endif
|
||||||
|
let cols = a:0 ? type(a:1) != type([]) ? [a:1] : a:1 : range(1, linelen)
|
||||||
|
for cnum in cols
|
||||||
|
if match(map(synstack(a:lnum, cnum),
|
||||||
|
\ "synIDattr(v:val, 'name')"), 'python\S*String') == -1
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
endfor
|
||||||
|
return 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! GetPythonPEPIndent(lnum)
|
||||||
|
" First line has indent 0
|
||||||
|
if a:lnum == 1
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let prevline = getline(a:lnum-1)
|
||||||
|
|
||||||
|
" Multilinestrings: continous, docstring or starting.
|
||||||
|
if s:is_python_string(a:lnum-1, len(prevline))
|
||||||
|
\ && (s:is_python_string(a:lnum, 1)
|
||||||
|
\ || match(line, '^\%("""\|''''''\)') != -1)
|
||||||
|
|
||||||
|
" Indent closing quotes as the line with the opening ones.
|
||||||
|
let match_quotes = match(line, '^\s*\zs\%("""\|''''''\)')
|
||||||
|
if match_quotes != -1
|
||||||
|
" closing multiline string
|
||||||
|
let quotes = line[match_quotes:(match_quotes+2)]
|
||||||
|
let pairpos = searchpairpos(quotes, '', quotes, 'b')
|
||||||
|
if pairpos[0] != 0
|
||||||
|
return indent(pairpos[0])
|
||||||
|
else
|
||||||
|
" TODO: test to cover this!
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:is_python_string(a:lnum-1)
|
||||||
|
" Previous line is (completely) a string.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if match(prevline, '^\s*\%("""\|''''''\)') != -1
|
||||||
|
" docstring.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indent_multi = get(b:, 'python_pep8_indent_multiline_string',
|
||||||
|
\ get(g:, 'python_pep8_indent_multiline_string', 0))
|
||||||
|
if match(prevline, '\v%("""|'''''')$') != -1
|
||||||
|
" Opening multiline string, started in previous line.
|
||||||
|
if (&autoindent && indent(a:lnum) == indent(a:lnum-1))
|
||||||
|
\ || match(line, '\v^\s+$') != -1
|
||||||
|
" <CR> with empty line or to split up 'foo("""bar' into
|
||||||
|
" 'foo("""' and 'bar'.
|
||||||
|
if indent_multi == -2
|
||||||
|
return indent(a:lnum-1) + s:sw()
|
||||||
|
endif
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Keep existing indent.
|
||||||
|
if match(line, '\v^\s*\S') != -1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if indent_multi != -2
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_opening_paren(a:lnum)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Parens: If we can find an open parenthesis/bracket/brace, line up with it.
|
||||||
|
let indent = s:indent_like_opening_paren(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Blocks: Match indent of first block of this type.
|
||||||
|
let indent = s:indent_like_block(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_previous_line(a:lnum)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
endif
|
||||||
@@ -1,217 +1,433 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python-ident') == -1
|
||||||
|
|
||||||
" PEP8 compatible Python indent file
|
" PEP8 compatible Python indent file
|
||||||
|
" Language: Python
|
||||||
|
" Maintainer: Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
" Prev Maintainer: Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Prev Maintainer: Eric Mc Sween <em@tomcom.de> (address invalid)
|
||||||
|
" Original Author: David Bustos <bustos@caltech.edu> (address invalid)
|
||||||
|
" License: CC0
|
||||||
|
"
|
||||||
|
" vim-python-pep8-indent - A nicer Python indentation style for vim.
|
||||||
|
" Written in 2004 by David Bustos <bustos@caltech.edu>
|
||||||
|
" Maintained from 2004-2005 by Eric Mc Sween <em@tomcom.de>
|
||||||
|
" Maintained from 2013 by Hynek Schlawack <hs@ox.cx>
|
||||||
|
" Maintained from 2017 by Daniel Hahler <https://daniel.hahler.de/>
|
||||||
|
"
|
||||||
|
" To the extent possible under law, the author(s) have dedicated all copyright
|
||||||
|
" and related and neighboring rights to this software to the public domain
|
||||||
|
" worldwide. This software is distributed without any warranty.
|
||||||
|
" You should have received a copy of the CC0 Public Domain Dedication along
|
||||||
|
" with this software. If not, see
|
||||||
|
" <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||||
|
|
||||||
" Only load this indent file when no other was loaded.
|
" Only load this indent file when no other was loaded.
|
||||||
if exists("b:did_indent")
|
if exists('b:did_indent')
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:did_indent = 1
|
let b:did_indent = 1
|
||||||
|
|
||||||
setlocal expandtab
|
|
||||||
setlocal nolisp
|
setlocal nolisp
|
||||||
setlocal autoindent
|
setlocal autoindent
|
||||||
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
|
setlocal indentexpr=GetPythonPEPIndent(v:lnum)
|
||||||
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
|
setlocal indentkeys=!^F,o,O,<:>,0),0],0},=elif,=except
|
||||||
|
|
||||||
let s:maxoff = 50
|
if !exists('g:python_pep8_indent_multiline_string')
|
||||||
|
let g:python_pep8_indent_multiline_string = 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:block_rules = {
|
||||||
|
\ '^\s*elif\>': ['if', 'elif'],
|
||||||
|
\ '^\s*except\>': ['try', 'except'],
|
||||||
|
\ '^\s*finally\>': ['try', 'except', 'else']
|
||||||
|
\ }
|
||||||
|
let s:block_rules_multiple = {
|
||||||
|
\ '^\s*else\>': ['if', 'elif', 'for', 'try', 'except'],
|
||||||
|
\ }
|
||||||
|
" Pairs to look for when searching for opening parenthesis.
|
||||||
|
" The value is the maximum offset in lines.
|
||||||
|
let s:paren_pairs = {'()': 50, '[]': 100, '{}': 1000}
|
||||||
|
|
||||||
|
if &filetype ==# 'pyrex' || &filetype ==# 'cython'
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except|cdef|cpdef)>'
|
||||||
|
else
|
||||||
|
let b:control_statement = '\v^\s*(class|def|if|while|with|for|except)>'
|
||||||
|
endif
|
||||||
|
let s:stop_statement = '^\s*\(break\|continue\|raise\|return\|pass\)\>'
|
||||||
|
|
||||||
|
" Skip strings and comments. Return 1 for chars to skip.
|
||||||
|
" jedi* refers to syntax definitions from jedi-vim for call signatures, which
|
||||||
|
" are inserted temporarily into the buffer.
|
||||||
|
let s:skip_special_chars = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vstring|comment|jedi\\S"'
|
||||||
|
|
||||||
|
let s:skip_after_opening_paren = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "\\vcomment|jedi\\S"'
|
||||||
|
|
||||||
|
" Also ignore anything concealed.
|
||||||
|
" Wrapper around synconcealed for older Vim (7.3.429, used on Travis CI).
|
||||||
|
function! s:is_concealed(line, col)
|
||||||
|
let concealed = synconcealed(a:line, a:col)
|
||||||
|
return len(concealed) && concealed[0]
|
||||||
|
endfunction
|
||||||
|
if has('conceal')
|
||||||
|
let s:skip_special_chars .= '|| s:is_concealed(line("."), col("."))'
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
let s:skip_search = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
|
||||||
|
\ '=~? "comment"'
|
||||||
|
|
||||||
|
" Use 'shiftwidth()' instead of '&sw'.
|
||||||
|
" (Since Vim patch 7.3.629, 'shiftwidth' can be set to 0 to follow 'tabstop').
|
||||||
|
if exists('*shiftwidth')
|
||||||
|
function! s:sw()
|
||||||
|
return shiftwidth()
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:sw()
|
||||||
|
return &shiftwidth
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:pair_sort(x, y)
|
||||||
|
if a:x[0] == a:y[0]
|
||||||
|
return a:x[1] == a:y[1] ? 0 : a:x[1] > a:y[1] ? 1 : -1
|
||||||
|
else
|
||||||
|
return a:x[0] > a:y[0] ? 1 : -1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Find backwards the closest open parenthesis/bracket/brace.
|
" Find backwards the closest open parenthesis/bracket/brace.
|
||||||
function! s:SearchParensPair()
|
function! s:find_opening_paren(...)
|
||||||
let line = line('.')
|
" optional arguments: line and column (defaults to 1) to search around
|
||||||
let col = col('.')
|
if a:0 > 0
|
||||||
|
let view = winsaveview()
|
||||||
" Skip strings and comments and don't look too far
|
call cursor(a:1, a:0 > 1 ? a:2 : 1)
|
||||||
let skip = "line('.') < " . (line - s:maxoff) . " ? dummy :" .
|
let ret = s:find_opening_paren()
|
||||||
\ 'synIDattr(synID(line("."), col("."), 0), "name") =~? ' .
|
call winrestview(view)
|
||||||
\ '"string\\|comment"'
|
return ret
|
||||||
|
|
||||||
" Search for parentheses
|
|
||||||
call cursor(line, col)
|
|
||||||
let parlnum = searchpair('(', '', ')', 'bW', skip)
|
|
||||||
let parcol = col('.')
|
|
||||||
|
|
||||||
" Search for brackets
|
|
||||||
call cursor(line, col)
|
|
||||||
let par2lnum = searchpair('\[', '', '\]', 'bW', skip)
|
|
||||||
let par2col = col('.')
|
|
||||||
|
|
||||||
" Search for braces
|
|
||||||
call cursor(line, col)
|
|
||||||
let par3lnum = searchpair('{', '', '}', 'bW', skip)
|
|
||||||
let par3col = col('.')
|
|
||||||
|
|
||||||
" Get the closest match
|
|
||||||
if par2lnum > parlnum || (par2lnum == parlnum && par2col > parcol)
|
|
||||||
let parlnum = par2lnum
|
|
||||||
let parcol = par2col
|
|
||||||
endif
|
|
||||||
if par3lnum > parlnum || (par3lnum == parlnum && par3col > parcol)
|
|
||||||
let parlnum = par3lnum
|
|
||||||
let parcol = par3col
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Put the cursor on the match
|
" Return if cursor is in a comment.
|
||||||
if parlnum > 0
|
exe 'if' s:skip_search '| return [0, 0] | endif'
|
||||||
call cursor(parlnum, parcol)
|
|
||||||
|
let nearest = [0, 0]
|
||||||
|
for [p, maxoff] in items(s:paren_pairs)
|
||||||
|
let stopline = max([0, line('.') - maxoff, nearest[0]])
|
||||||
|
let next = searchpairpos(
|
||||||
|
\ '\V'.p[0], '', '\V'.p[1], 'bnW', s:skip_special_chars, stopline)
|
||||||
|
if next[0] && (next[0] > nearest[0] || (next[0] == nearest[0] && next[1] > nearest[1]))
|
||||||
|
let nearest = next
|
||||||
endif
|
endif
|
||||||
return parlnum
|
endfor
|
||||||
|
return nearest
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Find the start of a multi-line statement
|
" Find the start of a multi-line statement
|
||||||
function! s:StatementStart(lnum)
|
function! s:find_start_of_multiline_statement(lnum)
|
||||||
let lnum = a:lnum
|
let lnum = a:lnum
|
||||||
while 1
|
while lnum > 0
|
||||||
if getline(lnum - 1) =~ '\\$'
|
if getline(lnum - 1) =~# '\\$'
|
||||||
let lnum = lnum - 1
|
|
||||||
else
|
|
||||||
call cursor(lnum, 1)
|
|
||||||
let maybe_lnum = s:SearchParensPair()
|
|
||||||
if maybe_lnum < 1
|
|
||||||
return lnum
|
|
||||||
else
|
|
||||||
let lnum = maybe_lnum
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endwhile
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Find the block starter that matches the current line
|
|
||||||
function! s:BlockStarter(lnum, block_start_re)
|
|
||||||
let lnum = a:lnum
|
|
||||||
let maxindent = 10000 " whatever
|
|
||||||
while lnum > 1
|
|
||||||
let lnum = prevnonblank(lnum - 1)
|
let lnum = prevnonblank(lnum - 1)
|
||||||
if indent(lnum) < maxindent
|
else
|
||||||
if getline(lnum) =~ a:block_start_re
|
let [paren_lnum, _] = s:find_opening_paren(lnum)
|
||||||
|
if paren_lnum < 1
|
||||||
return lnum
|
return lnum
|
||||||
else
|
else
|
||||||
let maxindent = indent(lnum)
|
let lnum = paren_lnum
|
||||||
" It's not worth going further if we reached the top level
|
|
||||||
if maxindent == 0
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
return -1
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! GetPythonPEPIndent(lnum)
|
" Find possible indent(s) of the block starter that matches the current line.
|
||||||
let scol = col('.')
|
function! s:find_start_of_block(lnum, types, multiple)
|
||||||
|
let r = []
|
||||||
" First line has indent 0
|
let types = copy(a:types)
|
||||||
if a:lnum == 1
|
let re = '\V\^\s\*\('.join(a:types, '\|').'\)\>'
|
||||||
return 0
|
let lnum = a:lnum
|
||||||
|
let last_indent = indent(lnum) + 1
|
||||||
|
while lnum > 0 && last_indent > 0
|
||||||
|
let indent = indent(lnum)
|
||||||
|
if indent < last_indent
|
||||||
|
for type in types
|
||||||
|
let re = '\v^\s*'.type.'>'
|
||||||
|
if getline(lnum) =~# re
|
||||||
|
if !a:multiple
|
||||||
|
return [indent]
|
||||||
endif
|
endif
|
||||||
|
if index(r, indent) == -1
|
||||||
|
let r += [indent]
|
||||||
|
endif
|
||||||
|
" Remove any handled type, e.g. 'if'.
|
||||||
|
call remove(types, index(types, type))
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
let last_indent = indent(lnum)
|
||||||
|
endif
|
||||||
|
let lnum = prevnonblank(lnum - 1)
|
||||||
|
endwhile
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
" If we can find an open parenthesis/bracket/brace, line up with it.
|
" Is "expr" true for every position in "lnum", beginning at "start"?
|
||||||
call cursor(a:lnum, 1)
|
" (optionally up to a:1 / 4th argument)
|
||||||
let parlnum = s:SearchParensPair()
|
function! s:match_expr_on_line(expr, lnum, start, ...)
|
||||||
if parlnum > 0
|
let text = getline(a:lnum)
|
||||||
let parcol = col('.')
|
let end = a:0 ? a:1 : len(text)
|
||||||
let matches = matchlist(getline(a:lnum), '^\(\s*\)[])}]')
|
if a:start > end
|
||||||
if len(matches) == 0
|
return 1
|
||||||
let closing_paren = 0
|
endif
|
||||||
let closing_paren_pos = 0
|
let save_pos = getpos('.')
|
||||||
|
let r = 1
|
||||||
|
for i in range(a:start, end)
|
||||||
|
call cursor(a:lnum, i)
|
||||||
|
if !(eval(a:expr) || text[i-1] =~# '\s')
|
||||||
|
let r = 0
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call setpos('.', save_pos)
|
||||||
|
return r
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Line up with open parenthesis/bracket/brace.
|
||||||
|
function! s:indent_like_opening_paren(lnum)
|
||||||
|
let [paren_lnum, paren_col] = s:find_opening_paren(a:lnum)
|
||||||
|
if paren_lnum <= 0
|
||||||
|
return -2
|
||||||
|
endif
|
||||||
|
let text = getline(paren_lnum)
|
||||||
|
let base = indent(paren_lnum)
|
||||||
|
|
||||||
|
let nothing_after_opening_paren = s:match_expr_on_line(
|
||||||
|
\ s:skip_after_opening_paren, paren_lnum, paren_col+1)
|
||||||
|
let starts_with_closing_paren = getline(a:lnum) =~# '^\s*[])}]'
|
||||||
|
|
||||||
|
if nothing_after_opening_paren
|
||||||
|
if starts_with_closing_paren
|
||||||
|
let res = base
|
||||||
else
|
else
|
||||||
let closing_paren = 1
|
let res = base + s:sw()
|
||||||
let closing_paren_pos = len(matches[1])
|
|
||||||
endif
|
endif
|
||||||
if match(getline(parlnum), '[([{]\s*$', parcol - 1) != -1
|
|
||||||
if closing_paren
|
|
||||||
return indent(parlnum)
|
|
||||||
else
|
else
|
||||||
return indent(parlnum) + &shiftwidth
|
" Indent to match position of opening paren.
|
||||||
|
let res = paren_col
|
||||||
endif
|
endif
|
||||||
elseif a:lnum - 1 != parlnum
|
|
||||||
if closing_paren && closing_paren_pos > scol
|
" If this line is the continuation of a control statement
|
||||||
return indent(parlnum)
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if text =~# b:control_statement && res == base + s:sw()
|
||||||
|
return base + s:sw() * 2
|
||||||
else
|
else
|
||||||
let lastindent = match(getline(a:lnum - 1), '\S')
|
return res
|
||||||
if lastindent != -1 && lastindent < parcol
|
|
||||||
return lastindent
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Match indent of first block of this type.
|
||||||
|
function! s:indent_like_block(lnum)
|
||||||
|
let text = getline(a:lnum)
|
||||||
|
for [multiple, block_rules] in [
|
||||||
|
\ [0, s:block_rules],
|
||||||
|
\ [1, s:block_rules_multiple]]
|
||||||
|
for [line_re, blocks] in items(block_rules)
|
||||||
|
if text !~# line_re
|
||||||
|
continue
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If we line up with an opening column there is a special case
|
let indents = s:find_start_of_block(a:lnum - 1, blocks, multiple)
|
||||||
" we want to handle: a docstring as argument. In that case we
|
if !len(indents)
|
||||||
" don't want to line up with the paren but with the statement
|
|
||||||
" imagine foo(doc=""" as example
|
|
||||||
echo getline(parlnum)
|
|
||||||
if match(getline(parlnum), '\("""\|' . "'''" . '\)\s*$') != -1
|
|
||||||
return indent(parlnum)
|
|
||||||
endif
|
|
||||||
|
|
||||||
return parcol
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Examine this line
|
|
||||||
let thisline = getline(a:lnum)
|
|
||||||
let thisindent = indent(a:lnum)
|
|
||||||
|
|
||||||
" If the line starts with 'elif' or 'else', line up with 'if' or 'elif'
|
|
||||||
if thisline =~ '^\s*\(elif\|else\)\>'
|
|
||||||
let bslnum = s:BlockStarter(a:lnum, '^\s*\(if\|elif\)\>')
|
|
||||||
if bslnum > 0
|
|
||||||
return indent(bslnum)
|
|
||||||
else
|
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
if len(indents) == 1
|
||||||
|
return indents[0]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If the line starts with 'except' or 'finally', line up with 'try'
|
" Multiple valid indents, e.g. for 'else' with both try and if.
|
||||||
" or 'except'
|
let indent = indent(a:lnum)
|
||||||
if thisline =~ '^\s*\(except\|finally\)\>'
|
if index(indents, indent) != -1
|
||||||
let bslnum = s:BlockStarter(a:lnum, '^\s*\(try\|except\)\>')
|
" The indent is valid, keep it.
|
||||||
if bslnum > 0
|
return indent
|
||||||
return indent(bslnum)
|
|
||||||
else
|
|
||||||
return -1
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
" Fallback to the first/nearest one.
|
||||||
|
return indents[0]
|
||||||
|
endfor
|
||||||
|
endfor
|
||||||
|
return -2
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Examine previous line
|
function! s:indent_like_previous_line(lnum)
|
||||||
let plnum = a:lnum - 1
|
let lnum = prevnonblank(a:lnum - 1)
|
||||||
let pline = getline(plnum)
|
|
||||||
let sslnum = s:StatementStart(plnum)
|
|
||||||
|
|
||||||
" If the previous line is blank, keep the same indentation
|
" No previous line, keep current indent.
|
||||||
if pline =~ '^\s*$'
|
if lnum < 1
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If this line is explicitly joined, try to find an indentation that looks
|
let text = getline(lnum)
|
||||||
" good.
|
let start = s:find_start_of_multiline_statement(lnum)
|
||||||
if pline =~ '\\$'
|
let base = indent(start)
|
||||||
let compound_statement = '^\s*\(if\|while\|from\|import\|for\s.*\sin\|except\)\s*'
|
let current = indent(a:lnum)
|
||||||
let maybe_indent = matchend(getline(sslnum), compound_statement)
|
|
||||||
if maybe_indent != -1
|
" Jump to last character in previous line.
|
||||||
return maybe_indent
|
call cursor(lnum, len(text))
|
||||||
else
|
let ignore_last_char = eval(s:skip_special_chars)
|
||||||
return indent(sslnum) + &sw * 2
|
|
||||||
|
" Search for final colon that is not inside something to be ignored.
|
||||||
|
while 1
|
||||||
|
let curpos = getpos('.')[2]
|
||||||
|
if curpos == 1 | break | endif
|
||||||
|
if eval(s:skip_special_chars) || text[curpos-1] =~# '\s'
|
||||||
|
normal! h
|
||||||
|
continue
|
||||||
|
elseif text[curpos-1] ==# ':'
|
||||||
|
return base + s:sw()
|
||||||
endif
|
endif
|
||||||
|
break
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
if text =~# '\\$' && !ignore_last_char
|
||||||
|
" If this line is the continuation of a control statement
|
||||||
|
" indent further to distinguish the continuation line
|
||||||
|
" from the next logical line.
|
||||||
|
if getline(start) =~# b:control_statement
|
||||||
|
return base + s:sw() * 2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If the previous line ended with a colon and is not a comment, indent
|
" Nest (other) explicit continuations only one level deeper.
|
||||||
" relative to statement start.
|
return base + s:sw()
|
||||||
if pline =~ '^[^#]*:\s*\(#.*\)\?$'
|
|
||||||
return indent(sslnum) + &sw
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" If the previous line was a stop-execution statement or a pass
|
let empty = getline(a:lnum) =~# '^\s*$'
|
||||||
if getline(sslnum) =~ '^\s*\(break\|continue\|raise\|return\|pass\)\>'
|
|
||||||
" See if the user has already dedented
|
" Current and prev line are empty, next is not -> indent like next.
|
||||||
if indent(a:lnum) > indent(sslnum) - &sw
|
if empty && a:lnum > 1 &&
|
||||||
" If not, recommend one dedent
|
\ (getline(a:lnum - 1) =~# '^\s*$') &&
|
||||||
return indent(sslnum) - &sw
|
\ !(getline(a:lnum + 1) =~# '^\s*$')
|
||||||
|
return indent(a:lnum + 1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If the previous statement was a stop-execution statement or a pass
|
||||||
|
if getline(start) =~# s:stop_statement
|
||||||
|
" Remove one level of indentation if the user hasn't already dedented
|
||||||
|
if empty || current > base - s:sw()
|
||||||
|
return base - s:sw()
|
||||||
endif
|
endif
|
||||||
" Otherwise, trust the user
|
" Otherwise, trust the user
|
||||||
return -1
|
return -1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if !empty && s:is_dedented_already(current, base)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
" In all other cases, line up with the start of the previous statement.
|
" In all other cases, line up with the start of the previous statement.
|
||||||
return indent(sslnum)
|
return base
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" If this line is dedented and the number of indent spaces is valid
|
||||||
|
" (multiple of the indentation size), trust the user.
|
||||||
|
function! s:is_dedented_already(current, base)
|
||||||
|
let dedent_size = a:current - a:base
|
||||||
|
return (dedent_size < 0 && a:current % s:sw() == 0) ? 1 : 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is the syntax at lnum (and optionally cnum) a python string?
|
||||||
|
function! s:is_python_string(lnum, ...)
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let linelen = len(line)
|
||||||
|
if linelen < 1
|
||||||
|
let linelen = 1
|
||||||
|
endif
|
||||||
|
let cols = a:0 ? type(a:1) != type([]) ? [a:1] : a:1 : range(1, linelen)
|
||||||
|
for cnum in cols
|
||||||
|
if match(map(synstack(a:lnum, cnum),
|
||||||
|
\ "synIDattr(v:val, 'name')"), 'python\S*String') == -1
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
endfor
|
||||||
|
return 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! GetPythonPEPIndent(lnum)
|
||||||
|
" First line has indent 0
|
||||||
|
if a:lnum == 1
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
|
let line = getline(a:lnum)
|
||||||
|
let prevline = getline(a:lnum-1)
|
||||||
|
|
||||||
|
" Multilinestrings: continous, docstring or starting.
|
||||||
|
if s:is_python_string(a:lnum-1, len(prevline))
|
||||||
|
\ && (s:is_python_string(a:lnum, 1)
|
||||||
|
\ || match(line, '^\%("""\|''''''\)') != -1)
|
||||||
|
|
||||||
|
" Indent closing quotes as the line with the opening ones.
|
||||||
|
let match_quotes = match(line, '^\s*\zs\%("""\|''''''\)')
|
||||||
|
if match_quotes != -1
|
||||||
|
" closing multiline string
|
||||||
|
let quotes = line[match_quotes:(match_quotes+2)]
|
||||||
|
let pairpos = searchpairpos(quotes, '', quotes, 'b')
|
||||||
|
if pairpos[0] != 0
|
||||||
|
return indent(pairpos[0])
|
||||||
|
else
|
||||||
|
" TODO: test to cover this!
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:is_python_string(a:lnum-1)
|
||||||
|
" Previous line is (completely) a string.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
if match(prevline, '^\s*\%("""\|''''''\)') != -1
|
||||||
|
" docstring.
|
||||||
|
return indent(a:lnum-1)
|
||||||
|
endif
|
||||||
|
|
||||||
|
let indent_multi = get(b:, 'python_pep8_indent_multiline_string',
|
||||||
|
\ get(g:, 'python_pep8_indent_multiline_string', 0))
|
||||||
|
if match(prevline, '\v%("""|'''''')$') != -1
|
||||||
|
" Opening multiline string, started in previous line.
|
||||||
|
if (&autoindent && indent(a:lnum) == indent(a:lnum-1))
|
||||||
|
\ || match(line, '\v^\s+$') != -1
|
||||||
|
" <CR> with empty line or to split up 'foo("""bar' into
|
||||||
|
" 'foo("""' and 'bar'.
|
||||||
|
if indent_multi == -2
|
||||||
|
return indent(a:lnum-1) + s:sw()
|
||||||
|
endif
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Keep existing indent.
|
||||||
|
if match(line, '\v^\s*\S') != -1
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
|
||||||
|
if indent_multi != -2
|
||||||
|
return indent_multi
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_opening_paren(a:lnum)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Parens: If we can find an open parenthesis/bracket/brace, line up with it.
|
||||||
|
let indent = s:indent_like_opening_paren(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Blocks: Match indent of first block of this type.
|
||||||
|
let indent = s:indent_like_block(a:lnum)
|
||||||
|
if indent >= -1
|
||||||
|
return indent
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:indent_like_previous_line(a:lnum)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -1,267 +1,404 @@
|
|||||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'python') == -1
|
||||||
|
|
||||||
" Vim syntax file
|
|
||||||
"
|
|
||||||
" Based on python.vim (from Vim 6.1 distribution)
|
|
||||||
" by Neil Schemenauer <nas@python.ca>
|
|
||||||
"
|
|
||||||
" Notes Armin:
|
|
||||||
"
|
|
||||||
" This version of the syntax file works better for 2.x and 3.x without
|
|
||||||
" having to switch modes.
|
|
||||||
"
|
|
||||||
" Thanks:
|
|
||||||
"
|
|
||||||
" Jeroen Ruigrok van der Werven
|
|
||||||
" for the idea of highlighting for erroneous operators
|
|
||||||
" Pedro Algarvio
|
|
||||||
" for the patch to enable spell checking only for the right spots
|
|
||||||
" (strings and comments)
|
|
||||||
|
|
||||||
"
|
|
||||||
" Options:
|
|
||||||
"
|
|
||||||
" For set option do: let OPTION_NAME = 1
|
|
||||||
" For clear option do: let OPTION_NAME = 0
|
|
||||||
"
|
|
||||||
" Option names:
|
|
||||||
"
|
|
||||||
" For highlight builtin functions:
|
|
||||||
" python_highlight_builtins
|
|
||||||
"
|
|
||||||
" For highlight standard exceptions:
|
|
||||||
" python_highlight_exceptions
|
|
||||||
"
|
|
||||||
" For highlight string formatting:
|
|
||||||
" python_highlight_string_formatting
|
|
||||||
"
|
|
||||||
" For highlight indentation errors:
|
|
||||||
" python_highlight_indent_errors
|
|
||||||
"
|
|
||||||
" For highlight trailing spaces:
|
|
||||||
" python_highlight_space_errors
|
|
||||||
"
|
|
||||||
" For highlight doc-tests:
|
|
||||||
" python_highlight_doctests
|
|
||||||
"
|
|
||||||
" If you want all possible Python highlighting:
|
|
||||||
" (This option not override previously set options)
|
|
||||||
" python_highlight_all
|
|
||||||
"
|
|
||||||
" For fast machines:
|
|
||||||
" python_slow_sync
|
|
||||||
"
|
|
||||||
|
|
||||||
" 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 v: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")
|
"
|
||||||
let python_highlight_builtins = 1
|
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
|
||||||
|
function! s:EnableByDefault(name)
|
||||||
|
if !exists(a:name)
|
||||||
|
let {a:name} = 1
|
||||||
endif
|
endif
|
||||||
if !exists("python_highlight_exceptions")
|
endfunction
|
||||||
let python_highlight_exceptions = 1
|
|
||||||
|
" Check if option is enabled
|
||||||
|
function! s:Enabled(name)
|
||||||
|
return exists(a:name) && {a:name}
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Is it Python 2 syntax?
|
||||||
|
function! s:Python2Syntax()
|
||||||
|
if exists('b:python_version_2')
|
||||||
|
return b:python_version_2
|
||||||
endif
|
endif
|
||||||
if !exists("python_highlight_string_formatting")
|
return s:Enabled('g:python_version_2')
|
||||||
let python_highlight_string_formatting = 1
|
endfunction
|
||||||
endif
|
|
||||||
if !exists("python_highlight_indent_errors")
|
"
|
||||||
let python_highlight_indent_errors = 1
|
" Default options
|
||||||
endif
|
"
|
||||||
if !exists("python_highlight_space_errors")
|
|
||||||
let python_highlight_space_errors = 1
|
call s:EnableByDefault('g:python_slow_sync')
|
||||||
endif
|
call s:EnableByDefault('g:python_highlight_builtin_funcs_kwarg')
|
||||||
if !exists("python_highlight_doctests")
|
|
||||||
let python_highlight_doctests = 1
|
if s:Enabled('g:python_highlight_all')
|
||||||
|
call s:EnableByDefault('g:python_highlight_builtins')
|
||||||
|
if s:Enabled('g:python_highlight_builtins')
|
||||||
|
call s:EnableByDefault('g:python_highlight_builtin_objs')
|
||||||
|
call s:EnableByDefault('g:python_highlight_builtin_funcs')
|
||||||
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')
|
||||||
|
call s:EnableByDefault('g:python_highlight_class_vars')
|
||||||
|
call s:EnableByDefault('g:python_highlight_operators')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
" Keywords
|
" Keywords
|
||||||
syn keyword pythonStatement break continue del
|
"
|
||||||
syn keyword pythonStatement exec return
|
|
||||||
syn keyword pythonStatement pass raise
|
syn keyword pythonStatement break continue del return pass yield global assert lambda with
|
||||||
syn keyword pythonStatement global assert
|
syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite
|
||||||
syn keyword pythonStatement lambda yield
|
|
||||||
syn keyword pythonStatement async await
|
|
||||||
syn keyword pythonStatement with nonlocal True False None
|
|
||||||
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
|
if s:Enabled('g:python_highlight_class_vars')
|
||||||
|
syn keyword pythonClassVar self cls
|
||||||
|
endif
|
||||||
syn keyword pythonRepeat for while
|
syn keyword pythonRepeat for while
|
||||||
syn keyword pythonConditional if elif else
|
syn keyword pythonConditional if elif else
|
||||||
syn keyword pythonImport import from as
|
|
||||||
syn keyword pythonException try except finally
|
syn keyword pythonException try except finally
|
||||||
|
" The standard pyrex.vim unconditionally removes the pythonInclude group, so
|
||||||
|
" we provide a dummy group here to avoid crashing pyrex.vim.
|
||||||
|
syn keyword pythonInclude import
|
||||||
|
syn keyword pythonImport import
|
||||||
|
syn match pythonRaiseFromStatement '\<from\>'
|
||||||
|
syn match pythonImport '^\s*\zsfrom\>'
|
||||||
|
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
if !s:Enabled('g:python_print_as_function')
|
||||||
|
syn keyword pythonStatement print
|
||||||
|
endif
|
||||||
|
syn keyword pythonStatement exec
|
||||||
|
syn keyword pythonImport as
|
||||||
|
syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained
|
||||||
|
else
|
||||||
|
syn keyword pythonStatement as nonlocal
|
||||||
|
syn match pythonStatement '\v\.@<!<await>'
|
||||||
|
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
|
||||||
|
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
|
||||||
|
syn match pythonStatement '\<async\s\+with\>'
|
||||||
|
syn match pythonStatement '\<async\s\+for\>'
|
||||||
|
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
"
|
||||||
|
" Operators
|
||||||
|
"
|
||||||
syn keyword pythonOperator and in is not or
|
syn keyword pythonOperator and in is not or
|
||||||
|
if s:Enabled('g:python_highlight_operators')
|
||||||
|
syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!='
|
||||||
|
endif
|
||||||
|
syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[<!>]\+=\{2,}\|!\{2,}=\+' display
|
||||||
|
|
||||||
" Print keyword but only if not used as function
|
"
|
||||||
syn match pythonStatement "\<print\>\((\|,\|*=\)\@!" display
|
|
||||||
|
|
||||||
" Decorators (new in Python 2.4)
|
" Decorators (new in Python 2.4)
|
||||||
syn match pythonDecorator "@" display nextgroup=pythonFunction skipwhite
|
"
|
||||||
|
|
||||||
|
syn match pythonDecorator '^\s*\zs@' 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 pythonDot '\.' display containedin=pythonDottedName
|
||||||
|
|
||||||
|
"
|
||||||
" Comments
|
" Comments
|
||||||
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
|
"
|
||||||
syn match pythonRun "\%^#!.*$"
|
|
||||||
syn match pythonCoding "\%^.*\(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
syn match pythonComment '#.*$' display contains=pythonTodo,@Spell
|
||||||
|
if !s:Enabled('g:python_highlight_file_headers_as_comments')
|
||||||
|
syn match pythonRun '\%^#!.*$'
|
||||||
|
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
|
" Errors
|
||||||
syn match pythonError "\<\d\+\D\+\>" display
|
"
|
||||||
syn match pythonError "[$?]" display
|
|
||||||
syn match pythonError "[-+&|]\{2,}" display
|
|
||||||
syn match pythonError "[=]\{3,}" display
|
|
||||||
|
|
||||||
" TODO: Mixing spaces and tabs also may be used for pretty formatting multiline
|
syn match pythonError '\<\d\+[^0-9[:space:]]\+\>' display
|
||||||
" statements. For now I don't know how to work around this.
|
|
||||||
if exists("python_highlight_indent_errors") && python_highlight_indent_errors != 0
|
" Mixing spaces and tabs also may be used for pretty formatting multiline
|
||||||
syn match pythonIndentError "^\s*\( \t\|\t \)\s*\S"me=e-1 display
|
" statements
|
||||||
|
if s:Enabled('g:python_highlight_indent_errors')
|
||||||
|
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=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
"
|
||||||
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonEscape,pythonEscapeError,@Spell
|
|
||||||
syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonEscape,pythonEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonString start=+'''+ 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]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
syn match pythonEscape "\\$"
|
syn region pythonString start=+[bB]\='''+ skip=+\\'+ 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]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
" Byte-Strings
|
syn match pythonBytesError '.\+' display contained
|
||||||
syn region pythonBString start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBEscape,pythonBEscapeError,@Spell
|
syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError
|
||||||
syn region pythonBString start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBEscape,pythonBEscapeError,@Spell
|
|
||||||
syn region pythonBString start=+[bB]"""+ end=+"""+ keepend contains=pythonBEscape,pythonBEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
|
||||||
syn region pythonBString start=+[bB]'''+ end=+'''+ keepend contains=pythonBEscape,pythonBEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
|
||||||
|
|
||||||
syn match pythonBEscape +\\[abfnrtv'"\\]+ display contained
|
|
||||||
syn match pythonBEscape "\\\o\o\=\o\=" display contained
|
|
||||||
syn match pythonBEscapeError "\\\o\{,2}[89]" display contained
|
|
||||||
syn match pythonBEscape "\\x\x\{2}" display contained
|
|
||||||
syn match pythonBEscapeError "\\x\x\=\X" display contained
|
|
||||||
syn match pythonBEscape "\\$"
|
|
||||||
|
|
||||||
" Unicode strings
|
|
||||||
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 "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
|
|
||||||
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
|
|
||||||
|
|
||||||
if exists("python_highlight_string_formatting") && python_highlight_string_formatting != 0
|
|
||||||
" String formatting
|
|
||||||
syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]*\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonBString,pythonUniString,pythonRawString,pythonUniRawString
|
|
||||||
syn match pythonStrFormat "%[-#0 +]*\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonBString,pythonUniString,pythonRawString,pythonUniRawString
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_highlight_doctests") && python_highlight_doctests != 0
|
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 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
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
" Python 2 Unicode strings
|
||||||
|
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonUniString start=+[uU]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonUniString start=+[uU]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,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=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||||
|
syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,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]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonUniRawString start=+[uU][rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,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]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawString start=+[bB]\=[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,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]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawString start=+[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||||
|
syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||||
|
endif
|
||||||
|
|
||||||
|
syn match pythonRawEscape +\\['"]+ display 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,pythonBytesContent
|
||||||
|
syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent
|
||||||
|
else
|
||||||
|
syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent
|
||||||
|
syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonRawString,pythonBytesContent
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_string_format')
|
||||||
|
" str.format syntax
|
||||||
|
if s:Python2Syntax()
|
||||||
|
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 "{\%(\%([^[: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
|
||||||
|
syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression
|
||||||
|
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_string_templates')
|
||||||
|
" string.Template format
|
||||||
|
if s:Python2Syntax()
|
||||||
|
syn match pythonStrTemplate '\$\$' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||||
|
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
|
||||||
|
|
||||||
|
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*>>>' skip=+\\'+ end=+'''+he=s-1 end='^\s*$' contained
|
||||||
syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
|
syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
" Numbers (ints, longs, floats, complex)
|
" Numbers (ints, longs, floats, complex)
|
||||||
syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
|
"
|
||||||
syn match pythonHexNumber "\<0[xX]\>" 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*[lL]\=\>" display
|
if s:Python2Syntax()
|
||||||
syn match pythonHexError "\<0[xX]\X\+[lL]\=\>" display
|
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
|
||||||
|
|
||||||
if exists("python_highlight_builtins") && python_highlight_builtins != 0
|
syn match pythonHexNumber '\<0[xX]\x\+[lL]\=\>' display
|
||||||
" Builtin functions, types and objects
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
else
|
||||||
|
syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display
|
||||||
|
" pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError
|
||||||
|
syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display
|
||||||
|
syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display
|
||||||
|
|
||||||
|
syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display
|
||||||
|
syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display
|
||||||
|
syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display
|
||||||
|
|
||||||
|
syn match pythonNumberError '\<\d[_0-9]*\D\>' display
|
||||||
|
syn match pythonNumberError '\<0[_0-9]\+\>' display
|
||||||
|
syn match pythonNumberError '\<0_x\S*\>' display
|
||||||
|
syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display
|
||||||
|
syn match pythonNumberError '\<\d[_0-9]*_\>' display
|
||||||
|
syn match pythonNumber '\<\d\>' display
|
||||||
|
syn match pythonNumber '\<[1-9][_0-9]*\d\>' display
|
||||||
|
syn match pythonNumber '\<\d[jJ]\>' display
|
||||||
|
syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display
|
||||||
|
|
||||||
|
syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display
|
||||||
|
syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display
|
||||||
|
|
||||||
|
syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display
|
||||||
|
syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display
|
||||||
|
syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display
|
||||||
|
endif
|
||||||
|
|
||||||
|
"
|
||||||
|
" Builtin objects and types
|
||||||
|
"
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_builtin_objs')
|
||||||
|
syn keyword pythonNone None
|
||||||
|
syn keyword pythonBoolean True False
|
||||||
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
||||||
|
syn match pythonBuiltinObj '\v\.@<!<%(object|bool|int|float|tuple|str|list|dict|set|frozenset|bytearray|bytes)>'
|
||||||
syn keyword pythonBuiltinFunc __import__ abs all any apply
|
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
|
||||||
syn keyword pythonBuiltinFunc basestring bool buffer bytearray bytes callable
|
syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__
|
||||||
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 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 object oct open ord 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
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_highlight_exceptions") && python_highlight_exceptions != 0
|
"
|
||||||
" Builtin exceptions and warnings
|
" Builtin functions
|
||||||
syn keyword pythonExClass BaseException
|
"
|
||||||
syn keyword pythonExClass Exception StandardError ArithmeticError
|
|
||||||
syn keyword pythonExClass LookupError EnvironmentError
|
|
||||||
|
|
||||||
syn keyword pythonExClass AssertionError AttributeError EOFError
|
if s:Enabled('g:python_highlight_builtin_funcs')
|
||||||
syn keyword pythonExClass FloatingPointError GeneratorExit IOError
|
let s:funcs_re = '__import__|abs|all|any|bin|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|oct|open|ord|pow|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip'
|
||||||
syn keyword pythonExClass ImportError IndexError KeyError
|
|
||||||
syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
|
|
||||||
syn keyword pythonExClass NotImplementedError OSError OverflowError
|
|
||||||
syn keyword pythonExClass ReferenceError RuntimeError StopIteration
|
|
||||||
syn keyword pythonExClass SyntaxError IndentationError TabError
|
|
||||||
syn keyword pythonExClass SystemError SystemExit TypeError
|
|
||||||
syn keyword pythonExClass UnboundLocalError UnicodeError
|
|
||||||
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
|
|
||||||
syn keyword pythonExClass UnicodeTranslateError ValueError
|
|
||||||
syn keyword pythonExClass WindowsError ZeroDivisionError
|
|
||||||
|
|
||||||
syn keyword pythonExClass Warning UserWarning DeprecationWarning
|
if s:Python2Syntax()
|
||||||
syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
|
let s:funcs_re .= '|apply|basestring|buffer|cmp|coerce|execfile|file|intern|long|raw_input|reduce|reload|unichr|unicode|xrange'
|
||||||
syn keyword pythonExClass RuntimeWarning FutureWarning OverflowWarning
|
if s:Enabled('g:python_print_as_function')
|
||||||
syn keyword pythonExClass ImportWarning UnicodeWarning
|
let s:funcs_re .= '|print'
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
let s:funcs_re .= '|ascii|exec|print'
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@<!\zs<%(' . s:funcs_re . ')>'
|
||||||
|
|
||||||
|
if !s:Enabled('g:python_highlight_builtin_funcs_kwarg')
|
||||||
|
let s:funcs_re .= '\=@!'
|
||||||
|
endif
|
||||||
|
|
||||||
|
execute s:funcs_re . ''''
|
||||||
|
unlet s:funcs_re
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists("python_slow_sync") && python_slow_sync != 0
|
"
|
||||||
|
" Builtin exceptions and warnings
|
||||||
|
"
|
||||||
|
|
||||||
|
if s:Enabled('g:python_highlight_exceptions')
|
||||||
|
let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDepricationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning'
|
||||||
|
|
||||||
|
if s:Python2Syntax()
|
||||||
|
let s:exs_re .= '|StandardError'
|
||||||
|
else
|
||||||
|
let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning'
|
||||||
|
endif
|
||||||
|
|
||||||
|
execute 'syn match pythonExClass ''\v\.@<!\zs<%(' . s:exs_re . ')>'''
|
||||||
|
unlet s:exs_re
|
||||||
|
endif
|
||||||
|
|
||||||
|
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
|
||||||
" is impossible to fix because the only way to know if you are inside a
|
" 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.
|
" triple quoted string is to start from the beginning of the file.
|
||||||
syn sync match pythonSync grouphere NONE "):$"
|
syn sync match pythonSync grouphere NONE '):$'
|
||||||
syn sync maxlines=200
|
syn sync maxlines=200
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if version >= 508 || !exists("did_python_syn_inits")
|
if v:version >= 508 || !exists('did_python_syn_inits')
|
||||||
if version <= 508
|
if v:version <= 508
|
||||||
let did_python_syn_inits = 1
|
let did_python_syn_inits = 1
|
||||||
command -nargs=+ HiLink hi link <args>
|
command -nargs=+ HiLink hi link <args>
|
||||||
else
|
else
|
||||||
@@ -269,7 +406,8 @@ if version >= 508 || !exists("did_python_syn_inits")
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
HiLink pythonStatement Statement
|
HiLink pythonStatement Statement
|
||||||
HiLink pythonImport Statement
|
HiLink pythonRaiseFromStatement Statement
|
||||||
|
HiLink pythonImport Include
|
||||||
HiLink pythonFunction Function
|
HiLink pythonFunction Function
|
||||||
HiLink pythonConditional Conditional
|
HiLink pythonConditional Conditional
|
||||||
HiLink pythonRepeat Repeat
|
HiLink pythonRepeat Repeat
|
||||||
@@ -277,10 +415,14 @@ if version >= 508 || !exists("did_python_syn_inits")
|
|||||||
HiLink pythonOperator Operator
|
HiLink pythonOperator Operator
|
||||||
|
|
||||||
HiLink pythonDecorator Define
|
HiLink pythonDecorator Define
|
||||||
|
HiLink pythonDottedName Function
|
||||||
|
HiLink pythonDot Normal
|
||||||
|
|
||||||
HiLink pythonComment Comment
|
HiLink pythonComment Comment
|
||||||
|
if !s:Enabled('g:python_highlight_file_headers_as_comments')
|
||||||
HiLink pythonCoding Special
|
HiLink pythonCoding Special
|
||||||
HiLink pythonRun Special
|
HiLink pythonRun Special
|
||||||
|
endif
|
||||||
HiLink pythonTodo Todo
|
HiLink pythonTodo Todo
|
||||||
|
|
||||||
HiLink pythonError Error
|
HiLink pythonError Error
|
||||||
@@ -288,39 +430,58 @@ if version >= 508 || !exists("did_python_syn_inits")
|
|||||||
HiLink pythonSpaceError Error
|
HiLink pythonSpaceError Error
|
||||||
|
|
||||||
HiLink pythonString String
|
HiLink pythonString String
|
||||||
HiLink pythonBString String
|
|
||||||
HiLink pythonUniString String
|
|
||||||
HiLink pythonRawString String
|
HiLink pythonRawString String
|
||||||
HiLink pythonUniRawString String
|
HiLink pythonRawEscape Special
|
||||||
|
|
||||||
HiLink pythonEscape Special
|
|
||||||
HiLink pythonBEscape Special
|
|
||||||
HiLink pythonEscapeError Error
|
|
||||||
HiLink pythonBEscapeError 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
|
||||||
|
HiLink pythonFString String
|
||||||
|
HiLink pythonRawFString String
|
||||||
|
HiLink pythonStrInterpRegion Special
|
||||||
|
endif
|
||||||
|
|
||||||
|
HiLink pythonStrFormatting Special
|
||||||
HiLink pythonStrFormat Special
|
HiLink pythonStrFormat Special
|
||||||
|
HiLink pythonStrTemplate Special
|
||||||
|
|
||||||
HiLink pythonDocTest Special
|
HiLink pythonDocTest Special
|
||||||
HiLink pythonDocTest2 Special
|
HiLink pythonDocTest2 Special
|
||||||
|
|
||||||
HiLink pythonNumber Number
|
HiLink pythonNumber Number
|
||||||
HiLink pythonHexNumber Number
|
HiLink pythonHexNumber Number
|
||||||
|
HiLink pythonOctNumber Number
|
||||||
|
HiLink pythonBinNumber Number
|
||||||
HiLink pythonFloat Float
|
HiLink pythonFloat Float
|
||||||
HiLink pythonOctalError Error
|
HiLink pythonNumberError Error
|
||||||
|
HiLink pythonOctError Error
|
||||||
HiLink pythonHexError Error
|
HiLink pythonHexError Error
|
||||||
|
HiLink pythonBinError Error
|
||||||
|
|
||||||
|
HiLink pythonBoolean Boolean
|
||||||
|
HiLink pythonNone Constant
|
||||||
|
|
||||||
HiLink pythonBuiltinObj Structure
|
HiLink pythonBuiltinObj Structure
|
||||||
HiLink pythonBuiltinFunc Function
|
HiLink pythonBuiltinFunc Function
|
||||||
|
|
||||||
HiLink pythonExClass Structure
|
HiLink pythonExClass Structure
|
||||||
|
HiLink pythonClassVar Identifier
|
||||||
|
|
||||||
delcommand HiLink
|
delcommand HiLink
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let b:current_syntax = "python"
|
let b:current_syntax = 'python'
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user