-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathrubyblock.vim
More file actions
58 lines (44 loc) · 1.34 KB
/
rubyblock.vim
File metadata and controls
58 lines (44 loc) · 1.34 KB
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
if exists('g:loaded_textobj_rubyblock') "{{{1
finish
endif
" Interface "{{{1
call textobj#user#plugin('rubyblock', {
\ '-': {
\ '*sfile*': expand('<sfile>:p'),
\ 'select-a': 'ar', '*select-a-function*': 's:select_a',
\ 'select-i': 'ir', '*select-i-function*': 's:select_i'
\ }
\ })
" Misc. "{{{1
let s:comment_escape = '\v^[^#]*'
let s:block_openers = '\zs(<def>|<if>|<do>|<module>|<class>)'
let s:start_pattern = s:comment_escape . s:block_openers
let s:end_pattern = s:comment_escape . '\zs<end>'
let s:skip_pattern = 'getline(".") =~ "\\w\\s\\.*+if"'
function! s:select_a()
let s:flags = 'W'
call searchpair(s:start_pattern,'',s:end_pattern, s:flags, s:skip_pattern)
let end_pos = getpos('.')
" Jump to match
normal %
let start_pos = getpos('.')
return ['V', start_pos, end_pos]
endfunction
function! s:select_i()
let s:flags = 'W'
if expand('<cword>') == 'end'
let s:flags = 'cW'
endif
call searchpair(s:start_pattern,'',s:end_pattern, s:flags, s:skip_pattern)
" Move up one line, and save position
normal k^
let end_pos = getpos('.')
" Move down again, jump to match, then down one line and save position
normal j^%j
let start_pos = getpos('.')
return ['V', start_pos, end_pos]
endfunction
" Fin. "{{{1
let g:loaded_textobj_rubyblock = 1
" __END__
" vim: foldmethod=marker