Create function for creating a coord/key lookup dict

This commit is contained in:
Kim Silkebækken 2011-04-02 16:30:10 +02:00
parent 9e69b61e6a
commit e68d5b08cd

View File

@ -325,26 +325,33 @@
return groups return groups
endfunction endfunction
" }}} " }}}
" }}} " Coord/key dictionary creation {{{
" Core functions {{{ function! s:CreateCoordKeyDict(groups, ...)
" Create key index {{{ " Dict structure:
function! s:CreateIndex(chars) " {{{ " 1,2 : a
let index_to_key = {} " 2,3 : b
let key_to_index = {} let coord_keys = {}
let group_key = a:0 == 1 ? a:1 : ''
let idx = 0 for [key, item] in items(a:groups)
for char in split(a:chars, '\zs') let key = ( ! empty(group_key) ? group_key : key)
let index_to_key[idx] = char
let key_to_index[char] = idx
let idx += 1 if type(item) == 3
" Destination coords
let coord_keys[join(item, ',')] = key
else
" Item is a dict (has children)
call extend(coord_keys, s:CreateCoordKeyDict(item, key))
endif
unlet item
endfor endfor
return [index_to_key, key_to_index] return coord_keys
endfunction "}}} endfunction
let [s:index_to_key, s:key_to_index] = s:CreateIndex(g:EasyMotion_keys)
" }}} " }}}
" }}}
" Core functions {{{
function! s:PromptUser(groups) "{{{ function! s:PromptUser(groups) "{{{
let single_group = len(a:groups) == 1 let single_group = len(a:groups) == 1
let targets_len = single_group ? len(a:groups[0]) : len(a:groups) let targets_len = single_group ? len(a:groups[0]) : len(a:groups)