aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-07-28 00:03:23 -0400
committerTeddy Wing2015-07-28 00:03:23 -0400
commit5aab2fb74706849d914b23166efb3fa251d96e67 (patch)
tree938467968ed10d3e3d53121ed97d77008768d9c3
parentdb37f84e67f2e20a33348453f6c1d351741f2f1e (diff)
downloadauditory.vim-5aab2fb74706849d914b23166efb3fa251d96e67.tar.bz2
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.
-rw-r--r--autoload/auditory.vim13
1 files 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['<c-r>'] = {
function! auditory#AssignMappings()
for [key, value] in items(s:mappings)
+ call auditory#StoreUserMapping(key)
+
" If this an `execute` mapping, add a pipe.
" Otherwise <cr> to exit command mode.
let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '<cr>'
@@ -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