|
| 1 | +try |
| 2 | + call refactoring_toolbox#adapters#vim#begin_ftplugin('refactoring_toolbox') |
| 3 | +catch /plugin_loaded/ |
| 4 | + finish |
| 5 | +endtry |
| 6 | + |
| 7 | +function s:registerMappings() |
| 8 | + if s:mappingIsEnabled() |
| 9 | + call s:addBufferVisualMapping( |
| 10 | + \ '<LocalLeader>ev', |
| 11 | + \ '<Plug>refactoring_toolbox_vim_ExtractVariable', |
| 12 | + \ 'refactoring_toolbox#extract_variable#main#extractVariableForVim()' |
| 13 | + \ ) |
| 14 | + endif |
| 15 | +endfunction |
| 16 | + |
| 17 | +function s:mappingIsEnabled() |
| 18 | + return !exists('no_plugin_maps') && !exists('no_typescript_maps') |
| 19 | +endfunction |
| 20 | + |
| 21 | +function s:addBufferNormalMapping(keys, name, executeFunction) |
| 22 | + if !hasmapto(a:name, 'n') |
| 23 | + call s:addUniqueBufferNormalMapping(a:keys, a:name) |
| 24 | + endif |
| 25 | + |
| 26 | + call s:addUniqueScriptAndBufferNormalMapping(a:name, ':call '.a:executeFunction.'<Enter>') |
| 27 | +endfunction |
| 28 | + |
| 29 | +function s:addUniqueBufferNormalMapping(left, right) |
| 30 | + execute 'nmap <buffer> <unique> '.a:left.' '.a:right |
| 31 | + |
| 32 | + call refactoring_toolbox#adapters#vim#appendFileTypeUndo('nunmap <buffer> '.a:left) |
| 33 | +endfunction |
| 34 | + |
| 35 | +function s:addUniqueScriptAndBufferNormalMapping(left, right) |
| 36 | + execute 'nnoremap <script> <buffer> <unique> '.a:left.' '.a:right |
| 37 | + |
| 38 | + call refactoring_toolbox#adapters#vim#appendFileTypeUndo('nunmap <script> <buffer> '.a:left) |
| 39 | +endfunction |
| 40 | + |
| 41 | +function s:addBufferVisualMapping(keys, name, executeFunction) |
| 42 | + if !hasmapto(a:name, 'v') |
| 43 | + call s:addUniqueBufferVisualMapping(a:keys, a:name) |
| 44 | + endif |
| 45 | + |
| 46 | + call s:addUniqueScriptAndBufferVisualMapping(a:name, ':call '.a:executeFunction.'<Enter>') |
| 47 | +endfunction |
| 48 | + |
| 49 | +function s:addUniqueBufferVisualMapping(left, right) |
| 50 | + execute 'vmap <buffer> <unique> '.a:left.' '.a:right |
| 51 | + |
| 52 | + call refactoring_toolbox#adapters#vim#appendFileTypeUndo('vunmap <buffer> '.a:left) |
| 53 | +endfunction |
| 54 | + |
| 55 | +function s:addUniqueScriptAndBufferVisualMapping(left, right) |
| 56 | + execute 'vnoremap <script> <buffer> <unique> '.a:left.' '.a:right |
| 57 | + |
| 58 | + call refactoring_toolbox#adapters#vim#appendFileTypeUndo('vunmap <script> <buffer> '.a:left) |
| 59 | +endfunction |
| 60 | + |
| 61 | +call s:registerMappings() |
| 62 | + |
| 63 | +call refactoring_toolbox#adapters#vim#end_ftplugin() |
0 commit comments