Skip to content

Commit

Permalink
- Added gendoc command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Dec 23, 2010
1 parent d50719e commit 60058b9
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 10 deletions.
12 changes: 9 additions & 3 deletions autoload/vimshell.vim
Expand Up @@ -744,9 +744,15 @@ function! s:init_internal_commands()"{{{

" Search autoload.
for list in split(globpath(&runtimepath, 'autoload/vimshell/commands/*.vim'), '\n')
let l:command = fnamemodify(list, ':t:r')
if !has_key(s:internal_commands, l:command)
let s:internal_commands[l:command] = call('vimshell#commands#'.l:command.'#define', [])
let l:command_name = fnamemodify(list, ':t:r')
if !has_key(s:internal_commands, l:command_name)
let l:command = {'vimshell#commands#'.l:command_name.'#define'}()

if !has_key(l:command, 'description')
let l:command.description = ''
endif

let s:internal_commands[l:command_name] = l:command
endif
endfor
endfunction"}}}
Expand Down
52 changes: 52 additions & 0 deletions autoload/vimshell/commands/gendoc.vim
@@ -0,0 +1,52 @@
"=============================================================================
" FILE: gendoc.vim
" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
" Last Modified: 23 Dec 2010.
" License: MIT license {{{
" Permission is hereby granted, free of charge, to any person obtaining
" a copy of this software and associated documentation files (the
" "Software"), to deal in the Software without restriction, including
" without limitation the rights to use, copy, modify, merge, publish,
" distribute, sublicense, and/or sell copies of the Software, and to
" permit persons to whom the Software is furnished to do so, subject to
" the following conditions:
"
" The above copyright notice and this permission notice shall be included
" in all copies or substantial portions of the Software.
"
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
" }}}
"=============================================================================

let s:command = {
\ 'name' : 'gendoc',
\ 'kind' : 'internal',
\ 'description' : 'gendoc {command} {args}',
\}
function! s:command.execute(command, args, fd, context)"{{{
" Generate cached doc.

if empty(a:args)
return
endif

" Get description.
let l:command_name = fnamemodify(a:args[0], ':t:r')
let l:output = split(vimproc#system(a:args).vimproc#get_last_errmsg(), '\n')
let l:description = empty(l:output) ? '' : l:output[0]

" Set cached doc.
let l:cached_doc = vimshell#help#get_cached_doc()
let l:cached_doc[l:command_name] = l:description
call vimshell#help#set_cached_doc(l:cached_doc)
endfunction"}}}

function! vimshell#commands#gendoc#define()
return s:command
endfunction
45 changes: 39 additions & 6 deletions autoload/vimshell/help.vim
Expand Up @@ -39,19 +39,32 @@ function! s:doc_dict.search(cur_text)"{{{
let l:command = fnamemodify(l:args[0], ':t:r')

let l:commands = vimshell#available_commands()
if l:command == '' || !has_key(l:commands, l:command)
\ || !has_key(l:commands[l:command], 'description')
if l:command == ''
return []
elseif !has_key(l:commands, l:command)
if !has_key(s:cached_doc, l:command)
return []
endif

let l:description = s:cached_doc[l:command]
else
let l:description = l:commands[l:command].description
endif

if l:commands[l:command].description =~# l:command.'\s*'
if l:description =~? '^usage:\s*'
return [
\ { 'text' : l:command, 'highlight' : 'Identifier' },
\ { 'text' : l:commands[l:command].description[len(l:command) :] },
\ { 'text' : 'Usage: ', 'highlight' : 'Identifier' },
\ { 'text' : l:command, 'highlight' : 'Statement' },
\ { 'text' : ' ' . join(split(l:description)[2:]) },
\ ]
elseif l:description =~# l:command.'\s*'
return [
\ { 'text' : l:command, 'highlight' : 'Statement' },
\ { 'text' : l:description[len(l:command) :] },
\ ]
else
return [
\ { 'text' : l:commands[l:command].description },
\ { 'text' : l:description },
\ ]
endif
endfunction"}}}
Expand All @@ -61,6 +74,26 @@ function! vimshell#help#init()"{{{
if exists('g:loaded_echodoc') && g:loaded_echodoc
call echodoc#register('vimshell', s:doc_dict)
endif

call vimshell#help#recache()
endfunction"}}}
function! vimshell#help#recache()"{{{
let s:cached_doc = {}
let l:doc_path = g:vimshell_temporary_directory.'/cached-doc'
if !filereadable(l:doc_path)
call writefile([], l:doc_path)
endif
for args in map(readfile(l:doc_path), 'split(v:val, "!!!")')
let s:cached_doc[args[0]] = join(args[1:], '!!!')
endfor
endfunction"}}}
function! vimshell#help#get_cached_doc()"{{{
return s:cached_doc
endfunction"}}}
function! vimshell#help#set_cached_doc(cache)"{{{
let s:cached_doc = a:cache
let l:doc_path = g:vimshell_temporary_directory.'/cached-doc'
call writefile(values(map(deepcopy(s:cached_doc), 'v:key."!!!".v:val')), l:doc_path)
endfunction"}}}

" vim: foldmethod=marker
8 changes: 7 additions & 1 deletion doc/vimshell.jax
Expand Up @@ -582,7 +582,13 @@ gcd [{directory-path}] *vimshell-internal-gcd*
{directory-path}を省略すると、vimshellのカレントディレクトリ
に移動します。

gexe {command} *vimshell-internal-gexe*
gendoc {command} {args} *vimshell-internal-gexe*
{command}に引数{args}を与えて実行し、結果を
g:vimshell_temporary_directory/cached-docに格納する。キャッ
シュした説明文は|echodoc|により表示できる。説明文としてキャッ
シュされるのは、コマンドの実行結果の一行目だけである。

gexe {command} *vimshell-internal-gexe*
{command}に引数を与えて実行します。必ず外部コマンドが実行さ
れます。exeとは違い、GUIコマンドを実行することに特化していま
す。
Expand Down
1 change: 1 addition & 0 deletions doc/vimshell.txt
Expand Up @@ -186,6 +186,7 @@ CHANGELOG *vimshell-changelog*

2010-12-23
- Supported echodoc.
- Added gendoc command.

2010-12-14
- Implemented set winsize behavior.
Expand Down

0 comments on commit 60058b9

Please sign in to comment.