unite.vim で vim-pukiwiki の検索をする その 3

  1. unite.vim で vim-pukiwiki の検索をする その 1 - vim 初心者の作業メモ
  2. unite.vim で vim-pukiwiki の検索をする その 2 - vim 初心者の作業メモ
  3. unite.vim で vim-pukiwiki の検索をする その 3 - vim 初心者の作業メモ
  4. 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
>

  • echo -- echo candidates for debug
  • edit -- edit source args
  • ex -- insert candidates into command line
  • insert -- insert word or text
  • insert_directory -- insert directory
  • preview -- preview word
  • start -- start source
  • yank -- yank word or text
  • yank_escape -- yank escaped word or text
  • デフォルトの action は start に設定されている.
  • 他は kind=common で設定されたものかな?

ソースを読む

ソースは 55 行でとても短い.

let s:save_cpo = &cpo
set cpo&vim
function! unite#sources#source#define()"{{{
  return s:source
endfunction"}}}
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?
  • "buffer" , "file_mru" and "virw/git" are valid.
https://github.com/Shougo/unite.vim/blob/bae05a9698702f8482a747611b68602dd71587ec/doc/unite.txt
  • 自分で中途半端にいっといてあれですが, "change directory" だと冠詞もないしだめな気がする.

An interface that can change directory.

https://github.com/Shougo/unite.vim/blob/bae05a9698702f8482a747611b68602dd71587ec/doc/unite.txt
    • change the working/current directory?