Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created March 8, 2013 09:39
Show Gist options
  • Save mmisono/5115325 to your computer and use it in GitHub Desktop.
Save mmisono/5115325 to your computer and use it in GitHub Desktop.
function! s:SID()
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
endfunction
let s:SID_PREFIX = s:SID()
delfunc s:SID
function! s:convertLocalFunc(funcname)
return printf('<SNR>%d_%s', s:SID_PREFIX, a:funcname)
endfunction
let s:unite_rotate_hue_source = {
\ 'name': 'rotate_hue',
\ 'hooks': {},
\ 'action_table': {'*': {}},
\}
function! s:unite_rotate_hue_source.hooks.on_init(args,context)
let s:hue_rotation_current_degree = 0
endfunction
let s:unite_rotate_hue_source.action_table['*'].preview = {
\ 'description': 'preview this hue rotated color',
\ 'is_quit': 0,
\}
function! s:unite_rotate_hue_source.action_table['*'].preview.func(candidate)
execute a:candidate.action__command
endfunction
function! s:unite_rotate_hue_source.gather_candidates(args, context)
if len(a:args) >= 1
let stride = a:args[0]
else
let stride = 20
endif
let strides = range(0,360,stride)
if (360 % stride) != 0
let strides += [360]
endif
let rotate_hue = s:convertLocalFunc("rotate_hue")
return map(strides, '{
\ "word": v:val,
\ "source": "rotate_hue",
\ "kind": ["command"],
\ "action__command": "call ".rotate_hue."(".v:val.")",
\ "action__type": ": ",
\ }')
endfunction
function! s:rotate_hue(degree)
call RotateHue(a:degree - s:hue_rotation_current_degree)
let s:hue_rotation_current_degree = a:degree
endfunction
call unite#define_source(s:unite_rotate_hue_source)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment