From 5aab2fb74706849d914b23166efb3fa251d96e67 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Jul 2015 00:03:23 -0400 Subject: autoload/auditory.vim: Restore user mappings when turning off In `auditory#Unmap()`, after unmapping Auditory maps, remap user-defined mappings. Say you redefined `j` -> `gj`. When turning Auditory off, we would previously just unmap `j`, resulting in `j` -> `j`. Now that we're restoring user mapppings, `j` once again gets mapped to `gj`. Also keep track of the mode that Auditory uses for its mappings when storing a user-defined mapping so that we're only saving and restoring them if they're defined in the mode used by Auditory. User mappings get saved in `auditory#AssignMappings()`, or the function that essentially turns on the plugin. Fix the `if` condition that checks `if l:user_mapping`. This gave me a lot of trouble because I needed to match it against emtpy string, instead of a boolean condition. Use the proper condition to get it actually working. --- autoload/auditory.vim | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index c590aad..1e5772b 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -442,6 +442,8 @@ let s:mappings[''] = { function! auditory#AssignMappings() for [key, value] in items(s:mappings) + call auditory#StoreUserMapping(key) + " If this an `execute` mapping, add a pipe. " Otherwise to exit command mode. let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' @@ -472,9 +474,11 @@ 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) + let l:map_mode = has_key(s:mappings[a:map_from], 'map_command') ? + \ s:mappings[a:map_from].map_command[0] : 'n' + let l:user_mapping = maparg(l:map_from, l:map_mode) - if l:user_mapping + if l:user_mapping !=# '' let s:mappings[a:map_from].user_mapping = l:user_mapping endif endif @@ -484,9 +488,14 @@ endfunction function! auditory#Unmap() for [key, value] in items(s:mappings) let l:cmd = has_key(value, 'map_command') ? value.map_command : 'nnoremap' + let l:user_mapping = get(value, 'user_mapping', '') if l:cmd ==# 'nnoremap' execute 'nunmap ' . key endif + + if l:user_mapping !=# '' + execute l:cmd . ' ' . get(value, 'map_from', key) . ' ' . value.user_mapping + endif endfor endfunction -- cgit v1.2.3