From 8dc2441f00eff079dc7a62147f84ec40ad73c75d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 19 Jul 2015 12:43:40 -0400 Subject: auditory#StoreUserMapping: Operate on a single mapping Refactor to operate on one mapping passed in as an argument instead of the whole `s:mappings` dictionary. This will allow me to call the function inside `auditory#AssignMappings` and avoid having 2 `for` loops when 1 will suffice. --- autoload/auditory.vim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 0476631..4bfac77 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -468,13 +468,14 @@ endfunction " If users have a custom mapping for any of the commands we need, store the " mapping so we can map to it after playing audio and so we can restore the " user's mappings when the plugin is toggled off. -function! auditory#StoreUserMappings() - for [key, value] in items(s:mappings) - let l:map_from = has_key(value, 'map_from') ? value.map_from : key +function! auditory#StoreUserMapping(map_from) + if !has_key(s:mappings[a:map_from], 'user_mapping') + let l:map_from = has_key(s:mappings[a:map_from], 'map_from') ? + \ s:mappings[a:map_from].map_from : a:map_from let l:user_mapping = maparg(l:map_from) if l:user_mapping - let value.user_mapping = l:user_mapping + let s:mappings[a:map_from].user_mapping = l:user_mapping endif - endfor + endif endfunction -- cgit v1.2.3