From 3fccfd9723b6af2c174cd073b3a0324a85611f11 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 20:06:26 -0400 Subject: autoload/auditory.vim: Make dictionary of mappings Create a dictionary with all our mappings. We'll use this to activate them programmatically. I think it might also be interesting to provide this as a configurable variable within the plugin so that users can change the built-in mappings if they so choose. Note that this doesn't currently work because you can't have comments in dictionary literals in Vimscript. Thanks to Raimondi on #vim for confirming that for me after I played around with this. Also thanks to bairui/dahu for his suggestion for emulating comments in dict literals: https://gist.github.com/dahu/18b48c70444d8078f7d7 " Barry Arthur, July 2015 " Kludge emulating comments in dict literals " :-0 surprised?! function! StripComments(comment_leader, dict) return filter(a:dict, 'v:key !~ "^" . escape(a:comment_leader, "\"")') endfunction let x = StripComments('REM', { \ 'a' : 1 \, 'REM This is a nasty workaround mimicking comments in dict literals' :-0 \, 'b' : 2 \, 'REM Duplicate keys are not tolerated within dict literals, hence the numbered comment keys' :-0 \, 'c' : 3 \, 'REM For the younger audience members, REM stands for "remark" and was the comment leader in BASIC' :-0 \, 'd' : 4 \}) --- autoload/auditory.vim | 239 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 1c27485..b0e8210 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -205,6 +205,245 @@ endfunction " Normal mode " =========== +let s:mappings = { + \ 'h': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'h'", + \ }, + \ 'j': { + \ 'audio': '/Resources/Normal_Mode/Down.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'j'", + \ }, + \ 'k': { + \ 'audio': '/Resources/Normal_Mode/Up.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'k'", + \ }, + \ 'l': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'l'", + \ }, + \ + \ 'gj': { + \ 'audio': '/Resources/Normal_Mode/Down.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'gj'", + \ }, + \ 'gk': { + \ 'audio': '/Resources/Normal_Mode/Up.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'gk'", + \ }, + \ + \ '': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . ''", + \ }, + \ + \ " FIXME: allow counts on the delete key + \ '': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "", + \ }, + \ + \ '0': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "0", + \ }, + \ '^': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . '^'", + \ }, + \ '_': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . '_'", + \ }, + \ '$': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . '$'", + \ }, + \ 'g_': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'g_'", + \ }, + \ '%': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "%", + \ }, + \ + \ 'b': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'b'", + \ }, + \ 'w': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'w'", + \ }, + \ 'e': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'e'", + \ }, + \ 'B': { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'B'", + \ }, + \ 'W': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'W'", + \ }, + \ 'E': { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'E'", + \ }, + \ + \ 'p': { + \ 'audio': '/Resources/Normal_Mode/Paste.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'p'", + \ }, + \ 'P': { + \ 'audio': '/Resources/Normal_Mode/Paste.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'P'", + \ }, + \ + \ '/': { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "/", + \ }, + \ 'n': { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "n", + \ }, + \ 'N': { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "N", + \ }, + \ '#': { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "#", + \ }, + \ '*': { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "*", + \ }, + \ + \ 'zt': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "zt", + \ }, + \ 'z.': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "z.", + \ }, + \ 'zz': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "zz", + \ }, + \ 'zb': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "zb", + \ }, + \ + \ " FIXME: Allow these scrolling commands to support counts. Was getting errors constructing them the other way + \ '': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", + \ }, + \ '': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", + \ }, + \ '': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", + \ }, + \ + \ " FIXME: need to press twice in order for it to work + \ '': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", + \ }, + \ + \ 'H': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "H", + \ }, + \ 'M': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "M", + \ }, + \ 'L': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "L", + \ }, + \ + \ '(': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . '('", + \ }, + \ ')': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . ')'", + \ }, + \ '{': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . '{'", + \ }, + \ '}': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . '}'", + \ }, + \ + \ '': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . ''", + \ }, + \ '': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . ''", + \ }, + \ + \ 'gg': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'gg'", + \ }, + \ 'G': { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count . 'G'", + \ }, + \ + \ 'x': { + \ 'audio': '/Resources/Normal_Mode/Delete.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'x'", + \ }, + \ 'x': { + \ 'audio': '/Resources/Normal_Mode/Delete.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'x'", + \ }, + \ " 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 + \ + \ " inoremap :call auditory#Play('/Resources/auto_complete.wav')a + \ " inoremap :call auditory#Play('/Resources/auto_complete.wav')a + \ + \ 'u': { + \ 'audio': '/Resources/Normal_Mode/Undo.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'u'", + \ }, + \ + \ " Note: redo doesn't currently support a count because the `v:count1` was giving me an error + \ '': { + \ 'audio': '/Resources/Normal_Mode/Redo.wav', + \ 'map_to': "", + \ }, +\ } + +function! auditory#AssignNormalModeMappings() + for [key, value] in items(s:mappings) + let l:pipe = '' + if match(value, 'exec') !=# -1 + let l:pipe = ' \| ' + endif + echom 'nmap ' . key . ' :call auditory#Play("' . value.audio . '")' . l:pipe . value.map_to + endfor +endfunction + function! auditory#NormalModeMappings() nnoremap h :call auditory#Play('/Resources/Normal_Mode/Left.wav') \| exec 'normal!' v:count1 . 'h' nnoremap j :call auditory#Play('/Resources/Normal_Mode/Down.wav') \| exec 'normal!' v:count1 . 'j' -- cgit v1.2.3 From 8903b72d2e1b325757d819d43debb825a999b176 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 20:28:51 -0400 Subject: autoload/auditory.vim: Change format of mapping dictionary Convert it from a dictionary literal to successive appends to the mapping dictionary to allow me to keep the various comments and FIXMEs. --- autoload/auditory.vim | 453 +++++++++++++++++++++++++------------------------- 1 file changed, 226 insertions(+), 227 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index b0e8210..2662d49 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -205,233 +205,232 @@ endfunction " Normal mode " =========== -let s:mappings = { - \ 'h': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'h'", - \ }, - \ 'j': { - \ 'audio': '/Resources/Normal_Mode/Down.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'j'", - \ }, - \ 'k': { - \ 'audio': '/Resources/Normal_Mode/Up.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'k'", - \ }, - \ 'l': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'l'", - \ }, - \ - \ 'gj': { - \ 'audio': '/Resources/Normal_Mode/Down.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'gj'", - \ }, - \ 'gk': { - \ 'audio': '/Resources/Normal_Mode/Up.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'gk'", - \ }, - \ - \ '': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . ''", - \ }, - \ - \ " FIXME: allow counts on the delete key - \ '': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "", - \ }, - \ - \ '0': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "0", - \ }, - \ '^': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . '^'", - \ }, - \ '_': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . '_'", - \ }, - \ '$': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . '$'", - \ }, - \ 'g_': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'g_'", - \ }, - \ '%': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "%", - \ }, - \ - \ 'b': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'b'", - \ }, - \ 'w': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'w'", - \ }, - \ 'e': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'e'", - \ }, - \ 'B': { - \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'B'", - \ }, - \ 'W': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'W'", - \ }, - \ 'E': { - \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'E'", - \ }, - \ - \ 'p': { - \ 'audio': '/Resources/Normal_Mode/Paste.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'p'", - \ }, - \ 'P': { - \ 'audio': '/Resources/Normal_Mode/Paste.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'P'", - \ }, - \ - \ '/': { - \ 'audio': '/Resources/Normal_Mode/Search.wav', - \ 'map_to': "/", - \ }, - \ 'n': { - \ 'audio': '/Resources/Normal_Mode/Search.wav', - \ 'map_to': "n", - \ }, - \ 'N': { - \ 'audio': '/Resources/Normal_Mode/Search.wav', - \ 'map_to': "N", - \ }, - \ '#': { - \ 'audio': '/Resources/Normal_Mode/Search.wav', - \ 'map_to': "#", - \ }, - \ '*': { - \ 'audio': '/Resources/Normal_Mode/Search.wav', - \ 'map_to': "*", - \ }, - \ - \ 'zt': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "zt", - \ }, - \ 'z.': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "z.", - \ }, - \ 'zz': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "zz", - \ }, - \ 'zb': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "zb", - \ }, - \ - \ " FIXME: Allow these scrolling commands to support counts. Was getting errors constructing them the other way - \ '': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", - \ }, - \ '': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", - \ }, - \ '': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", - \ }, - \ - \ " FIXME: need to press twice in order for it to work - \ '': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", - \ }, - \ - \ 'H': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "H", - \ }, - \ 'M': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "M", - \ }, - \ 'L': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "L", - \ }, - \ - \ '(': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . '('", - \ }, - \ ')': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . ')'", - \ }, - \ '{': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . '{'", - \ }, - \ '}': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . '}'", - \ }, - \ - \ '': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . ''", - \ }, - \ '': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . ''", - \ }, - \ - \ 'gg': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'gg'", - \ }, - \ 'G': { - \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count . 'G'", - \ }, - \ - \ 'x': { - \ 'audio': '/Resources/Normal_Mode/Delete.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'x'", - \ }, - \ 'x': { - \ 'audio': '/Resources/Normal_Mode/Delete.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'x'", - \ }, - \ " 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 - \ - \ " inoremap :call auditory#Play('/Resources/auto_complete.wav')a - \ " inoremap :call auditory#Play('/Resources/auto_complete.wav')a - \ - \ 'u': { - \ 'audio': '/Resources/Normal_Mode/Undo.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'u'", - \ }, - \ - \ " Note: redo doesn't currently support a count because the `v:count1` was giving me an error - \ '': { - \ 'audio': '/Resources/Normal_Mode/Redo.wav', - \ 'map_to': "", - \ }, +let s:mappings = {} +let s:mappings['h'] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'h'", +\ } +let s:mappings['j'] = { + \ 'audio': '/Resources/Normal_Mode/Down.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'j'", +\ } +let s:mappings['k'] = { + \ 'audio': '/Resources/Normal_Mode/Up.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'k'", +\ } +let s:mappings['l'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'l'", +\ } + +let s:mappings['gj'] = { + \ 'audio': '/Resources/Normal_Mode/Down.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'gj'", +\ } +let s:mappings['gk'] = { + \ 'audio': '/Resources/Normal_Mode/Up.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'gk'", +\ } + +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . ''", +\ } + +" FIXME: allow counts on the delete key +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "", +\ } + +let s:mappings['0'] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "0", +\ } +let s:mappings['^'] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . '^'", +\ } +let s:mappings['_'] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . '_'", +\ } +let s:mappings['$'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . '$'", +\ } +let s:mappings['g_'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'g_'", +\ } +let s:mappings['%'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "%", +\ } + +let s:mappings['b'] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'b'", +\ } +let s:mappings['w'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'w'", +\ } +let s:mappings['e'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'e'", +\ } +let s:mappings['B'] = { + \ 'audio': '/Resources/Normal_Mode/Left.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'B'", +\ } +let s:mappings['W'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'W'", +\ } +let s:mappings['E'] = { + \ 'audio': '/Resources/Normal_Mode/Right.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'E'", +\ } + +let s:mappings['p'] = { + \ 'audio': '/Resources/Normal_Mode/Paste.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'p'", +\ } +let s:mappings['P'] = { + \ 'audio': '/Resources/Normal_Mode/Paste.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'P'", +\ } + +let s:mappings['/'] = { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "/", +\ } +let s:mappings['n'] = { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "n", +\ } +let s:mappings['N'] = { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "N", +\ } +let s:mappings['#'] = { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "#", +\ } +let s:mappings['*'] = { + \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'map_to': "*", +\ } + +let s:mappings['zt'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "zt", +\ } +let s:mappings['z.'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "z.", +\ } +let s:mappings['zz'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "zz", +\ } +let s:mappings['zb'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "zb", +\ } + +" FIXME: Allow these scrolling commands to support counts. Was getting errors constructing them the other way +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", +\ } +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", +\ } +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", +\ } + +" FIXME: need to press twice in order for it to work +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "", +\ } + +let s:mappings['H'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "H", +\ } +let s:mappings['M'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "M", +\ } +let s:mappings['L'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "L", +\ } + +let s:mappings['('] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . '('", +\ } +let s:mappings[')'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . ')'", +\ } +let s:mappings['{'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . '{'", +\ } +let s:mappings['}'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . '}'", +\ } + +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . ''", +\ } +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . ''", +\ } + +let s:mappings['gg'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'gg'", +\ } +let s:mappings['G'] = { + \ 'audio': '/Resources/Normal_Mode/Jump.wav', + \ 'map_to': "exec 'normal!' v:count . 'G'", +\ } + +let s:mappings['x'] = { + \ 'audio': '/Resources/Normal_Mode/Delete.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'x'", +\ } +" let s:mappings['x'] = { +" \ 'audio': '/Resources/Normal_Mode/Delete.wav', +" \ 'map_to': "exec 'normal!' v:count1 . 'x'", +" \ } +" 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 + +" inoremap :call auditory#Play('/Resources/auto_complete.wav')a +" inoremap :call auditory#Play('/Resources/auto_complete.wav')a + +let s:mappings['u'] = { + \ 'audio': '/Resources/Normal_Mode/Undo.wav', + \ 'map_to': "exec 'normal!' v:count1 . 'u'", +\ } + +" Note: redo doesn't currently support a count because the `v:count1` was giving me an error +let s:mappings[''] = { + \ 'audio': '/Resources/Normal_Mode/Redo.wav', + \ 'map_to': "", \ } function! auditory#AssignNormalModeMappings() -- cgit v1.2.3 From 4bc277b212b75a62b233e494a86f27de49c8ff5b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 20:30:33 -0400 Subject: auditory#AssignNormalModeMappings: Use ternary for pipe variable Assign the pipe variable with a ternary operator to make the function more concise. --- autoload/auditory.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 2662d49..a0a97ec 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -435,10 +435,9 @@ let s:mappings[''] = { function! auditory#AssignNormalModeMappings() for [key, value] in items(s:mappings) - let l:pipe = '' - if match(value, 'exec') !=# -1 - let l:pipe = ' \| ' - endif + " If this an `execute` mapping, add a pipe + let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' + echom 'nmap ' . key . ' :call auditory#Play("' . value.audio . '")' . l:pipe . value.map_to endfor endfunction -- cgit v1.2.3 From 9779b2cee0ab633cfdc7c71f3544aa9741957b7d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 21:01:03 -0400 Subject: auditory.vim: Assign mappings with AssignNormalModeMappings() Assign our normal mode mappings with our new function that uses the mapping dictionary. --- autoload/auditory.vim | 2 +- plugin/auditory.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index a0a97ec..2176a4c 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -438,7 +438,7 @@ function! auditory#AssignNormalModeMappings() " If this an `execute` mapping, add a pipe let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' - echom 'nmap ' . key . ' :call auditory#Play("' . value.audio . '")' . l:pipe . value.map_to + execute 'nmap ' . key . ' :call auditory#Play("' . value.audio . '")' . l:pipe . value.map_to endfor endfunction diff --git a/plugin/auditory.vim b/plugin/auditory.vim index 821c5ba..ba46fa2 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -20,4 +20,4 @@ augroup END command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() -call auditory#NormalModeMappings() +call auditory#AssignNormalModeMappings() -- cgit v1.2.3 From f87ae56b53f46654df2d0a6decdd5c12b2620f8b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 21:05:01 -0400 Subject: autoload/auditory.vim: Delete auditory#NormalModeMappings() Now that we're assigning our mappings using the mapping dictionary, we can remove the old function that applied the mappings manually. It definitely less clear an readable I'll admit, but this allows us more flexibility and hopefully customisability. The original plan with the mapping dictionary was to allow toggling of the mappings on and off, so hopefully it will help with that. --- autoload/auditory.vim | 79 --------------------------------------------------- 1 file changed, 79 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 2176a4c..000498c 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -441,82 +441,3 @@ function! auditory#AssignNormalModeMappings() execute 'nmap ' . key . ' :call auditory#Play("' . value.audio . '")' . l:pipe . value.map_to endfor endfunction - -function! auditory#NormalModeMappings() - nnoremap h :call auditory#Play('/Resources/Normal_Mode/Left.wav') \| exec 'normal!' v:count1 . 'h' - nnoremap j :call auditory#Play('/Resources/Normal_Mode/Down.wav') \| exec 'normal!' v:count1 . 'j' - nnoremap k :call auditory#Play('/Resources/Normal_Mode/Up.wav') \| exec 'normal!' v:count1 . 'k' - nnoremap l :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . 'l' - - nnoremap gj :call auditory#Play('/Resources/Normal_Mode/Down.wav') \| exec 'normal!' v:count1 . 'gj' - nnoremap gk :call auditory#Play('/Resources/Normal_Mode/Up.wav') \| exec 'normal!' v:count1 . 'gk' - - nnoremap :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . '' - - " FIXME: allow counts on the delete key - nnoremap :call auditory#Play('/Resources/Normal_Mode/Left.wav') - - nnoremap 0 :call auditory#Play('/Resources/Normal_Mode/Left.wav')0 - nnoremap ^ :call auditory#Play('/Resources/Normal_Mode/Left.wav') \| exec 'normal!' v:count1 . '^' - nnoremap _ :call auditory#Play('/Resources/Normal_Mode/Left.wav') \| exec 'normal!' v:count1 . '_' - nnoremap $ :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . '$' - nnoremap g_ :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . 'g_' - nnoremap % :call auditory#Play('/Resources/Normal_Mode/Jump.wav')% - - nnoremap b :call auditory#Play('/Resources/Normal_Mode/Left.wav') \| exec 'normal!' v:count1 . 'b' - nnoremap w :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . 'w' - nnoremap e :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . 'e' - nnoremap B :call auditory#Play('/Resources/Normal_Mode/Left.wav') \| exec 'normal!' v:count1 . 'B' - nnoremap W :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . 'W' - nnoremap E :call auditory#Play('/Resources/Normal_Mode/Right.wav') \| exec 'normal!' v:count1 . 'E' - - nnoremap p :call auditory#Play('/Resources/Normal_Mode/Paste.wav') \| exec 'normal!' v:count1 . 'p' - nnoremap P :call auditory#Play('/Resources/Normal_Mode/Paste.wav') \| exec 'normal!' v:count1 . 'P' - - nnoremap / :call auditory#Play('/Resources/Normal_Mode/Search.wav')/ - nnoremap n :call auditory#Play('/Resources/Normal_Mode/Search.wav')n - nnoremap N :call auditory#Play('/Resources/Normal_Mode/Search.wav')N - nnoremap # :call auditory#Play('/Resources/Normal_Mode/Search.wav')# - nnoremap * :call auditory#Play('/Resources/Normal_Mode/Search.wav')* - - nnoremap zt :call auditory#Play('/Resources/Normal_Mode/Jump.wav')zt - nnoremap z. :call auditory#Play('/Resources/Normal_Mode/Jump.wav')z. - nnoremap zz :call auditory#Play('/Resources/Normal_Mode/Jump.wav')zz - nnoremap zb :call auditory#Play('/Resources/Normal_Mode/Jump.wav')zb - - " FIXME: Allow these scrolling commands to support counts. Was getting errors constructing them the other way - nnoremap :call auditory#Play('/Resources/Normal_Mode/Jump.wav') - nnoremap :call auditory#Play('/Resources/Normal_Mode/Jump.wav') - nnoremap :call auditory#Play('/Resources/Normal_Mode/Jump.wav') - - " FIXME: need to press twice in order for it to work - nnoremap :call auditory#Play('/Resources/Normal_Mode/Jump.wav') - - nnoremap H :call auditory#Play('/Resources/Normal_Mode/Jump.wav')H - nnoremap M :call auditory#Play('/Resources/Normal_Mode/Jump.wav')M - nnoremap L :call auditory#Play('/Resources/Normal_Mode/Jump.wav')L - - nnoremap ( :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . '(' - nnoremap ) :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . ')' - nnoremap { :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . '{' - nnoremap } :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . '}' - - nnoremap :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . '' - nnoremap :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . '' - - nnoremap gg :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count1 . 'gg' - nnoremap G :call auditory#Play('/Resources/Normal_Mode/Jump.wav') \| exec 'normal!' v:count . 'G' - - nnoremap x :call auditory#Play('/Resources/Normal_Mode/Delete.wav') \| exec 'normal!' v:count1 . 'x' - vnoremap x :call auditory#Play('/Resources/Normal_Mode/Delete.wav') \| exec 'normal!' v:count1 . 'x' - " 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 - - " inoremap :call auditory#Play('/Resources/auto_complete.wav')a - " inoremap :call auditory#Play('/Resources/auto_complete.wav')a - - nnoremap u :call auditory#Play('/Resources/Normal_Mode/Undo.wav') \| exec 'normal!' v:count1 . 'u' - - " Note: redo doesn't currently support a count because the `v:count1` was giving me an error - nnoremap :call auditory#Play('/Resources/Normal_Mode/Redo.wav') -endfunction -- cgit v1.2.3 From 83449bf7e30d45f91eccbcdffd56abb126be56c1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 21:59:50 -0400 Subject: autoload/auditory.vim: Only map with `` if using `execute` We don't need to use `` in our mappings if we're going back to a regular non-command mode command, so listen for commands where we `execute` in the mapping and don't `` them. Reverted the ternary I had added previously to make this workable with the now 2 variables that need to listen for `execute`. Also add some line wrapping to the map creation for better readability. --- autoload/auditory.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 000498c..22a7cd1 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -435,9 +435,17 @@ let s:mappings[''] = { function! auditory#AssignNormalModeMappings() for [key, value] in items(s:mappings) - " If this an `execute` mapping, add a pipe - let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' + let l:pipe = '' + let l:silence = '' - execute 'nmap ' . key . ' :call auditory#Play("' . value.audio . '")' . l:pipe . value.map_to + " If this an `execute` mapping + if match(value.map_to, 'exec') !=# -1 + let l:pipe = ' \| ' + let l:silence = '' + endif + + execute 'nmap ' . l:silence . ' ' . key . + \ ' :call auditory#Play("' . value.audio . '")' . + \ l:pipe . value.map_to endfor endfunction -- cgit v1.2.3 From a3fcb8c8a3b7d05ef354aa250acef49d2c5a8fba Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 22:15:16 -0400 Subject: autoload/auditory.vim: Always map with Turns out my assumption that we didn't need when `execute`ing in 83449bf7e30d45f91eccbcdffd56abb126be56c1 was incorrect. When performing , the audio play command appears in the command line, which is not the behaviour we want. Let's just revert to always using `` and figure that should work for us. Figured out between the last commit and this one that my manual testing wasn't with the latest code. I was using a037e921a4b9b0539c93450fe3df1f6c8175ceab this whole time because I didn't have my development setup configured correctly. Now I can actually see what's going on as I make changes (what a concept!). Also bring back the ternary since we're not setting any more variables for this condition any more. --- autoload/auditory.vim | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 22a7cd1..596fefe 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -435,16 +435,10 @@ let s:mappings[''] = { function! auditory#AssignNormalModeMappings() for [key, value] in items(s:mappings) - let l:pipe = '' - let l:silence = '' + " If this an `execute` mapping, add a pipe + let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' - " If this an `execute` mapping - if match(value.map_to, 'exec') !=# -1 - let l:pipe = ' \| ' - let l:silence = '' - endif - - execute 'nmap ' . l:silence . ' ' . key . + execute 'nmap ' . key . \ ' :call auditory#Play("' . value.audio . '")' . \ l:pipe . value.map_to endfor -- cgit v1.2.3 From b262ac5ba505c6ee27ad3dcf0db8b868f52a100b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 22:26:29 -0400 Subject: autoload/autoload.vim: Use `nnoremap` instead of `nmap` I wanted to use `nmap` so that user-defined commands would come through, but that caused the sounds to play recursively, a problem I now remember from when I originally wrote this. Change it to `nnoremap` by default to get around this. We'll look into whether it's possible to get user-defined mappings attached somehow. Maybe in the save-and-restore process. --- autoload/auditory.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 596fefe..a981e0a 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -438,7 +438,7 @@ function! auditory#AssignNormalModeMappings() " If this an `execute` mapping, add a pipe let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' - execute 'nmap ' . key . + execute 'nnoremap ' . key . \ ' :call auditory#Play("' . value.audio . '")' . \ l:pipe . value.map_to endfor -- cgit v1.2.3 From 0adb3c1b578fb0118de6387bddeea633bb1e1a94 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2015 22:34:44 -0400 Subject: autoload/auditory.vim: Ensure we `` if we're not piping If we're not piping to an `execute` command in the mapping, we need to `` to execute the sound player and type the normal mode command. Otherwise the normal mode command gets typed in command mode which is not what we want and messes things up greatly. Figured I would just tack the `` on to the pipe variable rather than create a new one since it's the inverse of what we need in that situation. Hopefully the intention is clear enough but I'll grant that this doesn't expose the most clarity. Edit: Added a comment for better explanation of the . --- autoload/auditory.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index a981e0a..4980ba5 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -435,8 +435,9 @@ let s:mappings[''] = { function! auditory#AssignNormalModeMappings() for [key, value] in items(s:mappings) - " If this an `execute` mapping, add a pipe - let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' + " If this an `execute` mapping, add a pipe. + " Otherwise to exit command mode. + let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' execute 'nnoremap ' . key . \ ' :call auditory#Play("' . value.audio . '")' . -- cgit v1.2.3 From a5e9b6c85c15ad9b8ce011171412fa5766d39e02 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 19 Jul 2015 11:19:06 -0400 Subject: autoload/auditory.vim: Reenable visual mode 'x' mapping Needed to come up with a way to add it to the `mappings` dictionary without overriding the existing normal mode 'x' mapping. Prefixed it with `v_` for the dictionary key so that it doesn't conflict, but that could easily be the start of a mapping (for whatever reason), so added a `map_from` field to make it explicit what we're mapping from in cases where the dict key is unclear. Also added another field to the dict to specify a custom mapping command. It will default to `nnoremap` as that's the one we use for most of our commands, but you can change it if you need another mode as we do for this visual 'x' mapping. --- autoload/auditory.vim | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 4980ba5..79ac524 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -412,10 +412,12 @@ let s:mappings['x'] = { \ 'audio': '/Resources/Normal_Mode/Delete.wav', \ 'map_to': "exec 'normal!' v:count1 . 'x'", \ } -" let s:mappings['x'] = { -" \ 'audio': '/Resources/Normal_Mode/Delete.wav', -" \ 'map_to': "exec 'normal!' v:count1 . 'x'", -" \ } +let s:mappings['v_x'] = { + \ 'audio': '/Resources/Normal_Mode/Delete.wav', + \ 'map_command': 'vnoremap', + \ 'map_from': 'x', + \ 'map_to': "exec 'normal!' v:count1 . 'x'", +\ } " 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 @@ -439,7 +441,13 @@ function! auditory#AssignNormalModeMappings() " Otherwise to exit command mode. let l:pipe = match(value.map_to, 'exec') !=# -1 ? ' \| ' : '' - execute 'nnoremap ' . key . + " Default to nnoremap + let l:cmd = has_key(value, 'map_command') ? value.map_command : 'nnoremap' + + " 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 + + execute l:cmd . ' ' . l:map_from . \ ' :call auditory#Play("' . value.audio . '")' . \ l:pipe . value.map_to endfor -- cgit v1.2.3 From 073fad07c8f9a7b2d59aa9a71061425c095d270e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 19 Jul 2015 11:31:45 -0400 Subject: autoload/auditory.vim: Unsilence search commands The search commands, as I has specified previously in the verbose mappings from before, should not be silenced, otherwise you can't see the useful output that they provide in the command line area. Add a way to make a mapping silent or not using a new field in the mappings dictionary. --- autoload/auditory.vim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 79ac524..31718dc 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -304,22 +304,27 @@ let s:mappings['P'] = { let s:mappings['/'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'silent': 0, \ 'map_to': "/", \ } let s:mappings['n'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'silent': 0, \ 'map_to': "n", \ } let s:mappings['N'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'silent': 0, \ 'map_to': "N", \ } let s:mappings['#'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'silent': 0, \ 'map_to': "#", \ } let s:mappings['*'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', + \ 'silent': 0, \ 'map_to': "*", \ } @@ -447,7 +452,13 @@ function! auditory#AssignNormalModeMappings() " 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 - execute l:cmd . ' ' . l:map_from . + " Default to unless the mapping explicitly calls for a value + let l:silence = '' + if has_key(value, 'silent') + let l:silence = value.silent ? l:silence : '' + endif + + execute l:cmd . ' ' . l:silence . ' ' . l:map_from . \ ' :call auditory#Play("' . value.audio . '")' . \ l:pipe . value.map_to endfor -- cgit v1.2.3 From 98b259d4065ef5b986d5d3cda953518061a6117f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 19 Jul 2015 11:42:47 -0400 Subject: auditory.vim: `AssignNormalModeMappings` -> `AssignMappings` Rename the function because we're not only assigning normal mode mappings here, we're also assigning visual mode mappings. And we might be assigning mappings for other modes here too in the future, so this name doesn't make sense. I had originally called it this to distinguish it from the insert mode set defined in plugin/auditory.vim with the `CursorMovedI` autocommand, but I think this should be more clear about what it's doing. Edit: Also modify the comment above this section for similar reasons. --- autoload/auditory.vim | 6 +++--- plugin/auditory.vim | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 31718dc..915c561 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -202,8 +202,8 @@ function! s:DeleteLine(type) endfunction -" Normal mode -" =========== +" Standard Mappings +" ================= let s:mappings = {} let s:mappings['h'] = { @@ -440,7 +440,7 @@ let s:mappings[''] = { \ 'map_to': "", \ } -function! auditory#AssignNormalModeMappings() +function! auditory#AssignMappings() for [key, value] in items(s:mappings) " If this an `execute` mapping, add a pipe. " Otherwise to exit command mode. diff --git a/plugin/auditory.vim b/plugin/auditory.vim index ba46fa2..87bfd71 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -20,4 +20,4 @@ augroup END command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() -call auditory#AssignNormalModeMappings() +call auditory#AssignMappings() -- cgit v1.2.3 From 340cf5a64b97cc9f123a85953c7f5b9bf93d2a9e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 19 Jul 2015 12:28:11 -0400 Subject: autoload/auditory.vim: Add function to store user mappings Get any mappings users have defined for the keys/commands that we use for playing audio and store them in our `mappings` dictionary. This will allow us to be friendly and have the keys do what users have defined them to do instead of using the stock Vim actions for everything. Storing these mappings will also allow us to easily restore user mappings when we make a way to turn the plugin's sounds off by unmapping our custom sound maps. --- autoload/auditory.vim | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 915c561..0476631 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -463,3 +463,18 @@ function! auditory#AssignMappings() \ l:pipe . value.map_to endfor 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 + let l:user_mapping = maparg(l:map_from) + + if l:user_mapping + let value.user_mapping = l:user_mapping + endif + endfor +endfunction -- cgit v1.2.3 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 From e2c581348cb66dc1446877e335ba4c3ccc17bd39 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 26 Jul 2015 12:05:12 -0400 Subject: autoload/auditory.vim: Initial Unmap function Unmaps all normal mode commands. This will be used to turn Auditory off. We'll want to also turn custom user mappings back on in the process but that's for a later commit. --- autoload/auditory.vim | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 4bfac77..c590aad 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -479,3 +479,14 @@ function! auditory#StoreUserMapping(map_from) endif endif endfunction + + +function! auditory#Unmap() + for [key, value] in items(s:mappings) + let l:cmd = has_key(value, 'map_command') ? value.map_command : 'nnoremap' + + if l:cmd ==# 'nnoremap' + execute 'nunmap ' . key + endif + endfor +endfunction -- cgit v1.2.3 From db37f84e67f2e20a33348453f6c1d351741f2f1e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 27 Jul 2015 01:11:34 -0400 Subject: TODO: Add some tasks related to the new mapping system --- TODO | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/TODO b/TODO index fccd05f..9659274 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,13 @@ TODO ==== +2015.07.26: +- Add all mappings to `s:mappings` +- Store user mappings on assignment +- If has user mapping, map to that user mapping +- On unmap, if has user mapping, remap back to that user mapping + + 2015.07.14: - Use Vim's `maparg()` to store user mappings so that we can create a toggle command that restores pre-plugin mappings -- cgit v1.2.3 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 From a4cf047b6cc8b9f09c4aa56dbf230e66bf7497b5 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 28 Jul 2015 00:09:37 -0400 Subject: plugin/auditory.vim: Add `:AuditoryOff` command New command that turns the plugin off by removing its mappings. --- plugin/auditory.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/auditory.vim b/plugin/auditory.vim index 87bfd71..21082f0 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -18,6 +18,7 @@ augroup END command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() +command! AuditoryOff call auditory#Unmap() call auditory#AssignMappings() -- cgit v1.2.3 From c3af9fe7691ce2b4db2b6c876eebf7b06e2d6bb1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Aug 2015 23:46:56 -0400 Subject: autoload/auditory.vim: Extract `map_to` to auditory#AssignMappings Take out the `map_to` field for Auditory's mappings and instead do what it needs to do in `AssignMappings`. Makes the code a bit more DRY. We replace it where necessary with a `count` field that tells whether we should `v:count1` the mapping. --- autoload/auditory.vim | 98 ++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 55 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 1e5772b..ed2040c 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -208,220 +208,201 @@ endfunction let s:mappings = {} let s:mappings['h'] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'h'", + \ 'count': 1, \ } let s:mappings['j'] = { \ 'audio': '/Resources/Normal_Mode/Down.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'j'", + \ 'count': 1, \ } let s:mappings['k'] = { \ 'audio': '/Resources/Normal_Mode/Up.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'k'", + \ 'count': 1, \ } let s:mappings['l'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'l'", + \ 'count': 1, \ } let s:mappings['gj'] = { \ 'audio': '/Resources/Normal_Mode/Down.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'gj'", + \ 'count': 1, \ } let s:mappings['gk'] = { \ 'audio': '/Resources/Normal_Mode/Up.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'gk'", + \ 'count': 1, \ } let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . ''", + \ 'count': 1, \ } " FIXME: allow counts on the delete key let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "", \ } let s:mappings['0'] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "0", \ } let s:mappings['^'] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . '^'", + \ 'count': 1, \ } let s:mappings['_'] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . '_'", + \ 'count': 1, \ } let s:mappings['$'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . '$'", + \ 'count': 1, \ } let s:mappings['g_'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'g_'", + \ 'count': 1, \ } let s:mappings['%'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "%", \ } let s:mappings['b'] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'b'", + \ 'count': 1, \ } let s:mappings['w'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'w'", + \ 'count': 1, \ } let s:mappings['e'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'e'", + \ 'count': 1, \ } let s:mappings['B'] = { \ 'audio': '/Resources/Normal_Mode/Left.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'B'", + \ 'count': 1, \ } let s:mappings['W'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'W'", + \ 'count': 1, \ } let s:mappings['E'] = { \ 'audio': '/Resources/Normal_Mode/Right.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'E'", + \ 'count': 1, \ } let s:mappings['p'] = { \ 'audio': '/Resources/Normal_Mode/Paste.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'p'", + \ 'count': 1, \ } let s:mappings['P'] = { \ 'audio': '/Resources/Normal_Mode/Paste.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'P'", + \ 'count': 1, \ } let s:mappings['/'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', \ 'silent': 0, - \ 'map_to': "/", \ } let s:mappings['n'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', \ 'silent': 0, - \ 'map_to': "n", \ } let s:mappings['N'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', \ 'silent': 0, - \ 'map_to': "N", \ } let s:mappings['#'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', \ 'silent': 0, - \ 'map_to': "#", \ } let s:mappings['*'] = { \ 'audio': '/Resources/Normal_Mode/Search.wav', \ 'silent': 0, - \ 'map_to': "*", \ } let s:mappings['zt'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "zt", \ } let s:mappings['z.'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "z.", \ } let s:mappings['zz'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "zz", \ } let s:mappings['zb'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "zb", \ } " FIXME: Allow these scrolling commands to support counts. Was getting errors constructing them the other way let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", \ } let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", \ } let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", \ } " FIXME: need to press twice in order for it to work let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "", \ } let s:mappings['H'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "H", \ } let s:mappings['M'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "M", \ } let s:mappings['L'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "L", \ } let s:mappings['('] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . '('", + \ 'count': 1, \ } let s:mappings[')'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . ')'", + \ 'count': 1, \ } let s:mappings['{'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . '{'", + \ 'count': 1, \ } let s:mappings['}'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . '}'", + \ 'count': 1, \ } let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . ''", + \ 'count': 1, \ } let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . ''", + \ 'count': 1, \ } let s:mappings['gg'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'gg'", + \ 'count': 1, \ } let s:mappings['G'] = { \ 'audio': '/Resources/Normal_Mode/Jump.wav', - \ 'map_to': "exec 'normal!' v:count . 'G'", + \ 'count': 1, \ } let s:mappings['x'] = { \ 'audio': '/Resources/Normal_Mode/Delete.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'x'", + \ 'count': 1, \ } let s:mappings['v_x'] = { \ 'audio': '/Resources/Normal_Mode/Delete.wav', \ 'map_command': 'vnoremap', \ 'map_from': 'x', - \ 'map_to': "exec 'normal!' v:count1 . 'x'", + \ 'count': 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 @@ -431,29 +412,35 @@ let s:mappings['v_x'] = { let s:mappings['u'] = { \ 'audio': '/Resources/Normal_Mode/Undo.wav', - \ 'map_to': "exec 'normal!' v:count1 . 'u'", + \ 'count': 1, \ } " Note: redo doesn't currently support a count because the `v:count1` was giving me an error let s:mappings[''] = { \ 'audio': '/Resources/Normal_Mode/Redo.wav', - \ 'map_to': "", \ } 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 ? ' \| ' : '' - " Default to nnoremap let l:cmd = has_key(value, 'map_command') ? value.map_command : 'nnoremap' " 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 + " Map to the same key unless a `map_to` is defined + let l:map_to = has_key(value, 'map_to') ? value.map_to : key + + let l:map_to_with_count = has_key(value, 'count') ? + \ "execute 'normal!' v:count1 . '" . l:map_to . "'" : + \ l:map_to + + " If this an `execute` mapping, add a pipe. + " Otherwise to exit command mode. + let l:pipe = match(l:map_to_with_count , 'exec') !=# -1 ? ' \| ' : '' + " Default to unless the mapping explicitly calls for a value let l:silence = '' if has_key(value, 'silent') @@ -462,7 +449,8 @@ function! auditory#AssignMappings() execute l:cmd . ' ' . l:silence . ' ' . l:map_from . \ ' :call auditory#Play("' . value.audio . '")' . - \ l:pipe . value.map_to + \ l:pipe . + \ l:map_to_with_count endfor endfunction -- cgit v1.2.3 From 7306b5f6a5a8a1c9db8d9417f115e9f0d4c62f9e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 2 Aug 2015 23:54:47 -0400 Subject: autoload/auditory.vim: Correctly map to user mappings If a user has defined: nnoremap j gj then when you press `j` with Auditory turned on, it should make the sound and do `gj`. Previously it did `j` instead. Now it does `gj`. No more blatant disregard for user mappings. --- autoload/auditory.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index ed2040c..b89daf8 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -430,8 +430,16 @@ 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 - " Map to the same key unless a `map_to` is defined - let l:map_to = has_key(value, 'map_to') ? value.map_to : key + " 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 + else + if has_key(value, 'user_mapping') + let l:map_to = value.user_mapping + else + let l:map_to = key + endif + endif let l:map_to_with_count = has_key(value, 'count') ? \ "execute 'normal!' v:count1 . '" . l:map_to . "'" : -- cgit v1.2.3 From e11e2c45ae3efa36233aa39132f3f8515334b32a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 3 Aug 2015 00:08:23 -0400 Subject: TODO: Update with latest completed items --- TODO | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index 9659274..20dbbcc 100644 --- a/TODO +++ b/TODO @@ -2,14 +2,14 @@ TODO ==== 2015.07.26: -- Add all mappings to `s:mappings` -- Store user mappings on assignment -- If has user mapping, map to that user mapping -- On unmap, if has user mapping, remap back to that user mapping +v Add all mappings to `s:mappings` +v Store user mappings on assignment +v If has user mapping, map to that user mapping +v On unmap, if has user mapping, remap back to that user mapping 2015.07.14: -- Use Vim's `maparg()` to store user mappings so that we can create a toggle +v Use Vim's `maparg()` to store user mappings so that we can create a toggle command that restores pre-plugin mappings -- cgit v1.2.3 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 From d5b7bd6857e82fd2b164d41b929426394dcbf10e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:08:13 -0400 Subject: autoload/auditory.vim: Allow unmapping of non-normal mode commands Add support for unmapping a map from any mode where it was defined, not just normal mode mappings from `auditory#Unmap()`. --- autoload/auditory.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 3e09a90..042c48b 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -509,11 +509,10 @@ 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:key = has_key(value, 'map_from') ? value.map_from : key let l:user_mapping = get(value, 'user_mapping', '') - if l:cmd ==# 'nnoremap' - execute 'nunmap ' . key - endif + execute l:cmd[0] . 'unmap ' . l:key if l:user_mapping !=# '' execute l:cmd . ' ' . get(value, 'map_from', key) . ' ' . value.user_mapping -- cgit v1.2.3 From a612f8fb835df92648401606dec6c2d07fa3ae4b Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:19:58 -0400 Subject: Unmap insert mode sounds from `auditory#Unmap()` * Move the insert mode autocommand definition into a new function that turns on insert mode sounds * Create a function to turn off insert mode sounds * Call these from our normal `AssignMappings` and `Unmap` functions so we can turn all our sounds on and off in one fell swoop --- autoload/auditory.vim | 19 +++++++++++++++++++ plugin/auditory.vim | 6 ------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 042c48b..ffa2b1e 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -76,6 +76,21 @@ function! auditory#PlayScale() endfunction +function! auditory#AssignInsertMappings() + augroup auditory#insert_mode + autocmd! + autocmd CursorMovedI * call auditory#PlayScale() + augroup END +endfunction + + +function! auditory#UnmapInsert() + augroup auditory#insert_mode + autocmd! + augroup END +endfunction + + let s:galaxy_far_far_away_index = 0 let s:cantina = [ \ 'Cantina_1.1.wav', @@ -485,6 +500,8 @@ function! auditory#AssignMappings() \ l:pipe . \ l:map_to_with_count endfor + + call auditory#AssignInsertMappings() endfunction @@ -518,4 +535,6 @@ function! auditory#Unmap() execute l:cmd . ' ' . get(value, 'map_from', key) . ' ' . value.user_mapping endif endfor + + call auditory#UnmapInsert() endfunction diff --git a/plugin/auditory.vim b/plugin/auditory.vim index 21082f0..e8ceeba 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -11,12 +11,6 @@ if !executable('mplayer') endif -augroup auditory#insert_mode - autocmd! - autocmd CursorMovedI * call auditory#PlayScale() -augroup END - - command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() command! AuditoryOff call auditory#Unmap() -- cgit v1.2.3 From f3444f5dcfa269eee62b8daf552b3ed29a43aa04 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:26:56 -0400 Subject: plugin/auditory.vim: Add `:AuditoryOn` command Create a new command to match `:AuditoryOff` that turns on mappings and sounds. We'll need this because I'm going to make the plugin not enable sounds by default. That will be controlled by a global variable. You'll be able to turn the sounds on and off as you wish. --- plugin/auditory.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/auditory.vim b/plugin/auditory.vim index e8ceeba..e0a764a 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -11,8 +11,9 @@ if !executable('mplayer') endif -command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() +command! AuditoryOn call auditory#AssignMappings() command! AuditoryOff call auditory#Unmap() +command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() call auditory#AssignMappings() -- cgit v1.2.3 From 957cc40ba08d66d9b39edda074662677d3d6f21a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:34:36 -0400 Subject: plugin/auditory.vim: Check for `g:auditory_on` Don't heedlessly turn on sounds when the plugin is loaded. Instead, give users a choice of whether or not sounds should be loaded when starting Vim with a configuration variable that can be set in a user vimrc. By default sounds are now off. --- plugin/auditory.vim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin/auditory.vim b/plugin/auditory.vim index e0a764a..593617e 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -11,9 +11,16 @@ if !executable('mplayer') endif +if !exists('g:auditory_on') + let g:auditory_on = 0 +endif + + command! AuditoryOn call auditory#AssignMappings() command! AuditoryOff call auditory#Unmap() command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() -call auditory#AssignMappings() +if g:auditory_on ==# 1 + call auditory#AssignMappings() +endif -- cgit v1.2.3 From da0a9cf9fba990b5d39041b43b7257599fd4c5a4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:39:22 -0400 Subject: plugin/auditory.vim: Condense `g:auditory_on` check Realised that I don't need to explicitly check for 1, I can check against true or false. Get rid of the explicit check to make this more concise. --- plugin/auditory.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/auditory.vim b/plugin/auditory.vim index 593617e..39ae283 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -21,6 +21,6 @@ command! AuditoryOff call auditory#Unmap() command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() -if g:auditory_on ==# 1 +if g:auditory_on call auditory#AssignMappings() endif -- cgit v1.2.3 From 8a0fd42b1df21aa9bd1c9d6f8b169d060ea8db6e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:43:09 -0400 Subject: Add function and command to toggle mappings * Create `auditory#ToggleMappings()` that turns sounds on if they're off and off if they're on * Create an `:AuditoryToggle` command that runs the toggle function in a more user-friendly callable way With a toggle command, turning Auditory on or off can be as simple as hitting 1 custom mapping. With our previous `AuditoryOn` and `AuditoryOff`, you would have to use 2 mappings: 1 for on and another for off. --- autoload/auditory.vim | 11 +++++++++++ plugin/auditory.vim | 1 + 2 files changed, 12 insertions(+) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index ffa2b1e..e914a03 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -538,3 +538,14 @@ function! auditory#Unmap() call auditory#UnmapInsert() endfunction + + +function! auditory#ToggleMappings() + if g:auditory_on + call auditory#Unmap() + let g:auditory_on = 0 + else + call auditory#AssignMappings() + let g:auditory_on = 1 + endif +endfunction diff --git a/plugin/auditory.vim b/plugin/auditory.vim index 39ae283..378fd39 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -18,6 +18,7 @@ endif command! AuditoryOn call auditory#AssignMappings() command! AuditoryOff call auditory#Unmap() +command! AuditoryToggle call auditory#ToggleMappings() command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() -- cgit v1.2.3 From 87452e0058fb8984b678947d33715b155dd3dbf0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 02:48:18 -0400 Subject: autoload/auditory.vim: Fix `AuditoryToggle` + `Auditory[On|Off]` When using `:AuditoryToggle` in conjunction with `:AuditoryOn` or `:AuditoryOff`, things would get messed up. This is because `:AuditoryToggle` relies on `g:auditory_on` in order to know whether to turn sounds on or off, but the variable was only getting set in `auditory#ToggleMappings`, not in the functions that `:AuditoryOn` or `:AuditoryOff` call. Move the setting of the variable into `auditory#AssignMappings` and `auditory#Unmap` so that the right thing will happen regardless of which on/off/toggle commands you run. --- autoload/auditory.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index e914a03..e214974 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -502,6 +502,8 @@ function! auditory#AssignMappings() endfor call auditory#AssignInsertMappings() + + let g:auditory_on = 1 endfunction @@ -537,15 +539,15 @@ function! auditory#Unmap() endfor call auditory#UnmapInsert() + + let g:auditory_on = 0 endfunction function! auditory#ToggleMappings() if g:auditory_on call auditory#Unmap() - let g:auditory_on = 0 else call auditory#AssignMappings() - let g:auditory_on = 1 endif endfunction -- cgit v1.2.3 From 71ec214cdb8814ecb71c837bf947583fda54d37e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 14:45:33 -0400 Subject: Create a setting for Galaxy Far Far Away sounds Adding a configuration variable for these sounds allows them to be turned on by default without having to `:AuditoryToggleGalaxyFarFarAway`, so if you prefer these sounds you can enable them at the outset. --- autoload/auditory.vim | 7 +++---- plugin/auditory.vim | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index e214974..994b64e 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -169,20 +169,19 @@ function! s:GalaxyFarFarAway() endfunction -let s:galaxy_far_far_away = 0 function! auditory#ToggleGalaxyFarFarAway() - if s:galaxy_far_far_away + if g:auditory_galaxy_far_far_away augroup auditory#insert_mode autocmd! autocmd CursorMovedI * call auditory#PlayScale() augroup END - let s:galaxy_far_far_away = 0 + let g:auditory_galaxy_far_far_away = 0 else augroup auditory#insert_mode autocmd! autocmd CursorMovedI * call GalaxyFarFarAway() augroup END - let s:galaxy_far_far_away = 1 + let g:auditory_galaxy_far_far_away = 1 endif endfunction diff --git a/plugin/auditory.vim b/plugin/auditory.vim index 378fd39..d740561 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -15,6 +15,10 @@ if !exists('g:auditory_on') let g:auditory_on = 0 endif +if !exists('g:auditory_galaxy_far_far_away') + let g:auditory_galaxy_far_far_away = 0 +endif + command! AuditoryOn call auditory#AssignMappings() command! AuditoryOff call auditory#Unmap() @@ -25,3 +29,8 @@ command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() if g:auditory_on call auditory#AssignMappings() endif + +if g:auditory_galaxy_far_far_away + let g:auditory_galaxy_far_far_away = 0 + call auditory#ToggleGalaxyFarFarAway() +endif -- cgit v1.2.3 From 1c9fe852b40d4e7a883bcdc71c91abdd023514bb Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 14:50:35 -0400 Subject: Don't turn on Galaxy Far Far away when not `g:auditory_on` My change from 71ec214cdb8814ecb71c837bf947583fda54d37e caused Galaxy Far Far Away sounds to be turned on any time you had `g:auditory_galaxy_far_far_away` turned on, regardless of whether `g:auditory_on` was also turned on. Fix this because we never want sounds to play when `g:auditory_on` is off. We now rely on `auditory#AssignInsertMappings()` to know whether to use Galaxy Far Far Away or default insert mode sounds. Need to toggle `g:auditory_galaxy_far_far_away` in that function because we're calling the toggle function so we need to set it to the opposite of what we want. In the future if we add more insert mode sounds we'll have to change this structure around but it should work for now. --- autoload/auditory.vim | 6 ++---- plugin/auditory.vim | 5 ----- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 994b64e..1e3d134 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -77,10 +77,8 @@ endfunction function! auditory#AssignInsertMappings() - augroup auditory#insert_mode - autocmd! - autocmd CursorMovedI * call auditory#PlayScale() - augroup END + let g:auditory_galaxy_far_far_away = !g:auditory_galaxy_far_far_away + call auditory#ToggleGalaxyFarFarAway() endfunction diff --git a/plugin/auditory.vim b/plugin/auditory.vim index d740561..411a812 100644 --- a/plugin/auditory.vim +++ b/plugin/auditory.vim @@ -29,8 +29,3 @@ command! AuditoryToggleGalaxyFarFarAway call auditory#ToggleGalaxyFarFarAway() if g:auditory_on call auditory#AssignMappings() endif - -if g:auditory_galaxy_far_far_away - let g:auditory_galaxy_far_far_away = 0 - call auditory#ToggleGalaxyFarFarAway() -endif -- cgit v1.2.3 From 324da0f6817f9fd409f7963b1c34dd8eb8d7a2b6 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 15:08:16 -0400 Subject: autoload/auditory.vim: Remove old functions Delete some old code that isn't used any more. This was when I first made the plugin. These functions were used to start a song when insert mode was activated and stop the song on insert leave. Since we're not playing full songs any more, and our insert sounds are tied to key presses, these functions are no longer needed. --- autoload/auditory.vim | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/autoload/auditory.vim b/autoload/auditory.vim index 1e3d134..1af3d38 100644 --- a/autoload/auditory.vim +++ b/autoload/auditory.vim @@ -2,20 +2,6 @@ let s:script_path = resolve(expand(':p:h')) . '/..' -" Pid -" === - -" Get most recent mplayer pid -function! s:GetPid() - return system("ps | grep mplayer | head -n1 | awk '{printf $1}'") -endfunction - -" Run system kill -function! s:KillPid(pid) - return system("kill " . a:pid) -endfunction - - " Play audio " ========== @@ -27,18 +13,6 @@ endfunction " Insert mode " =========== -" Old functions that would start a song when entering insert mode and stop the -" song when leaving insert mode. -function! s:PlayInsertEnter() - call auditory#Play("/private/test-track.mp3") - let s:insert_mode_pid = s:GetPid() -endfunction - -function! s:PlayInsertLeave() - call s:KillPid(s:insert_mode_pid) -endfunction - - let s:scale = [ \ 'C#3.wav', \ 'C#4.wav', -- cgit v1.2.3 From 431c43bab11294ba0123c1964ae40f1c5665d9e4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 15:11:17 -0400 Subject: TODO: Update with latest completed tasks --- TODO | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 20dbbcc..1d1d813 100644 --- a/TODO +++ b/TODO @@ -26,8 +26,8 @@ v Add pathogen instructions to README (2014.11.15) v Make `dd` work to delete a line v Checking whether mplayer is installed and send an error if not (2014.11.22) - Adding some docs -- Global setting for Galaxy Far Far Away mode -- Add an easy way to turn the plugin on and off without having to disable it manually +v Global setting for Galaxy Far Far Away mode (2015.08.16) +v Add an easy way to turn the plugin on and off without having to disable it manually (2015.08.15) - Play the delete sound when pressing 'D' -- cgit v1.2.3 From 17a812cd4a20c6967be281b9beb8a297298dcf8f Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 16 Aug 2015 17:38:12 -0400 Subject: Add CHANGELOG --- CHANGELOG | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..93a3945 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,22 @@ +CHANGELOG +========= + +v0.0.5 (2014.10.27): + * Don't reload the plugin if it's already loaded + +v0.0.4 (2014.10.22): + * Show a warning message if `mplayer` is not installed + +v0.0.3 (2014.10.15): + * Update default insert mode sounds to use 3 octaves from the C# scale + instead of a single one. (Spencer Bateman) + * Fix bug where `d` didn't save to the delete register + * Add installation instructions to README + +v0.0.2 (2014.10.10): + * Make `dd` work to delete a line and play the delete sound + +v0.0.1 (2014.10.09): + * Initial alpha release from Boston Music Hack Day 2014. Support for an + array of normal mode command sounds, insert mode sounds, as well as Galaxy + Far Far Away sounds in insert mode. -- cgit v1.2.3