X Tutup
Skip to content

Commit d7cf768

Browse files
committed
Update show documentation functioonality (c) blueyed
1 parent 6924c75 commit d7cf768

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

autoload/pymode/doc.vim

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,37 @@
22
"
33
PymodePython import pymode
44

5+
6+
fun! pymode#doc#find() "{{{
7+
" Extract the 'word' at the cursor, expanding leftwards across identifiers
8+
" and the . operator, and rightwards across the identifier only.
9+
"
10+
" For example:
11+
" import xml.dom.minidom
12+
" ^ !
13+
"
14+
" With the cursor at ^ this returns 'xml'; at ! it returns 'xml.dom'.
15+
let l:line = getline(".")
16+
let l:pre = l:line[:col(".") - 1]
17+
let l:suf = l:line[col("."):]
18+
let word = matchstr(pre, "[A-Za-z0-9_.]*$") . matchstr(suf, "^[A-Za-z0-9_]*")
19+
call pymode#doc#show(word)
20+
endfunction "}}}
21+
22+
23+
524
fun! pymode#doc#show(word) "{{{
625
if a:word == ''
726
call pymode#error("No name/symbol under cursor!")
8-
else
9-
call pymode#tempbuffer_open('__doc__')
10-
PymodePython pymode.get_documentation()
11-
setlocal nomodifiable
12-
setlocal nomodified
13-
setlocal filetype=rst
14-
wincmd p
27+
return 0
1528
endif
29+
30+
call pymode#tempbuffer_open('__doc__')
31+
PymodePython pymode.get_documentation()
32+
setlocal nomodifiable
33+
setlocal nomodified
34+
setlocal filetype=rst
35+
wincmd p
36+
1637
endfunction "}}}
1738

ftplugin/python/pymode.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ if g:pymode_doc
100100
command! -buffer -nargs=1 PymodeDoc call pymode#doc#show("<args>")
101101

102102
" Set keys
103-
exe "nnoremap <silent> <buffer> " g:pymode_doc_bind ":call pymode#doc#show(expand('<cword>'))<CR>"
103+
exe "nnoremap <silent> <buffer> " g:pymode_doc_bind ":call pymode#doc#find()<CR>"
104104
exe "vnoremap <silent> <buffer> " g:pymode_doc_bind ":<C-U>call pymode#doc#show(@*)<CR>"
105105

106106
end

pymode/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ def get_documentation():
3535
help(vim.eval('a:word'))
3636
sys.stdout, out = _, sys.stdout.getvalue()
3737
vim.current.buffer.append(str(out).splitlines(), 0)
38+

0 commit comments

Comments
 (0)
X Tutup