diff options
| author | Teddy Wing | 2015-08-16 00:11:05 -0400 |
|---|---|---|
| committer | Teddy Wing | 2015-08-16 00:11:05 -0400 |
| commit | 099eb5c4209c7db737e3cf76b616fea98ca78a3e (patch) | |
| tree | 68af3a8e142d2b0655a25ac13d045dc9f2e6a505 /autoload | |
| parent | e11e2c45ae3efa36233aa39132f3f8515334b32a (diff) | |
| download | auditory.vim-099eb5c4209c7db737e3cf76b616fea98ca78a3e.tar.bz2 | |
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.
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/auditory.vim | 35 |
1 files 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 <silent> d :set opfunc=<SID>Delete<CR>g@ -nnoremap <silent> dd :set opfunc=<SID>DeleteLine<CR>g@$ -vnoremap <silent> d :<C-U>call <SID>Delete(visualmode(), 1)<CR> 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=<SID>Delete<CR>g@', + \ 'silence': 1, +\ } +let s:mappings['v_d'] = { + \ 'map_from': 'd', + \ 'map_to': ':<C-U>call <SID>Delete(visualmode(), 1)<CR>', + \ 'map_command': 'vnoremap', + \ 'silence': 1, +\ } + +let s:mappings['dd'] = { + \ 'map_to': ':set opfunc=<SID>DeleteLine<CR>g@$', + \ 'silence': 1, +\ } + " nnoremap <silent> d :<c-u>call auditory#Play('/Resources/Normal_Mode/Delete.wav') \| exec 'normal!' v:count1 . 'd'<cr> " nnoremap <silent> d :<c-u>set opfunc=d \| call auditory#Play('/Resources/Normal_Mode/Delete.wav') \| exec 'normal!' v:count1 . @g<cr> @@ -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 = ':<c-u>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 <cr> to exit command mode. - let l:pipe = match(l:map_to_with_count , 'exec') !=# -1 ? ' \| ' : '<cr>' + if l:audio !=# '' + let l:pipe = match(l:map_to_with_count , 'exec') !=# -1 ? ' \| ' : '<cr>' + else + let l:pipe = '' + endif " Default to <silent> unless the mapping explicitly calls for a value let l:silence = '<silent>' @@ -456,7 +480,8 @@ function! auditory#AssignMappings() endif execute l:cmd . ' ' . l:silence . ' ' . l:map_from . - \ ' :<c-u>call auditory#Play("' . value.audio . '")' . + \ ' ' . + \ l:audio . \ l:pipe . \ l:map_to_with_count endfor |
