Skip to content

Commit

Permalink
Add 'def' as one of the block matchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nelstrom committed Nov 20, 2010
1 parent ef0599c commit 114f952
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions vim/bundle/textobj-rubyblock/plugin/textobj/rubyblock.vim
Expand Up @@ -13,7 +13,7 @@ call textobj#user#plugin('rubyblock', {

" Misc. "{{{1
function! s:select_a()
call searchpair('\v^[^#]*\zs(<if>|<do>|<module>|<class>)','','\v^[^#]*\zs<end>', 'cW')
call searchpair('\v^[^#]*\zs(<def>|<if>|<do>|<module>|<class>)','','\v^[^#]*\zs<end>', 'cW')
let end_pos = getpos('.')

normal %
Expand All @@ -23,7 +23,7 @@ function! s:select_a()
endfunction

function! s:select_i()
call searchpair('\v^[^#]*\zs(<if>|<do>|<module>|<class>)','','\v^[^#]*\zs<end>', 'cW')
call searchpair('\v^[^#]*\zs(<def>|<if>|<do>|<module>|<class>)','','\v^[^#]*\zs<end>', 'cW')
let end_pos = getpos('.')
let end_pos[1] = end_pos[1] - 1

Expand Down
14 changes: 12 additions & 2 deletions vim/bundle/textobj-rubyblock/test/examples.rb
Expand Up @@ -16,7 +16,7 @@ class Foo

class Foo
# [cursor]
# Should select Foo class
# vir/var should select Foo class
if true
# do not select inner block only
# search forwards.
Expand All @@ -26,7 +26,17 @@ class Foo
end
end

[1,2,3,4,5].map |i| do
module Foo
class Bar
def Baz
[1,2,3].each do |i|
i + 1
end
end
end
end

[1,2,3,4,5].map do |i|
# don't forget that a method can be called on 'end'!
i + 1
end.max

0 comments on commit 114f952

Please sign in to comment.