unite-source で soruce 独自の値を初期化する
ちょっと前に教えてもらったので覚書。
unite-source で独自の値を保持する場合、hooks.init で context に対して値を代入すれば初期化する事が出来ます。
[unite-source]
let s:RAND_MAX = 32767 let s:seed = 4239 function! s:rand() let s:seed = s:seed * 214013 + 2531011 return (s:seed < 0 ? s:seed - 0x80000000 : s:seed) / 0x10000 % 0x8000 endfunction " 起動時に乱数で初期化して表示するだけの unite-source let s:source = { \ "name" : "random", \} let s:source.hooks = {} function! s:source.hooks.on_init(args, context) let s:seed = localtime() let a:context.source__random_values = map(range(10), "s:rand()") endfunction function! s:source.gather_candidates(args, context) return map(a:context.source__random_values, '{ "word" : v:val }') endfunction call unite#define_source(s:source) unlet s:source