1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-17 11:30:29 +01:00

- updated FuzzyFinder

- moved Pydoc to ftplugin/python
- updated pyflakes
- added Pygments feature into rst functions
This commit is contained in:
2010-11-15 18:45:27 +01:00
parent 53ddc03045
commit 442a6ab74e
29 changed files with 1779 additions and 1147 deletions

View File

@@ -16,13 +16,16 @@ setlocal colorcolumn=+1
set wildignore+=*.pyc
"inoremap # X<BS>#
inoremap # X<BS>#
"set ofu=syntaxcomplete#Complete
"autocmd FileType python setlocal omnifunc=pysmell#Complete
let python_highlight_all=1
"I don't want to have pyflakes errors in qfix, it interfering with Pep8/Pylint
let g:pyflakes_use_quickfix = 0
"Load views for py files
autocmd BufWinLeave *.py mkview
autocmd BufWinEnter *.py silent loadview

110
ftplugin/python/pydoc.vim Normal file
View File

@@ -0,0 +1,110 @@
"pydoc.vim: pydoc integration for vim
"performs searches and can display the documentation of python modules
"Author: Andr<64> Kelpe <efeshundertelf at googlemail dot com>
"Author: Romain Chossart <romainchossat at gmail dot com>
"Author: Matthias Vogelgesang
"http://www.vim.org/scripts/script.php?script_id=910
"This plugin integrates the pydoc into vim. You can view the
"documentation of a module by using :Pydoc foo.bar.baz or search
"a word (uses pydoc -k) in the documentation by typing PydocSearch
"foobar. You can also view the documentation of the word under the
"cursor by pressing <leader>pw or the WORD (see :help WORD) by pressing
"<leader>pW. "This is very useful if you want to jump to a module which was found by
"PydocSearch. To have a browser like feeling you can use u and CTRL-R to
"go back and forward, just like editing normal text.
"If you want to use the script and pydoc is not in your PATH, just put a
"line like
" let g:pydoc_cmd = \"/usr/bin/pydoc" (without the backslash!!)
"in your .vimrc
"pydoc.vim is free software, you can redistribute or modify
"it under the terms of the GNU General Public License Version 2 or any
"later Version (see http://www.gnu.org/copyleft/gpl.html for details).
"Please feel free to contact me.
set switchbuf=useopen
function! ShowPyDoc(name, type)
if !exists('g:pydoc_cmd')
let g:pydoc_cmd = 'pydoc'
endif
if bufloaded("__doc__") >0
let l:buf_is_new = 0
else
let l:buf_is_new = 1
endif
if bufnr("__doc__") >0
execute "sb __doc__"
else
execute 'split __doc__'
endif
setlocal noswapfile
set buftype=nofile
setlocal modifiable
normal ggdG
let s:name2 = substitute(a:name, '(.*', '', 'g' )
let s:name2 = substitute(a:name, ':', '', 'g' )
if a:type==1
execute "silent read ! " . g:pydoc_cmd . " " . s:name2
else
execute "silent read ! " . g:pydoc_cmd . " -k " . s:name2
endif
setlocal nomodified
set filetype=man
normal 1G
if !exists('g:pydoc_wh')
let g:pydoc_wh = 10
end
resize -999
execute "silent resize +" . g:pydoc_wh
if !exists('g:pydoc_highlight')
let g:pydoc_highlight = 1
endif
if g:pydoc_highlight == 1
call Highlight(s:name2)
endif
let l:line = getline(2)
if l:line =~ "^no Python documentation found for.*$"
if l:buf_is_new
execute "bd!"
else
normal u
endif
redraw
echohl WarningMsg | echo l:line | echohl None
endif
endfunction
function! Highlight(name)
execute "sb __doc__"
set filetype=man
syn on
execute 'syntax keyword pydoc '.s:name2
hi pydoc gui=reverse
endfunction
"mappings
au FileType python,man map <buffer> <leader>pw :call ShowPyDoc('<C-R><C-W>', 1)<CR>
au FileType python,man map <buffer> <leader>pW :call ShowPyDoc('<C-R><C-A>', 1)<CR>
au FileType python,man map <buffer> <leader>pk :call ShowPyDoc('<C-R><C-W>', 0)<CR>
au FileType python,man map <buffer> <leader>pK :call ShowPyDoc('<C-R><C-A>', 0)<CR>
" remap the K (or 'help') key
nnoremap <silent> <buffer> K :call ShowPyDoc(expand("<cword>"), 1)<CR>
"commands
command! -nargs=1 Pydoc :call ShowPyDoc('<args>', 1)
command! -nargs=* PydocSearch :call ShowPyDoc('<args>', 0)

View File

@@ -29,6 +29,11 @@ if !exists("b:did_python_init")
finish
endif
if !exists('g:pyflakes_use_quickfix')
let g:pyflakes_use_quickfix = 1
endif
python << EOF
import vim
import os.path
@@ -154,11 +159,47 @@ if !exists("*s:WideMsg")
let x=&ruler | let y=&showcmd
set noruler noshowcmd
redraw
echo a:msg
echo strpart(a:msg, 0, &columns-1)
let &ruler=x | let &showcmd=y
endfun
endif
if !exists("*s:GetQuickFixStackCount")
function s:GetQuickFixStackCount()
let l:stack_count = 0
try
silent colder 9
catch /E380:/
endtry
try
for i in range(9)
silent cnewer
let l:stack_count = l:stack_count + 1
endfor
catch /E381:/
return l:stack_count
endtry
endfunction
endif
if !exists("*s:ActivatePyflakesQuickFixWindow")
function s:ActivatePyflakesQuickFixWindow()
try
silent colder 9 " go to the bottom of quickfix stack
catch /E380:/
endtry
if s:pyflakes_qf > 0
try
exe "silent cnewer " . s:pyflakes_qf
catch /E381:/
echoerr "Could not activate Pyflakes Quickfix Window."
endtry
endif
endfunction
endif
if !exists("*s:RunPyflakes")
function s:RunPyflakes()
highlight link PyFlakes SpellBad
@@ -174,12 +215,23 @@ if !exists("*s:RunPyflakes")
let b:matched = []
let b:matchedlines = {}
let b:qf_list = []
let b:qf_window_count = -1
python << EOF
for w in check(vim.current.buffer):
vim.command('let s:matchDict = {}')
vim.command("let s:matchDict['lineNum'] = " + str(w.lineno))
vim.command("let s:matchDict['message'] = '%s'" % vim_quote(w.message % w.message_args))
vim.command("let b:matchedlines[" + str(w.lineno) + "] = s:matchDict")
vim.command("let l:qf_item = {}")
vim.command("let l:qf_item.bufnr = bufnr('%')")
vim.command("let l:qf_item.filename = expand('%')")
vim.command("let l:qf_item.lnum = %s" % str(w.lineno))
vim.command("let l:qf_item.text = '%s'" % vim_quote(w.message % w.message_args))
vim.command("let l:qf_item.type = 'E'")
if w.col is None or isinstance(w, SyntaxError):
# without column information, just highlight the whole line
@@ -189,8 +241,24 @@ for w in check(vim.current.buffer):
# with a column number, highlight the first keyword there
vim.command(r"let s:mID = matchadd('PyFlakes', '^\%" + str(w.lineno) + r"l\_.\{-}\zs\k\+\k\@!\%>" + str(w.col) + r"c')")
vim.command("let l:qf_item.vcol = 1")
vim.command("let l:qf_item.col = %s" % str(w.col + 1))
vim.command("call add(b:matched, s:matchDict)")
vim.command("call add(b:qf_list, l:qf_item)")
EOF
if g:pyflakes_use_quickfix == 1
if exists("s:pyflakes_qf")
" if pyflakes quickfix window is already created, reuse it
call s:ActivatePyflakesQuickFixWindow()
call setqflist(b:qf_list, 'r')
else
" one pyflakes quickfix window for all buffer
call setqflist(b:qf_list, '')
let s:pyflakes_qf = s:GetQuickFixStackCount()
endif
endif
let b:cleared = 0
endfunction
end

View File

@@ -5,7 +5,7 @@ This version of PyFlakes_ has been improved to use Python's newer ``ast``
module, instead of ``compiler``. So code checking happens faster, and will stay
up to date with new language changes.
.. _PyFlakes: http://http://www.divmod.org/trac/wiki/DivmodPyflakes
.. _PyFlakes: http://www.divmod.org/trac/wiki/DivmodPyflakes
TODO
----