-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelixir.vim
64 lines (48 loc) · 1.73 KB
/
elixir.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
if exists('g:loaded_textobj_elixir')
finish
endif
let g:loaded_textobj_elixir = 1
let s:save_cpo = &cpoptions
set cpoptions&vim
call textobj#user#plugin('elixir', {
\ 'blocks': {
\ 'select-a-function': 'ElixirAround',
\ 'select-a': 'ae',
\ 'select-i-function': 'ElixirInside',
\ 'select-i': 'ie',
\ },
\ })
function! ElixirAround()
let head_pos = searchpairpos('\<do\>:\@!\|\<fn\>', '', '\<end\>', 'Wbn')
let tail_pos = searchpairpos('\<do\>:\@!\|\<fn\>', '', '\<end\>', 'Wn')
let fn_head_pos = searchpairpos('\<fn\>', '', '\<end\>', 'Wbn')
let fn_tail_pos = searchpairpos('\<fn\>', '', '\<end\>', 'Wn')
let select_mode = 'V'
if fn_head_pos == head_pos && fn_tail_pos == tail_pos
let select_mode = 'v'
endif
let [head_line, head_col] = head_pos
let [tail_line, tail_col] = tail_pos
return [select_mode, [0, head_line, head_col, 0], [0, tail_line, tail_col + 2, 0]]
endfunction
function! ElixirInside()
let head_pos = searchpairpos('\<do\>:\@!\|\<fn\>', '', '\<end\>','Wnb')
let tail_pos = searchpairpos('\<do\>:\@!\|\<fn\>', '', '\<end\>','Wn')
let fn_head_pos = searchpairpos('\<fn\>', '', '\<end\>','Wnb')
let fn_tail_pos = searchpairpos('\<fn\>', '', '\<end\>','Wn')
let select_mode = 'V'
if fn_head_pos == head_pos && fn_tail_pos == tail_pos
let select_mode = 'v'
endif
let [head_line, head_col] = head_pos
let [tail_line, tail_col] = tail_pos
if head_line != 0 && tail_line != 0
if !(fn_head_pos == head_pos && fn_tail_pos == tail_pos)
let head_line = head_line + 1
let tail_line = tail_line - 1
endif
return [select_mode, [0, head_line, head_col + 2, 0], [0, tail_line, tail_col - 1, 0]]
endif
endfunction
let &cpoptions = s:save_cpo
unlet s:save_cpo