" 関数定義開始 function! Perldoc(pod) let pod = a:pod " もしpodがnullなら if !strlen(pod) " カーソル下にある、アルファベット、数字、コロンの組み合わせを " モジュール名として取得 setlocal iskeyword=a-z,A-Z,48-57,_,: let pod = expand('') setlocal iskeyword< endif " pod2vimを使ってマニュアルを取得 set shellredir:> let perldoc = system('pod2vim ' . shellescape(pod)) set shellredir& " 取得できなかったら if !strlen(perldoc) echohl ErrorMsg echo 'ドキュメントが見つかりません : ' . pod echohl None return endif " キャッシュディレクトリが設定されていなかったら if !strlen(g:Perldoc_path) echohl ErrorMsg echo '最初に g:Perldoc_path を設定してください' echohl None return endif " キャッシュファイル名を作成 let pod_name_with_hyphes = substitute(pod, '::', '-', 'g') let file_path = g:Perldoc_path . pod_name_with_hyphes let file_path = fnameescape(file_path) let file_as_list = split(perldoc, '\n') " キャッシュファイルに書き込み try call writefile(file_as_list, file_path) catch echohl ErrorMsg echo 'ファイルに書き込めませんでした : ' . file_path echohl None return endtry " 以前Perldocを表示したウィンドウを取得して let winnum = bufwinnr(g:__perldoc__) " 見つからなかったら新しく作成 if winnum == -1 execute 'vnew' else if winnr() != winnum exe winnum . 'wincmd w' endif endif " ウィンドウを画面の一番左に持って行き execute 'wincmd L' " サイズは横幅80桁に合わせる execute 'vertical resize 80' " 表示、及び各種設定 execute 'silent edit ' . file_path " 次表示するときのためにバッファ名を保存 let g:__perldoc__ = pod_name_with_hyphes endfunction let g:__perldoc__ = '__perldoc__' command! -nargs=? Perldoc :call Perldoc('')