Permalink
Browse files

Fixes several issues

- Converts python_pydoc.vim to UTF-8
- Improves ftplugin behaviour:
	+ No redefine function when executed several times the plugin
	+ Global variables defined once on first time
- If the cursor is under a blank line, do not try to search for doc
- Set the __doc__ buffer as nomodifiable
- Allows searches in the __doc__ buffer with the correct syntax coloring
  using filetype=python and syntax=man
- Fixes highlighting and allow to highlight WORD
- Updates TODO with pending issues:
	+ Fix error when no doc is available, the error message is not shown, why?
	  (This is my fault, but I don't know how I broke it :-/)
	+ When first try is for a word/WORD that does not have doc, then the
	  syntax is not loaded correctly.
  • Loading branch information...
1 parent a43148d commit 303cb9359d043f8c2c896a183863517f2190e989 @jimenezrick jimenezrick committed Oct 26, 2011
Showing with 44 additions and 32 deletions.
  1. +3 −3 TODO
  2. +41 −29 ftplugin/python_pydoc.vim
View
@@ -1,3 +1,3 @@
-- Fix s:Highlight() function, does it work?
-- Fix when searching for some word/WORD inside the __doc__ buffer.
- Now it does nothing, it stays in the same module doc.
+- Fix error when no doc is available, the error message is not shown, why?
+- When first try is for a word/WORD that does not have doc, then the
+ syntax is not loaded correctly.
@@ -1,9 +1,9 @@
" Vim ftplugin file
" Language: Python
-" Authors: André Kelpe <efeshundertelf at googlemail dot com>
+" Authors: André Kelpe <efeshundertelf at googlemail dot com>
" Romain Chossart <romainchossat at gmail dot com>
" Matthias Vogelgesang
-" Ricardo Catalinas Jiménez <jimenezrick at gmail.com>
+" Ricardo Catalinas Jiménez <jimenezrick at gmail.com>
" Patches and suggestions from all sorts of fine people
"
" More info and updates at:
@@ -69,15 +69,35 @@ else
let b:did_ftplugin = 1
endif
+" Don't redefine the functions if this ftplugin has been executed previously
+" and before finish create the local mappings in the current buffer
+if exists('*s:ShowPyDoc') && g:pydoc_perform_mappings
+ call s:PerformMappings()
+ finish
+endif
+
+if !exists('g:pydoc_perform_mappings')
+ let g:pydoc_perform_mappings = 1
+endif
+
+if !exists('g:pydoc_highlight')
+ let g:pydoc_highlight = 1
+endif
+
+if !exists('g:pydoc_cmd')
+ let g:pydoc_cmd = 'pydoc'
+endif
+
+if !exists('g:pydoc_open_cmd')
+ let g:pydoc_open_cmd = 'split'
+endif
+
setlocal switchbuf=useopen
+highlight pydoc cterm=reverse gui=reverse
function s:ShowPyDoc(name, type)
- if !exists('g:pydoc_cmd')
- let g:pydoc_cmd = 'pydoc'
- endif
-
- if !exists('g:pydoc_open_cmd')
- let g:pydoc_open_cmd = 'split'
+ if a:name == ''
+ return
endif
if g:pydoc_open_cmd == 'split'
@@ -94,19 +114,21 @@ function s:ShowPyDoc(name, type)
" The current buffer is __doc__, so do not
" recreate nor resize it
let l:pydoc_wh = -1
+ setlocal modifiable
else
if bufnr("__doc__") > 0
" If the __doc__ buffer is open in the
" current window, jump to it
execute "sbuffer" bufnr("__doc__")
let l:pydoc_wh = -1
+ setlocal modifiable
else
execute g:pydoc_open_cmd '__doc__'
setlocal noswapfile
setlocal buftype=nofile
- setlocal bufhidden=wipe
- setlocal modifiable
- setlocal filetype=man
+ setlocal bufhidden=delete
+ setlocal filetype=python
+ setlocal syntax=man
call s:PerformMappings()
endif
endif
@@ -121,40 +143,33 @@ function s:ShowPyDoc(name, type)
else
execute "silent read !" g:pydoc_cmd "-k" s:name2
endif
- setlocal nomodified
normal 1G
if exists('l:pydoc_wh') && l:pydoc_wh != -1
execute "silent resize" l:pydoc_wh
end
- if !exists('g:pydoc_highlight')
- let g:pydoc_highlight = 1
- endif
if g:pydoc_highlight == 1
- call s:Highlight(s:name2)
+ execute 'syntax match pydoc' "'" . s:name2 . "'"
endif
let l:line = getline(2)
if l:line =~ "^no Python documentation found for.*$"
if l:buf_is_new
- execute "bd!"
+ execute "bdelete!"
else
normal u
+ setlocal nomodified
+ setlocal nomodifiable
endif
redraw
echohl WarningMsg | echo l:line | echohl None
+ else
+ setlocal nomodified
+ setlocal nomodifiable
endif
endfunction
-" Highlighting
-function s:Highlight(name)
- execute "sb __doc__"
- setlocal filetype=man
- execute 'syntax keyword pydoc' a:name
- hi pydoc gui=reverse
-endfunction
-
" Mappings
function s:PerformMappings()
nnoremap <silent> <buffer> <Leader>pw :silent call <SID>ShowPyDoc('<C-R><C-W>', 1)<CR>
@@ -166,10 +181,7 @@ function s:PerformMappings()
nnoremap <silent> <buffer> K :silent call <SID>ShowPyDoc(expand("<cword>"), 1)<CR>
endfunction
-if !exists('g:pydoc_perform_mappings')
- let g:pydoc_perform_mappings = 1
-endif
-if g:pydoc_perform_mappings != 0
+if g:pydoc_perform_mappings
call s:PerformMappings()
endif

0 comments on commit 303cb93

Please sign in to comment.