Skip to content

Commit

Permalink
feat: Add default mapping for vim/nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Sep 1, 2024
1 parent 8a697ec commit c7e1b06
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions plugin/elin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ let g:elin_home = expand('<sfile>: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 = '<Leader>'
endif

function! s:init() abort
if &ft !=# 'clojure' || exists('g:initialized_vim_elin')
return
Expand Down Expand Up @@ -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, '<Leader>', g:elin_default_key_mapping_leader, '')
let cmd = printf('%s <buffer> %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', "<Leader>'", '<Cmd>call elin#notify("elin.handler.connect/connect", [])<CR>')

call s:define_mapping('nmap', "<Leader>ei", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-current-expr", [])<CR>')
call s:define_mapping('nmap', "<Leader>ee", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-current-list", [])<CR>')
call s:define_mapping('nmap', "<Leader>et", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-current-top-list", [])<CR>')
call s:define_mapping('nmap', "<Leader>eb", '<Cmd>call elin#notify("elin.handler.evaluate/load-current-file", [])<CR>')

call s:define_mapping('nmap', "<Leader>en", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-namespace-form", [])<CR>')
call s:define_mapping('nmap', "<Leader>ep", '<Cmd>call elin#notify("elin.handler.evaluate/print-last-result", [])<CR>')
call s:define_mapping('nmap', "<Leader>ea", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-at-mark", [nr2char(getchar())])<CR>')
call s:define_mapping('nmap', "<Leader>ece", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-current-list", [], {"config": "{:interceptor {:includes [elin.interceptor.optional.evaluate/eval-with-context-interceptor]}}"})<CR>')
call s:define_mapping('nmap', "<Leader>epe", '<Cmd>call elin#notify("elin.handler.evaluate/evaluate-current-list", [], {"config": "{:interceptor {:includes [[elin.interceptor.optional.evaluate/wrap-eval-code-interceptor \"println\"]]}}"})<CR>')

call s:define_mapping('nmap', "<Leader>enr", '<Cmd>call elin#notify("elin.handler.evaluate/reload", [])<CR>')
call s:define_mapping('nmap', "<Leader>enR", '<Cmd>call elin#notify("elin.handler.evaluate/reload-all", [])<CR>')

call s:define_mapping('nmap', "<Leader>ran", '<Cmd>call elin#notify("elin.handler.namespace/add-libspec", [])<CR>')
call s:define_mapping('nmap', "<Leader>ram", '<Cmd>call elin#notify("elin.handler.namespace/add-missing-libspec", [])<CR>')

call s:define_mapping('nmap', "<C-]>", '<Cmd>call elin#notify("elin.handler.navigate/jump-to-definition", [])<CR>')
call s:define_mapping('nmap', "K", '<Cmd>call elin#notify("elin.handler.lookup/lookup", [])<CR>')
call s:define_mapping('nmap', "<Leader>hs", '<Cmd>call elin#notify("elin.handler.lookup/show-source", [])<CR>')
call s:define_mapping('nmap', "<Leader>tt", '<Cmd>call elin#notify("elin.handler.test/run-test-under-cursor", [])<CR>')
call s:define_mapping('nmap', "<Leader>tn", '<Cmd>call elin#notify("elin.handler.test/run-tests-in-ns", [])<CR>')
call s:define_mapping('nmap', "<Leader>tl", '<Cmd>call elin#notify("elin.handler.test/rerun-last-tests", [])<CR>')
call s:define_mapping('nmap', "<Leader>tr", '<Cmd>call elin#notify("elin.handler.test/rerun-last-tests", [])<CR>')
call s:define_mapping('nmap', "tt", '<Cmd>call elin#notify("elin.handler.navigate/cycle-source-and-test", [])<CR>')
call s:define_mapping('nmap', "<Leader>ss", '<Cmd>call elin#internal#buffer#info#toggle()<CR>')
call s:define_mapping('nmap', "<Leader>sl", '<Cmd>call elin#internal#buffer#info#clear()<CR>')
call s:define_mapping('nmap', "<Leader><Esc>", '<Cmd>call elin#internal#virtual_text#clear()<CR>')
endfunction

0 comments on commit c7e1b06

Please sign in to comment.