はじめに
発端はこの会話.
@koturn deinでNeoBundleListに相当する関数ってわかりますか?
— ちゃっく (@chakku_000) 2016年8月21日
この質問を受け,dein.vimにおいて, :NeoBundleList
に相当する関数を探したが,直接的に該当するものはなかった.
しかし,dein.vimの関数を組み合わせることで実現できそうだったので,実装を試みた.
実装方針
:NeoBundleList
では,管理している全プラグインがそれぞれ
- インストールされているかどうか
- sourceされている(
runtimepath
に追加されている)かどうか
を echomsg
で表示する.
これを目指す.
dein#get()
を引数を与えずに呼び出すことで,管理プラグインの辞書を得ることができる.
この辞書から必要な情報を抜き出すとよい.
インストールされているかどうか
dein.vimが想定するインストール先のパスを確認するとよい. イメージとしては以下の通り.
for pair in items(dein#get()) echomsg pair[0] 'is' (isdirectory(pair[1].path) ? 'installed' : 'not installed') endfor
sourceされているかどうか
それぞれのプラグインの辞書に sourced
というキーがあるので,それを利用する.
イメージとしては以下の通り.
for pair in items(dein#get()) echomsg pair[0] 'is' (pair[1].sourced ? 'sourced' : 'not sourced') endfor
実装
以上のことをまとめ,以下のコードにするとよい.
ついでに, DeinList
というコマンドを定義しておく.
function! s:dein_list() abort echomsg '[dein] #: not sourced, X: not installed' for pair in items(dein#get()) echomsg (!isdirectory(pair[1].path) ? 'X' \ : pair[1].sourced ? ' ' \ : '#') pair[0] endfor endfunction command! DeinList call s:dein_list()
ちなみに,空引数の dein#get()
は dein#_plugins
の浅いコピーを返却するだけなので,以下のようにした方が無駄がない.
function! s:dein_list() abort echomsg '[dein] #: not sourced, X: not installed' for pair in items(dein#_plugins) echomsg (!isdirectory(pair[1].path) ? 'X' \ : pair[1].sourced ? ' ' \ : '#') pair[0] endfor endfunction command! DeinList call s:dein_list()
ただ,privateを意図したような変数を直接いじるのは,やや気乗りしないものがある.
まとめ
dein.vimの関数を組み合わせることで,:NeoBundleList
と同等のものを実現することができる.