dotfiles/vim/.vim/after/ftplugin/python.vim

32 lines
1.0 KiB
VimL

set tabstop=4 shiftwidth=4 autoindent smartindent expandtab
setlocal colorcolumn=80
setlocal path=.,**
setlocal wildignore+=*.pyc
" Add search in other files inside the path
set include=^\\s*\\(from\\\|import\\)\\s*\\zs\\(\\S\\+\\s\\{-}\\)*\\ze\\($\\\|\ as\\)
function! PyInclude(fname)
" Following examples:
" import conv.metrics
" /conv.metrics/
" conv/metrics.py
" from conv import conversion as conv (2)
" /conv import conversion/
" conv/conversion.py conv.py
let parts = split(a:fname, ' import ') " (1) [conv.metrics] (2) [conv, conversion]
let l = parts[0] " (1) conv.metrics (2) conv
if len ( parts ) > 1
let r = parts[1] " conversion
let joined = join([l,r], '.') " conv.conversion
let fp = substitute(joined, '\.', '/', 'g') . '.py'
let found = glob(fp, 1)
if len(found)
return found
endif
endif
return substitute(joined, '\.', '/', 'g') . '.py'
endfunction
setlocal includeexpr=PyInclude(v:fname)
setlocal define=^\\s*\\<\\(def\\\|class\\)\\>