configuration/config/nvim/ftplugin/python.vim

65 lines
1.5 KiB
VimL
Raw Normal View History

2015-12-29 21:26:04 +01:00
" Interactive
2016-04-01 08:54:31 +02:00
nnoremap <buffer> <Leader>i :terminal python3 -i %<CR>
2015-12-29 21:26:04 +01:00
" Lint
2015-12-29 21:46:22 +01:00
function! Pylint()
2015-12-29 21:26:04 +01:00
silent !pylint --reports=n --output-format=parseable '%' > /tmp/errors.err 2> /dev/null
cfile
silent !rm /tmp/errors.err
redraw!
copen
endfunction
nnoremap <buffer> <Leader>x :call Pylint()<CR>
2016-04-04 16:43:15 +02:00
function! IndentLevel(lnum)
return indent(a:lnum) / &shiftwidth
endfunction
function! IsBlankLine(lnum)
return getline(a:lnum) =~? '\v^\s*$'
endfunction
function! IsDefLine(lnum)
return getline(a:lnum) =~ '^\s*def\s' || getline(a:lnum) =~ '^\s*class\s'
endfunction
2015-12-29 21:26:04 +01:00
" Folding
2015-12-29 21:46:22 +01:00
function! PythonFold(lnum)
2016-04-04 16:43:15 +02:00
if IsBlankLine(a:lnum)
return '-1'
2015-12-29 21:26:04 +01:00
endif
2016-04-04 16:43:15 +02:00
let this_indent = IndentLevel(a:lnum)
if IsDefLine(a:lnum)
return '>' . (this_indent + 1)
2015-12-29 21:26:04 +01:00
endif
2016-04-04 16:43:15 +02:00
let minimum = this_indent
let current = a:lnum
while current > 1 && minimum > 0
let current -= 1
if IsBlankLine(current)
continue
endif
let current_indent = IndentLevel(current)
if current_indent < minimum
if IsDefLine(current)
return current_indent + 1
endif
let minimum = current_indent
endif
endwhile
return minimum
2015-12-29 21:26:04 +01:00
endfunction
2015-12-29 21:46:22 +01:00
function! PythonFoldText()
2016-04-04 16:43:15 +02:00
return getline(v:foldstart) . ' (' . (v:foldend - v:foldstart) . ' lines) '
2015-12-29 21:26:04 +01:00
endfunction
setlocal foldmethod=expr
setlocal foldexpr=PythonFold(v:lnum)
setlocal foldtext=PythonFoldText()