Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf61b74a

Browse files
authored
Merge pull request#1015 from KamranMaharov/method_motion_include_decorator
method motions to include decorators
2 parentsac11db2 +0a90e0f commitf61b74a

File tree

3 files changed

+77
-32
lines changed

3 files changed

+77
-32
lines changed

‎after/ftplugin/python.vim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ if g:pymode_motion
3030
vnoremap<buffer>]M:call pymode#motion#vmove('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', '')<CR>
3131
vnoremap<buffer>[M:call pymode#motion#vmove('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 'b')<CR>
3232
33-
onoremap<buffer>C:<C-U>call pymode#motion#select('^<Bslash>s*class<Bslash>s', 0)<CR>
34-
onoremap<buffer>aC:<C-U>call pymode#motion#select('^<Bslash>s*class<Bslash>s', 0)<CR>
35-
onoremap<buffer>iC:<C-U>call pymode#motion#select('^<Bslash>s*class<Bslash>s', 1)<CR>
36-
vnoremap<buffer>aC:<C-U>call pymode#motion#select('^<Bslash>s*class<Bslash>s', 0)<CR>
37-
vnoremap<buffer>iC:<C-U>call pymode#motion#select('^<Bslash>s*class<Bslash>s', 1)<CR>
38-
39-
onoremap<buffer>M:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
40-
onoremap<buffer>aM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
41-
onoremap<buffer>iM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 1)<CR>
42-
vnoremap<buffer>aM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
43-
vnoremap<buffer>iM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 1)<CR>
33+
onoremap<buffer>C:<C-U>call pymode#motion#select_c('^<Bslash>s*class<Bslash>s', 0)<CR>
34+
onoremap<buffer>aC:<C-U>call pymode#motion#select_c('^<Bslash>s*class<Bslash>s', 0)<CR>
35+
onoremap<buffer>iC:<C-U>call pymode#motion#select_c('^<Bslash>s*class<Bslash>s', 1)<CR>
36+
vnoremap<buffer>aC:<C-U>call pymode#motion#select_c('^<Bslash>s*class<Bslash>s', 0)<CR>
37+
vnoremap<buffer>iC:<C-U>call pymode#motion#select_c('^<Bslash>s*class<Bslash>s', 1)<CR>
38+
39+
onoremap<buffer>M:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@','^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
40+
onoremap<buffer>aM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@','^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
41+
onoremap<buffer>iM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@','^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 1)<CR>
42+
vnoremap<buffer>aM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@','^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 0)<CR>
43+
vnoremap<buffer>iM:<C-U>call pymode#motion#select('^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=@','^<Bslash>s*<Bslash>(async<Bslash>s<Bslash>+<Bslash>)<Bslash>=def<Bslash>s', 1)<CR>
4444
4545
endif
4646

‎autoload/pymode/motion.vim

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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]))
2929
endfunction"}}}
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-
letsnum=s:BlockStart(orig[0],a:pattern)
36-
ifgetline(snum)!~a:pattern
34+
letposns=s:BlockStart(orig[0],a:first_pattern,a:second_pattern)
35+
ifgetline(posns[0])!~a:first_pattern&&getline(posns[0])!~a:second_pattern
3736
return0
3837
endif
39-
letenum=s:BlockEnd(snum,indent(snum))
38+
let snum= posns[0]
39+
letenum=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
letenum=s:BlockEnd(lnum,indent(lnum))
4444
callcursor(enum,1)
4545
endif
4646
let cnt= cnt-1
4747
endwhile
48-
ifpymode#motion#pos_le([snum,0], orig)&&pymode#motion#pos_le(orig, [enum,1])
48+
ifpymode#motion#pos_le([snum,0], orig)&&pymode#motion#pos_le(orig, [enum+1,0])
4949
ifa:inner
50-
let snum= snum+1
51-
letenum=prevnonblank(enum)
50+
let snum= posns[1]+1
5251
endif
5352

5453
callcursor(snum,1)
@@ -57,28 +56,37 @@ fun! pymode#motion#select(pattern, inner) "{{{
5756
endif
5857
endfunction"}}}
5958

59+
fun!pymode#motion#select_c(pattern, inner)"{{{
60+
callpymode#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
letindent=100
6566
while lnum
6667
let lnum=prevnonblank(lnum-1)
6768
let test=indent(lnum)
6869
letline=getline(lnum)
69-
ifline=~'^\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+
ifline=~'^\s*#'|| test>=indent
7472
continue
75-
" Indent is strictly less at this point: check for def/class
76-
elseifline=~ pattern&&line!~'^\s*@'
77-
return lnum
7873
endif
7974
letindent=indent(lnum)
75+
76+
" Indent is strictly less at this point: check for def/class/@
77+
ifline=~a:first_pattern||line=~a:second_pattern
78+
whilegetline(lnum-1)=~a:first_pattern
79+
let lnum= lnum-1
80+
endwhile
81+
let first_pos= lnum
82+
whilegetline(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-
return0
89+
return[0,0]
8290
endfunction"}}}
8391

8492

@@ -89,7 +97,7 @@ fun! s:BlockEnd(lnum, ...) "{{{
8997
let lnum=nextnonblank(lnum+1)
9098
ifgetline(lnum)=~'^\s*#' |continue
9199
elseif lnum&&indent(lnum)<=indent
92-
return lnum-1
100+
returnprevnonblank(lnum-1)
93101
endif
94102
endwhile
95103
returnline('$')

‎tests/motion_decorator.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!coding=utf-8
2+
"""
3+
to test pymode motions, please put cursor on each of the lines
4+
and press "vaM" for selecting methods or
5+
"vaC" for selection class.
6+
"""
7+
8+
defa_decorator(func):
9+
print("chamando func")
10+
defwrapped(*args,**kw):
11+
returnfunc(*args,**kw)
12+
print("Pós func")
13+
returnwrapped
14+
15+
defb_decorator(func):
16+
print("second chamando func")
17+
defwrapped(*args,**kw):
18+
returnfunc(*args,**kw)
19+
print("second Pós func")
20+
returnwrapped
21+
22+
@b_decorator
23+
@a_decorator
24+
defteste():
25+
print("Not Selecting Decorator")
26+
27+
classTeste:
28+
@a_decorator
29+
@b_decorator
30+
defmetodo(self):
31+
print("Meu método")
32+
33+
34+
teste()
35+
36+
testinho=Teste()
37+
testinho.metodo()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp