~gpanders/dotfiles

ref: c8e63bac959db19c138dcc3198a56514f0b444ff dotfiles/.vim/autoload/ft/python.vim -rw-r--r-- 1.2 KiB
c8e63bacGreg Anders Manage dotfiles directly in home directory 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
" Python autoload functions
" Author: Greg Anders

" Generate include path for python, using the terminal's version of Python and
" not Vim's compiled version. Use the asynchronous jobs API if available,
" otherwise make a system call and cache the result.

let s:python_paths = {}

let s:cmd = join([
      \ 'import sys',
      \ 'from glob import glob',
      \ 'from os import path',
      \ 'print(",".join([d for d in sys.path if path.isdir(d) and glob(path.join(d, "*.py"))]))'],
      \ ';')

function! ft#python#set_path(...)
  let python = 'python'
  if a:0 && !empty(a:1)
    let python = a:1
  endif

  if has('nvim') || has('job')
    call async#run([python, '-c', s:cmd], 'let &l:path = &path . '','' . v:val')
  else
    let cwd = getcwd()
    if !has_key(s:python_paths, cwd)
      let s:python_paths[cwd] = systemlist(python . ' -c "' . escape(s:cmd, '"') . '"')[0]
    endif
    let &l:path = &path . ',' . s:python_paths[cwd]
  endif
endfunction

function! ft#python#pydoc(...)
  let keyword = a:0 ? a:1 : expand('<cword>')
  let tmpfile = tempname()
  call writefile(systemlist('pydoc ' . keyword), tmpfile, '')
  pedit +set\ ro\ nobl\ bt=nofile `=tmpfile`
endfunction