diff options
Diffstat (limited to 'misc/vim/plugin/godoc.vim')
-rw-r--r-- | misc/vim/plugin/godoc.vim | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/misc/vim/plugin/godoc.vim b/misc/vim/plugin/godoc.vim index a7b84de74..a145d313f 100644 --- a/misc/vim/plugin/godoc.vim +++ b/misc/vim/plugin/godoc.vim @@ -3,6 +3,20 @@ " license that can be found in the LICENSE file. " " godoc.vim: Vim command to see godoc. +" +" +" Commands: +" +" :Godoc +" +" Open the relevant Godoc for either the word[s] passed to the command or +" the, by default, the word under the cursor. +" +" Options: +" +" g:go_godoc_commands [default=1] +" +" Flag to indicate whether to enable the commands listed above. if exists("g:loaded_godoc") finish @@ -12,6 +26,16 @@ let g:loaded_godoc = 1 let s:buf_nr = -1 let s:last_word = '' +if !exists('g:go_godoc_commands') + let g:go_godoc_commands = 1 +endif + +if g:go_godoc_commands + command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc(<f-args>) +endif + +nnoremap <silent> <Plug>(godoc-keyword) :<C-u>call <SID>Godoc('')<CR> + function! s:GodocView() if !bufexists(s:buf_nr) leftabove new @@ -42,6 +66,13 @@ function! s:GodocView() endfunction function! s:GodocWord(word) + if !executable('godoc') + echohl WarningMsg + echo "godoc command not found." + echo " install with: go get code.google.com/p/go.tools/cmd/godoc" + echohl None + return 0 + endif let word = a:word silent! let content = system('godoc ' . word) if v:shell_error || !len(content) @@ -49,12 +80,12 @@ function! s:GodocWord(word) silent! let content = system('godoc ' . s:last_word.'/'.word) if v:shell_error || !len(content) echo 'No documentation found for "' . word . '".' - return + return 0 endif let word = s:last_word.'/'.word else echo 'No documentation found for "' . word . '".' - return + return 0 endif endif let s:last_word = word @@ -65,34 +96,35 @@ function! s:GodocWord(word) silent! normal gg setlocal nomodifiable setfiletype godoc + return 1 endfunction function! s:Godoc(...) - let word = join(a:000, ' ') - if !len(word) + if !len(a:000) let oldiskeyword = &iskeyword setlocal iskeyword+=. let word = expand('<cword>') let &iskeyword = oldiskeyword + let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') + let words = split(word, '\.\ze[^./]\+$') + else + let words = a:000 endif - let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') - let words = split(word, '\.') if !len(words) return endif - call s:GodocWord(words[0]) - if len(words) > 1 - if search('^\%(const\|var\|type\|\s\+\) ' . words[1] . '\s\+=\s') - return - endif - if search('^func ' . words[1] . '(') - return + if s:GodocWord(words[0]) + if len(words) > 1 + if search('^\%(const\|var\|type\|\s\+\) ' . words[1] . '\s\+=\s') + return + endif + if search('^func ' . words[1] . '(') + silent! normal zt + return + endif + echo 'No documentation found for "' . words[1] . '".' endif - echo 'No documentation found for "' . word . '".' endif endfunction -command! -nargs=* -range -complete=customlist,go#complete#Package Godoc :call s:Godoc(<q-args>) -nnoremap <silent> <Plug>(godoc-keyword) :<C-u>call <SID>Godoc('')<CR> - " vim:ts=4:sw=4:et |