@@ -28,27 +28,26 @@ fun! pymode#motion#pos_le(pos1, pos2) "{{{
2828 return ((a: pos1 [0 ] < a: pos2 [0 ]) || (a: pos1 [0 ] == a: pos2 [0 ] && a: pos1 [1 ] <= a: pos2 [1 ]))
2929endfunction " }}}
3030
31-
32- fun ! pymode#motion#select (pattern, inner) " {{{
31+ fun ! pymode#motion#select (first_pattern, second_pattern, inner) " {{{
3332 let cnt = v: count1 - 1
3433 let orig = getpos (' .' )[1 :2 ]
35- let snum = s: BlockStart (orig[0 ], a: pattern )
36- if getline (snum ) !~ a: pattern
34+ let posns = s: BlockStart (orig[0 ], a: first_pattern , a: second_pattern )
35+ if getline (posns[ 0 ] ) !~ a: first_pattern && getline (posns[ 0 ]) !~ a: second_pattern
3736 return 0
3837 endif
39- let enum = s: BlockEnd (snum, indent (snum))
38+ let snum = posns[0 ]
39+ let enum = s: BlockEnd (posns[1 ], indent (posns[1 ]))
4040 while cnt
41- let lnum = search (a: pattern , ' nW' )
41+ let lnum = search (a: second_pattern , ' nW' )
4242 if lnum
4343 let enum = s: BlockEnd (lnum, indent (lnum))
4444 call cursor (enum , 1 )
4545 endif
4646 let cnt = cnt - 1
4747 endwhile
48- if pymode#motion#pos_le ([snum, 0 ], orig) && pymode#motion#pos_le (orig, [enum , 1 ])
48+ if pymode#motion#pos_le ([snum, 0 ], orig) && pymode#motion#pos_le (orig, [enum + 1 , 0 ])
4949 if a: inner
50- let snum = snum + 1
51- let enum = prevnonblank (enum )
50+ let snum = posns[1 ] + 1
5251 endif
5352
5453 call cursor (snum, 1 )
@@ -57,28 +56,37 @@ fun! pymode#motion#select(pattern, inner) "{{{
5756 endif
5857endfunction " }}}
5958
59+ fun ! pymode#motion#select_c (pattern, inner) " {{{
60+ call pymode#motion#select (a: pattern , a: pattern , a: inner )
61+ endfunction " }}}
6062
61- fun ! s: BlockStart (lnum, ... ) " {{{
62- let pattern = a: 0 ? a: 1 : ' ^\s*\(@\|class\s.*:\|def\s\)'
63+ fun ! s: BlockStart (lnum, first_pattern, second_pattern) " {{{
6364 let lnum = a: lnum + 1
6465 let indent = 100
6566 while lnum
6667 let lnum = prevnonblank (lnum - 1 )
6768 let test = indent (lnum)
6869 let line = getline (lnum)
69- if line = ~ ' ^\s*#' " Skip comments
70- continue
71- elseif ! test " Zero-level regular line
72- return lnum
73- elseif test >= indent " Skip deeper or equal lines
70+ " Skip comments, deeper or equal lines
71+ if line = ~ ' ^\s*#' || test >= indent
7472 continue
75- " Indent is strictly less at this point: check for def/class
76- elseif line = ~ pattern && line !~ ' ^\s*@'
77- return lnum
7873 endif
7974 let indent = indent (lnum)
75+
76+ " Indent is strictly less at this point: check for def/class/@
77+ if line = ~ a: first_pattern || line = ~ a: second_pattern
78+ while getline (lnum- 1 ) = ~ a: first_pattern
79+ let lnum = lnum - 1
80+ endwhile
81+ let first_pos = lnum
82+ while getline (lnum) !~ a: second_pattern
83+ let lnum = lnum + 1
84+ endwhile
85+ let second_pos = lnum
86+ return [first_pos, second_pos]
87+ endif
8088 endwhile
81- return 0
89+ return [ 0 , 0 ]
8290endfunction " }}}
8391
8492
@@ -89,7 +97,7 @@ fun! s:BlockEnd(lnum, ...) "{{{
8997 let lnum = nextnonblank (lnum + 1 )
9098 if getline (lnum) = ~ ' ^\s*#' | continue
9199 elseif lnum && indent (lnum) <= indent
92- return lnum - 1
100+ return prevnonblank ( lnum - 1 )
93101 endif
94102 endwhile
95103 return line (' $' )
0 commit comments