-
Notifications
You must be signed in to change notification settings - Fork 56
/
tidal.vim
84 lines (70 loc) · 2.51 KB
/
tidal.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Functions
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let s:not_prefixable_keywords = [ "import", "data", "instance", "class", "{-#", "type", "case", "do", "let", "default", "foreign", "--"]
" guess correct number of spaces to indent
" (tabs are not allowed)
function! Get_indent_string()
return repeat(" ", 4)
endfunction
" replace tabs by spaces
function! Tab_to_spaces(text)
return substitute(a:text, " ", Get_indent_string(), "g")
endfunction
" Wrap in :{ :} if there's more than one line
function! Wrap_if_multi(lines)
if len(a:lines) > 1
return [":{"] + a:lines + [":}"]
else
return a:lines
endif
endfunction
" change string into array of lines
function! Lines(text)
return split(a:text, "\n")
endfunction
" change lines back into text
function! Unlines(lines)
if g:tidal_target == "tmux"
" Without this, the user has to manually submit a newline each time
" they evaluate an expression with `ctrl e`.
return join(a:lines, "\n") . "\n"
else
return join(a:lines, "\n")
endif
endfunction
" vim slime handler
function! _EscapeText_tidal(text)
let l:lines = Lines(Tab_to_spaces(a:text))
let l:lines = Wrap_if_multi(l:lines)
return Unlines(l:lines)
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if !exists("g:tidal_no_mappings") || !g:tidal_no_mappings
if !hasmapto('<Plug>TidalConfig', 'n')
nmap <buffer> <localleader>c <Plug>TidalConfig
endif
if !hasmapto('<Plug>TidalRegionSend', 'x')
xmap <buffer> <localleader>s <Plug>TidalRegionSend
xmap <buffer> <c-e> <Plug>TidalRegionSend
endif
if !hasmapto('<Plug>TidalLineSend', 'n')
nmap <buffer> <localleader>s <Plug>TidalLineSend
endif
if !hasmapto('<Plug>TidalParagraphSend', 'n')
nmap <buffer> <localleader>ss <Plug>TidalParagraphSend
nmap <buffer> <c-e> <Plug>TidalParagraphSend
endif
imap <buffer> <c-e> <Esc><Plug>TidalParagraphSend<Esc>i<Right>
nnoremap <buffer> <localleader>h :TidalHush<cr>
nnoremap <buffer> <c-h> :TidalHush<cr>
let i = 1
while i <= 9
execute 'nnoremap <buffer> <localleader>'.i.' :TidalSilence '.i.'<cr>'
execute 'nnoremap <buffer> <c-'.i.'> :TidalSilence '.i.'<cr>'
execute 'nnoremap <buffer> <localleader>s'.i.' :TidalPlay '.i.'<cr>'
let i += 1
endwhile
endif