From 099eb5c4209c7db737e3cf76b616fea98ca78a3e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 00:11:05 -0400 Subject: autoload/auditory.vim: Move `d` mappings to `s:mappings` Put our `d`, `v_d`, and `dd` mappings in the `s:mappings` dictionary so that they get automatically activated and deactivated when our map and unmap functions go through the dict. This required some modifications to `auditory#AssignMappings()` to allow it to accept `map_to` commands that don't have a preceding `auditory#Play()` call (because in the case of our `d` mappings, the audio is played inside the function they call. Also ensure we're not adding a pipe to the command if there's no preceding audio part. --- autoload/auditory.vim | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index b89daf8..3e09a90 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -174,9 +174,6 @@ endfunction " Operators " ========= -nnoremap d :set opfunc=Deleteg@ -nnoremap dd :set opfunc=DeleteLineg@$ -vnoremap d :call Delete(visualmode(), 1) function! s:Delete(type, ...) let sel_save = &selection @@ -404,6 +401,23 @@ let s:mappings['v_x'] = { \ 'map_from': 'x', \ 'count': 1, \ } + +let s:mappings['d'] = { + \ 'map_to': ':set opfunc=Deleteg@', + \ 'silence': 1, +\ } +let s:mappings['v_d'] = { + \ 'map_from': 'd', + \ 'map_to': ':call Delete(visualmode(), 1)', + \ 'map_command': 'vnoremap', + \ 'silence': 1, +\ } + +let s:mappings['dd'] = { + \ 'map_to': ':set opfunc=DeleteLineg@$', + \ 'silence': 1, +\ } + " nnoremap d :call auditory#Play('/Resources/Normal_Mode/Delete.wav') \| exec 'normal!' v:count1 . 'd' " nnoremap d :set opfunc=d \| call auditory#Play('/Resources/Normal_Mode/Delete.wav') \| exec 'normal!' v:count1 . @g @@ -430,6 +444,12 @@ function! auditory#AssignMappings() " If `map_from` is specified, we can't rely on `key` to provide it let l:map_from = has_key(value, 'map_from') ? value.map_from : key + if has_key(value, 'audio') + let l:audio = ':call auditory#Play("' . value.audio . '")' + else + let l:audio = '' + endif + " Map to key unless a `map_to` or user mapping is defined if has_key(value, 'map_to') let l:map_to = value.map_to @@ -447,7 +467,11 @@ function! auditory#AssignMappings() " If this an `execute` mapping, add a pipe. " Otherwise to exit command mode. - let l:pipe = match(l:map_to_with_count , 'exec') !=# -1 ? ' \| ' : '' + if l:audio !=# '' + let l:pipe = match(l:map_to_with_count , 'exec') !=# -1 ? ' \| ' : '' + else + let l:pipe = '' + endif " Default to unless the mapping explicitly calls for a value let l:silence = '' @@ -456,7 +480,8 @@ function! auditory#AssignMappings() endif execute l:cmd . ' ' . l:silence . ' ' . l:map_from . - \ ' :call auditory#Play("' . value.audio . '")' . + \ ' ' . + \ l:audio . \ l:pipe . \ l:map_to_with_count endfor -- cgit v1.2.3