unite.vim で vim-pukiwiki の検索をする その 1
- unite.vim で vim-pukiwiki の検索をする その 1 - vim 初心者の作業メモ
- unite.vim で vim-pukiwiki の検索をする その 2 - vim 初心者の作業メモ
- unite.vim で vim-pukiwiki の検索をする その 3 - vim 初心者の作業メモ
unite.vim | の vim-pukiwiki 用の source を作ろうというお話. |
正直なところ, いまだに unite のすごさを感じられていなかったりするのですが.
今までのインタフェースを「破壊」し、新たなインタフェースの元にすべてを「統一」する
http://www.slideshare.net/Shougo/unite-vim
兎にも角にも, vim-pukiwiki における「検索」を unite.vim 経由にする.
pukiwiki でそのような操作が必要となるのはいくつか存在する.
- 単語検索機能による一覧
- 最新の更新ページ一覧
- ページ一覧
とりあえず, 私が一番使うのは「最新更新」なのでこれの source を作る.
unite.vim の source を作る
unite.vim の source はたくさんつくられているし, その情報もたくさん公開されている.
- unite.vim/unite.txt at master · Shougo/unite.vim · GitHub
- http://vim-users.jp/2011/01/hack197/
- 簡単な unite の source の作り方 - 永遠に未完成
- vim 本: Vimテクニックバイブル ―作業効率をカイゼンする150の技
vim 力ないから何が書いてあるのかさっぱりだ...
unite.vim の source の作り方を理解する
unite.vim の source は適当に作ってそれを"登録"する必要がある.
- 1 つ目の方法は .vimrc にでも書けばいいので初歩としては楽なのだと思われる.
- 2 つ目の方法は, plugin 作成者なんかがそれ専用の source を作るならこっちをとるのかな.
1つ目の方法は unite#define_source を使用する方法です。
http://vim-users.jp/2011/01/hack197/
(略)
2つ目の方法は autoload/unite/sources/ に配置する方法です。
source を定義するオブジェクト (Dictionary) を作る. |unite-source-attributes| 参考.
現状これだけあるらしい. name と gather_candidates のみ必須.
name String (Required) gather_candidates Function (Required) change_candidates Function (Optional) async_gather_candidates Function (Optional) complete Function (Optional) hooks Dictionary (Optional) action_table Dictionary (Optional) default_action Dictionary (Optional) default_kind String (Optional) alias_table Dictionary (Optional) max_candidates Number (Optional) required_pattern_length Number (Optional) is_volatile Number (Optional) is_listed Number (Optional) description String (Optional) syntax String (Optional) filters List (Optional) source__ Unknown (Optional)https://github.com/Shougo/unite.vim/blob/master/doc/unite.txt
name
とりあえず名前を付ける.
let s:unite_source = {} let s:unite_source.name = "source 名"
gather_candidates
gather_candidates は候補のリストを返す関数を定義する.
- args: Unite コマンド実行時の引数の List
Examples: "file:foo:bar": the parameters of source file are ["foo", "bar"]. "file:foo\:bar": the parameter of source file is ["foo:bar"]. "file:foo::baz": the parameters of source file are ["foo", "", "bar"].https://github.com/Shougo/unite.vim/blob/master/doc/unite.txt
- context: souce が呼び出されたときの context information. Dictionary.
{ 'is_changed' : 0, 'start_insert' : 0, 'short_source_names' : 0, 'is_invalidate' : 1, 'no_cursor_line' : 0, 'col' : 1, 'no_buffer' : 0, 'no_focus' : 0, 'temporary' : 0, 'script' : 0, 'auto_preview' : 0, 'verbose' : 0, 'is_list_input' : 0, 'no_quit' : 0, 'hide_source_names' : 0, 'unite__is_interactive' : 1, 'complete' : 0, 'direction' : 'topleft', 'unite__old_winwidth' : 0, 'keep_focus' : 0, 'multi_line' : 0, 'unite__disable_hooks' : 0, 'quick_match' : 0, 'toggle' : 0, 'default_action' : 'default', 'input_list' : [], 'auto_resize' : 0, 'unite__max_candidates' : 0, 'is_redraw' : 0, 'create' : 0, 'max_multi_lines' : 5, 'winwidth' : 90, 'no_empty' : 0, 'update_time' : 500, 'unite__is_complete' : 0, 'prompt' : '> ', ... 略
gather_candidates の復帰値は選択肢となる候補.
要素は一つずつが Dictionary で定義される.
詳細は |unite-notation-{candidate}| 参照.
- word には (Required) とかかれていないが必須オプションかな?
- kind と action あたりは指定しないとなんともならない気がする.
word | (String) | ???? | abbr | (String) | (Optional) | $word source | (String) | (Optional) | kind | (String/List) | (Optional) | common is_dummy | (Number) | (Optional) | 0 is_matched | (Number) | (Optional) | is_multiline | (Number) | (Optional) | 0 source__{name} | (Unknown) | (Optional) | action__{name} | (Unknown) | (Optional) |
kind
少し疲れてきました.
unite-kinds | 参照. 候補となるものの種類を指定する. |
file だとか directory だとか.
common A kind for common actions. openable An interface that can open. cdable An interface that can cd. file An interface for files. buffer An interface for buffers. tab An interface for tabs. directory An interface for directories. word A String that can be inserted jump_list An interface for jump lists. command An interface for Ex commands of Vim window An interface for Windows of Vim completion An interface for completion source unite.vim source uri Files and protocols guicmd GUI executable commandshttps://github.com/Shougo/unite.vim/blob/master/doc/unite.txt
- 多分関係あるのは command かな.
"簡単な unite の source" を理解する
- 登録方法の 1 つ目の方法を紹介している.
- source 名は lines. ":Unite lines" で実行できる
function! s:unite_source.gather_candidates(args, context) " 裏バッファ '#' のファイル名 let path = expand('#:p') " 裏バッファ '#' の 1行目から最終行までの内容を取得する " lines は各行の文字列のリスト let lines = getbufline('#', 1, '$') " unite で表示させる文字列の生成 " strlen(len(lines)) は桁数をカウントしているだけで, " "%d: %s" 形式で内容を出力している. let format = '%' . strlen(len(lines)) . 'd: %s' " map は無視すると, return map(lines, '{ " word には "%d: %s" の内容 " v:key は map を利用するときに使える, リストのインデックス. " 行番号は 1 から始まり, リストのインデックスは 0 から始まるので 1 足して調整 " v:val はリストの内容 " @see [http://d.hatena.ne.jp/osyo-manga/20121108/1352302694:title] \ "word": printf(format, v:key + 1, v:val), " 名前. 設定する必要があるのかな. " help には 「Note: This attribute is set automatically.」とある \ "source": "lines", " jump list が何かわからないのに.... ヘルプではこの一ヶ所しかでてこない " 「An interface for jump lists.」 " jump list は vim 用語なのか? " まぁきっと移動することなんでしょう. " kind=jump_list のとき action__path と action__line は必須. \ "kind": "jump_list", " 行先のファイル名か. \ "action__path": path, " 行先の行番号か. \ "action__line": v:key + 1, \ }')
動かしてみる
ソースを ~/.vimrc にコピーして, ":source ~/.vimrc" して ":Unite lines" ....?????
何も表示されない.
printf デバッグすると, 関数がコールされているので動作はしているようだけど何かがおかしいらしい, が何かわからなかった.
- ちょっと聞いてみたログ http://lingr.com/room/vim/archives/2012/11/17
- 複数のウィンドウを開いた状態で実行すると動作した.
- [2012/11/19 追記]
Shougo
これ、本当はon_init()でバッファを取って来るべき
簡単化のために手抜きをしているので動作がおかしいのでしょうthinca
http://lingr.com/room/vim/archives/2012/11/17
>簡単化のために手抜きをしているので
違う。当時はそもそも on_init がなかった。
気づいたこと
- unite.vim のヘルプ, KIND のところピリオドがちょくちょくぬける.
- vim 力がないせいなのか, ヘルプが読めていないのか, unite に関する知識がないからかわからないけど, 用語がわからない
- "jump lists"
- "An interface that can cd."?? cd って動詞?
- change directory の略?
- |unite-notation-{candidate}| word には (Required) とかかれていないが必須オプション?
- [2012/11/19 追記] 11/18 に修正していただきました. はやい.
Github
http://lingr.com/room/vim/archives/2012/11/18
[unite.vim/master] - Fixed documentation. - Shougo Matsushita : https://github.com/Shougo/unite.vim/compare/c7047aba1a39...7b40c9ce1060
Shougo
指摘されていた不備を修正しました