Skip to content

Commit 51d72ee

Browse files
committed
Fix motion.
1 parent 3073ac2 commit 51d72ee

File tree

2 files changed

+45
-30
lines changed

2 files changed

+45
-30
lines changed

after/ftplugin/python.vim

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,32 @@ endif
77

88
if !pymode#Default('g:pymode_motion', 1) || g:pymode_motion
99

10-
nnoremap <buffer> ]] :call pymode#motion#move('^\(class\\|def\)\s', '')<CR>
11-
nnoremap <buffer> [[ :call pymode#motion#move('^\(class\\|def\)\s', 'b')<CR>
12-
nnoremap <buffer> ]m :call pymode#motion#move('^\s*\(class\\|def\)\s', '')<CR>
13-
nnoremap <buffer> [m :call pymode#motion#move('^\s*\(class\\|def\)\s', 'b')<CR>
14-
onoremap <buffer> ]] :call pymode#motion#move('^\(class\\|def\)\s', '')<CR>
15-
onoremap <buffer> [[ :call pymode#motion#move('^\(class\\|def\)\s', 'b')<CR>
16-
onoremap <buffer> ]m :call pymode#motion#move('^\s*\(class\\|def\)\s', '')<CR>
17-
onoremap <buffer> [m :call pymode#motion#move('^\s*\(class\\|def\)\s', 'b')<CR>
18-
vnoremap <buffer> ]] :call pymode#motion#vmove('^\(class\\|def\)\s', '')<CR>
19-
vnoremap <buffer> [[ :call pymode#motion#vmove('^\(class\\|def\)\s', 'b')<CR>
20-
vnoremap <buffer> ]m :call pymode#motion#vmove('^\s*\(class\\|def\)\s', '')<CR>
21-
vnoremap <buffer> [m :call pymode#motion#vmove('^\s*\(class\\|def\)\s', 'b')<CR>
22-
23-
nnoremap <buffer> vac :call pymode#motion#select('^\s*\(class\)\s', 0)<CR>
24-
nnoremap <buffer> vic :call pymode#motion#select('^\s*\(class\)\s', 1)<CR>
25-
nnoremap <buffer> vam :call pymode#motion#select('^\s*\(def\)\s', 0)<CR>
26-
nnoremap <buffer> vim :call pymode#motion#select('^\s*\(def\)\s', 1)<CR>
27-
onoremap <buffer> am :call pymode#motion#select('^\s*\(def\)\s', 0)<CR>
28-
onoremap <buffer> im :call pymode#motion#select('^\s*\(def\)\s', 1)<CR>
29-
onoremap <buffer> ac :call pymode#motion#select('^\s*\(class\)\s', 0)<CR>
30-
onoremap <buffer> ic :call pymode#motion#select('^\s*\(class\)\s', 1)<CR>
10+
nnoremap <buffer> ]] :<C-U>call pymode#motion#move2('^\(class\\|def\)\s', '')<CR>
11+
nnoremap <buffer> [[ :<C-U>call pymode#motion#move2('^\(class\\|def\)\s', 'b')<CR>
12+
nnoremap <buffer> ]m :<C-U>call pymode#motion#move2('^\s*def\s', '')<CR>
13+
nnoremap <buffer> [m :<C-U>call pymode#motion#move2('^\s*def\s', 'b')<CR>
14+
15+
onoremap <buffer> ]] :<C-U>call pymode#motion#move2('^\(class\\|def\)\s', '')<CR>
16+
onoremap <buffer> [[ :<C-U>call pymode#motion#move2('^\(class\\|def\)\s', 'b')<CR>
17+
onoremap <buffer> ]m :<C-U>call pymode#motion#move2('^\s*def\s', '')<CR>
18+
onoremap <buffer> [m :<C-U>call pymode#motion#move2('^\s*def\s', 'b')<CR>
19+
20+
vnoremap <buffer> ]] :<C-U>call pymode#motion#vmove('^\(class\\|def\)\s', '')<CR>
21+
vnoremap <buffer> [[ :<C-U>call pymode#motion#vmove('^\(class\\|def\)\s', 'b')<CR>
22+
vnoremap <buffer> ]m :<C-U>call pymode#motion#vmove('^\s*def\s', '')<CR>
23+
vnoremap <buffer> [m :<C-U>call pymode#motion#vmove('^\s*def\s', 'b')<CR>
24+
25+
onoremap <buffer> c :<C-U>call pymode#motion#select('^\s*class\s', 0)<CR>
26+
onoremap <buffer> ac :<C-U>call pymode#motion#select('^\s*class\s', 0)<CR>
27+
onoremap <buffer> ic :<C-U>call pymode#motion#select('^\s*class\s', 1)<CR>
28+
vnoremap <buffer> ac :<C-U>call pymode#motion#select('^\s*class\s', 0)<CR>
29+
vnoremap <buffer> ic :<C-U>call pymode#motion#select('^\s*class\s', 1)<CR>
30+
31+
onoremap <buffer> m :<C-U>call pymode#motion#select('^\s*def\s', 0)<CR>
32+
onoremap <buffer> am :<C-U>call pymode#motion#select('^\s*def\s', 0)<CR>
33+
onoremap <buffer> im :<C-U>call pymode#motion#select('^\s*def\s', 1)<CR>
34+
vnoremap <buffer> am :<C-U>call pymode#motion#select('^\s*def\s', 0)<CR>
35+
vnoremap <buffer> im :<C-U>call pymode#motion#select('^\s*def\s', 1)<CR>
3136
3237
endif
3338

autoload/pymode/motion.vim

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
" Check indentation level on motion
2+
" dC dM
3+
14
fun! pymode#motion#block(lnum) "{{{
25
let start = indent(a:lnum)
36
let num = a:lnum
@@ -11,18 +14,25 @@ fun! pymode#motion#block(lnum) "{{{
1114
endfunction "}}}
1215

1316

14-
fun! pymode#motion#move(pattern, flags) "{{{
15-
let i = v:count1
16-
while i > 0
17-
let result = searchpos(a:pattern, a:flags.'W')
18-
let i = i - 1
17+
fun! pymode#motion#move2(pattern, flags, ...) "{{{
18+
let cnt = v:count1 - 1
19+
let [line, column] = searchpos(a:pattern, a:flags . 'W')
20+
let indent = indent(line)
21+
22+
while l:cnt && l:line
23+
let [line, column] = searchpos(a:pattern, a:flags . 'W')
24+
if indent(line) == l:indent
25+
let cnt = l:cnt - 1
26+
endif
1927
endwhile
20-
return result
21-
endfunction "}}}
28+
29+
return [line, column]
30+
31+
endfunction "}}}
2232

2333

2434
fun! pymode#motion#vmove(pattern, flags) "{{{
25-
let end = pymode#motion#move(a:pattern, a:flags)
35+
let end = pymode#motion#move2(a:pattern, a:flags)
2636
normal! gv
2737
call cursor(end)
2838
endfunction "}}}
@@ -35,7 +45,7 @@ endfunction "}}}
3545

3646
fun! pymode#motion#select(pattern, inner) "{{{
3747
let orig = getpos('.')[1:2]
38-
let start = pymode#motion#move(a:pattern, 'bW')
48+
let start = pymode#motion#move2(a:pattern, 'cb')
3949
let eline = pymode#motion#block(start[0])
4050
let end = [eline, len(getline(eline))]
4151
call cursor(orig)

0 commit comments

Comments
 (0)