unite.vim で vim-pukiwiki の検索をする その 3
- unite.vim で vim-pukiwiki の検索をする その 1 - vim 初心者の作業メモ
- unite.vim で vim-pukiwiki の検索をする その 2 - vim 初心者の作業メモ
- unite.vim で vim-pukiwiki の検索をする その 3 - vim 初心者の作業メモ
- unite.vim で vim-pukiwiki の検索をする その 4 - vim 初心者の作業メモ
unite.vim 標準の source 'source' を理解する
動作を理解する.
source
Nominates Unite source names themselves as candidates.Runs |unite#start()| with the selected source name, using the
current Unite buffer context.
":Unite source" すると以下の一覧がでた
Sources: source (53/53) > - alignta -- candidates from alignta's preset arguments - bookmark -- candidates from bookmark list - buffer -- candidates from buffer list - buffer_tab -- candidates from buffer list in current tab - change -- candidates from changes - command -- candidates from Ex command - directory -- candidates from directory list - directory/new -- directory candidates from input - directory_mru -- candidates from directory MRU list ... (略)
- 使用できる source の一覧.
":Unite source" 後にbufer を選択して TAB を押す.
Sources: action (9/9)
[action] candidates: buffer -- candidates from buffer list(source)
[action] default_action: start
>
- デフォルトの action は start に設定されている.
- 他は kind=common で設定されたものかな?
ソースを読む
ソースは 55 行でとても短い.
let s:save_cpo = &cpo set cpo&vim
- cpo = cpoptions のバックアップ
- なぜこれが必要か?
- http://vim-users.jp/2010/10/hack179/
function! unite#sources#source#define()"{{{ return s:source endfunction"}}}
- s:source を登録
- 2 つ目の方法: http://vim-users.jp/2011/01/hack197/
let s:source = { \ 'name' : 'source', \ 'description' : 'candidates from sources list', \ 'default_action' : 'start', \ 'default_kind' : 'source', \}
- source 名 'source'
- デフォルトの action は 'start' に設定
- デフォルトの kind を 'source' にする
function! s:source.gather_candidates(args, context)"{{{ return map(copy(unite#util#sort_by(filter( \ values(unite#get_all_sources()), 'v:val.is_listed'), 'v:val.name')), "{ \ 'word' : v:val.name, \ 'abbr' : unite#util#truncate(v:val.name, 25) . \ (v:val.description != '' ? ' -- ' . v:val.description : ''), \ 'action__source_name' : v:val.name, \ 'action__source_args' : [], \}") endfunction"}}}
- unite#get_all_sources() で source の一覧がでくるのでしょう.
:echo len(unite#get_all_sources())
とすると, 62 になる. ":Unite source" ででてきたのは 53 だったので 9 つは削除されている.
- |values({dict})| は Dictionary の値のみを返す.
- |filter({expr}, {string})| はリストか辞書の {expr} を受け取って, {string} を評価して真の場合に値を返す.
let &cpo = s:save_cpo unlet s:save_cpo
- 保存しておいた cpo をリストア
- 多分, kind=source が unite.vim として準備されているのであまりやることがない. のでお勉強にはあまり良くなかった気がする.
- unite.vim の kind を定義している部分を読めばいいのでしょうけど.
- cpo はなんで保存するのかな.
- これ, view/git の typo?
https://github.com/Shougo/unite.vim/blob/bae05a9698702f8482a747611b68602dd71587ec/doc/unite.txt
- "buffer" , "file_mru" and "virw/git" are valid.
- 自分で中途半端にいっといてあれですが, "change directory" だと冠詞もないしだめな気がする.
An interface that can change directory.
https://github.com/Shougo/unite.vim/blob/bae05a9698702f8482a747611b68602dd71587ec/doc/unite.txt
-
- change the working/current directory?