diff --git a/plugin/elin.vim b/plugin/elin.vim index fb2a1d74..cc368c99 100644 --- a/plugin/elin.vim +++ b/plugin/elin.vim @@ -7,6 +7,10 @@ let g:elin_home = expand(':p:h:h') let g:elin_auto_connect = get(g:, 'elin_auto_connect', v:true) let g:elin_server_port = get(g:, 'elin_server_port', v:null) +if !exists('g:elin_default_key_mapping_leader') + let g:elin_default_key_mapping_leader = '' +endif + function! s:init() abort if &ft !=# 'clojure' || exists('g:initialized_vim_elin') return @@ -55,3 +59,62 @@ else call s:init() endif endif + +if exists('g:elin_enable_default_key_mappings') + \ && g:elin_enable_default_key_mappings + silent! call s:default_key_mappings() + aug elin_default_key_mappings + au! + au FileType clojure call s:default_key_mappings() + aug END +endif + +function! s:define_mapping(map_type, default_keys, plug_name) abort + if !hasmapto(a:plug_name) + let keys = substitute(a:default_keys, '', g:elin_default_key_mapping_leader, '') + let cmd = printf('%s %s %s', + \ a:map_type, + \ keys, + \ a:plug_name, + \ ) + call execute(cmd, 'silent!') + endif +endfunction + +function! s:default_key_mappings() abort + if exists('b:elin_default_key_mappings_applied') + return + endif + let b:elin_default_key_mappings_applied = v:true + + call s:define_mapping('nmap', "'", 'call elin#notify("elin.handler.connect/connect", [])') + + call s:define_mapping('nmap', "ei", 'call elin#notify("elin.handler.evaluate/evaluate-current-expr", [])') + call s:define_mapping('nmap', "ee", 'call elin#notify("elin.handler.evaluate/evaluate-current-list", [])') + call s:define_mapping('nmap', "et", 'call elin#notify("elin.handler.evaluate/evaluate-current-top-list", [])') + call s:define_mapping('nmap', "eb", 'call elin#notify("elin.handler.evaluate/load-current-file", [])') + + call s:define_mapping('nmap', "en", 'call elin#notify("elin.handler.evaluate/evaluate-namespace-form", [])') + call s:define_mapping('nmap', "ep", 'call elin#notify("elin.handler.evaluate/print-last-result", [])') + call s:define_mapping('nmap', "ea", 'call elin#notify("elin.handler.evaluate/evaluate-at-mark", [nr2char(getchar())])') + call s:define_mapping('nmap', "ece", 'call elin#notify("elin.handler.evaluate/evaluate-current-list", [], {"config": "{:interceptor {:includes [elin.interceptor.optional.evaluate/eval-with-context-interceptor]}}"})') + call s:define_mapping('nmap', "epe", 'call elin#notify("elin.handler.evaluate/evaluate-current-list", [], {"config": "{:interceptor {:includes [[elin.interceptor.optional.evaluate/wrap-eval-code-interceptor \"println\"]]}}"})') + + call s:define_mapping('nmap', "enr", 'call elin#notify("elin.handler.evaluate/reload", [])') + call s:define_mapping('nmap', "enR", 'call elin#notify("elin.handler.evaluate/reload-all", [])') + + call s:define_mapping('nmap', "ran", 'call elin#notify("elin.handler.namespace/add-libspec", [])') + call s:define_mapping('nmap', "ram", 'call elin#notify("elin.handler.namespace/add-missing-libspec", [])') + + call s:define_mapping('nmap', "", 'call elin#notify("elin.handler.navigate/jump-to-definition", [])') + call s:define_mapping('nmap', "K", 'call elin#notify("elin.handler.lookup/lookup", [])') + call s:define_mapping('nmap', "hs", 'call elin#notify("elin.handler.lookup/show-source", [])') + call s:define_mapping('nmap', "tt", 'call elin#notify("elin.handler.test/run-test-under-cursor", [])') + call s:define_mapping('nmap', "tn", 'call elin#notify("elin.handler.test/run-tests-in-ns", [])') + call s:define_mapping('nmap', "tl", 'call elin#notify("elin.handler.test/rerun-last-tests", [])') + call s:define_mapping('nmap', "tr", 'call elin#notify("elin.handler.test/rerun-last-tests", [])') + call s:define_mapping('nmap', "tt", 'call elin#notify("elin.handler.navigate/cycle-source-and-test", [])') + call s:define_mapping('nmap', "ss", 'call elin#internal#buffer#info#toggle()') + call s:define_mapping('nmap', "sl", 'call elin#internal#buffer#info#clear()') + call s:define_mapping('nmap', "", 'call elin#internal#virtual_text#clear()') +endfunction