@@ -28,27 +28,26 @@ fun! pymode#motion#pos_le(pos1, pos2) "{{{
28
28
return ((a: pos1 [0 ] < a: pos2 [0 ])|| (a: pos1 [0 ]== a: pos2 [0 ]&& a: pos1 [1 ]<= a: pos2 [1 ]))
29
29
endfunction " }}}
30
30
31
-
32
- fun ! pymode#motion#select (pattern, inner)" {{{
31
+ fun ! pymode#motion#select (first_pattern, second_pattern, inner)" {{{
33
32
let cnt= v: count1- 1
34
33
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
37
36
return 0
38
37
endif
39
- let enum = s: BlockEnd (snum,indent (snum))
38
+ let snum= posns[0 ]
39
+ let enum = s: BlockEnd (posns[1 ],indent (posns[1 ]))
40
40
while cnt
41
- let lnum= search (a: pattern ,' nW' )
41
+ let lnum= search (a: second_pattern ,' nW' )
42
42
if lnum
43
43
let enum = s: BlockEnd (lnum,indent (lnum))
44
44
call cursor (enum ,1 )
45
45
endif
46
46
let cnt= cnt- 1
47
47
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 ])
49
49
if a: inner
50
- let snum= snum+ 1
51
- let enum = prevnonblank (enum )
50
+ let snum= posns[1 ]+ 1
52
51
endif
53
52
54
53
call cursor (snum,1 )
@@ -57,28 +56,37 @@ fun! pymode#motion#select(pattern, inner) "{{{
57
56
endif
58
57
endfunction " }}}
59
58
59
+ fun ! pymode#motion#select_c (pattern, inner)" {{{
60
+ call pymode#motion#select (a: pattern ,a: pattern ,a: inner )
61
+ endfunction " }}}
60
62
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)" {{{
63
64
let lnum= a: lnum+ 1
64
65
let indent = 100
65
66
while lnum
66
67
let lnum= prevnonblank (lnum- 1 )
67
68
let test= indent (lnum)
68
69
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
74
72
continue
75
- " Indent is strictly less at this point: check for def/class
76
- elseif line = ~ pattern&& line !~ ' ^\s*@'
77
- return lnum
78
73
endif
79
74
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
80
88
endwhile
81
- return 0
89
+ return [ 0 , 0 ]
82
90
endfunction " }}}
83
91
84
92
@@ -89,7 +97,7 @@ fun! s:BlockEnd(lnum, ...) "{{{
89
97
let lnum= nextnonblank (lnum+ 1 )
90
98
if getline (lnum)= ~' ^\s*#' |continue
91
99
elseif lnum&& indent (lnum)<= indent
92
- return lnum- 1
100
+ return prevnonblank ( lnum- 1 )
93
101
endif
94
102
endwhile
95
103
return line (' $' )