Skip to content

Commit 3562021

Browse files
committed
Add python objects and motions
1 parent 93f5da1 commit 3562021

File tree

7 files changed

+157
-17
lines changed

7 files changed

+157
-17
lines changed

Changelog.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
## 2011-11-30 0.5.0
5+
-------------------
6+
* Add python objects and motions (beta)
7+
:h pymode_motion
8+
49
## 2011-11-27 0.4.8
510
-------------------
611
* Add `PyLintWindowToggle` command

README.rst

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ There is no need to install the pylint_, rope_ or any used python library on you
99

1010
- Highlight syntax errors
1111
- Highlight and auto fix unused imports
12+
- Python objects and motion (]], ]m, vac, vim, dim, ...)
1213
- Strong code completion
1314
- Code refactoring
1415
- Python documentation
@@ -27,16 +28,10 @@ See screencast here: http://t.co/3b0bzeXA (sorry for quality, this is my first s
2728
Changelog
2829
=========
2930

30-
## 2011-11-23 0.4.6
31+
## 2011-11-30 0.5.0
3132
-------------------
32-
* Enable all syntax highlighting
33-
For old settings set in your vimrc: ::
34-
35-
let g:pymode_syntax_builtin_objs = 0
36-
let g:pymode_syntax_builtin_funcs = 0
37-
38-
* Change namespace of syntax variables
39-
See README
33+
* Add python objects and motions (beta)
34+
:h pymode_motion
4035

4136

4237
Requirements
@@ -216,6 +211,9 @@ Other stuff
216211

217212
Default values: ::
218213

214+
" Load motion plugin
215+
let g:pymode_motion = 1
216+
219217
" Load breakpoints plugin
220218
let g:pymode_breakpoint = 1
221219

@@ -291,13 +289,29 @@ Default keys
291289
============== =============
292290
Keys Command
293291
============== =============
294-
**K** Show python docs
292+
**K** Show python docs (g:pymode_doc enabled)
293+
-------------- -------------
294+
**<C-Space>** Rope autocomplete (g:pymode_rope enabled)
295+
-------------- -------------
296+
**<Leader>r** Run python (g:pymode_run enabled)
297+
-------------- -------------
298+
**<Leader>b** Set, unset breakpoint (g:pymode_breakpoint enabled)
299+
-------------- -------------
300+
[[ Jump on previous class or function (normal, visual, operator modes)
301+
-------------- -------------
302+
]] Jump on next class or function (normal, visual, operator modes)
303+
-------------- -------------
304+
[m Jump on previous class or method (normal, visual, operator modes)
305+
-------------- -------------
306+
]m Jump on next class or method (normal, visual, operator modes)
307+
-------------- -------------
308+
ac Select a class. Ex: vac, dac, yac, cac (normal, operator modes)
295309
-------------- -------------
296-
**<C-Space>** Rope autocomplete
310+
ic Select inner class. Ex: vic, dic, yic, cic (normal, operator modes)
297311
-------------- -------------
298-
**<Leader>r** Run python
312+
am Select a function or method. Ex: vam, dam, yam, cam (normal, operator modes)
299313
-------------- -------------
300-
**<Leader>b** Set, unset breakpoint
314+
im Select inner function or method. Ex: vim, dim, yim, cim (normal, operator modes)
301315
============== =============
302316

303317
.. note:: See also ``:help ropevim.txt``

after/ftplugin/python.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,33 @@
22
if g:pymode && g:pymode_rope && g:pymode_rope_vim_completion
33
setlocal omnifunc=RopeOmni
44
endif
5+
6+
" Motion {{{
7+
8+
if !pymode#Default('g:pymode_motion', 1) || g:pymode_motion
9+
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>
31+
32+
endif
33+
34+
" }}}

autoload/pymode/motion.vim

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
fun! pymode#motion#block(lnum) "{{{
2+
let start = indent(a:lnum)
3+
let num = a:lnum
4+
while num
5+
let num = nextnonblank(num + 1)
6+
if num && indent(num) <= start
7+
return num - 1
8+
endif
9+
endwhile
10+
return line('$')
11+
endfunction "}}}
12+
13+
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
19+
endwhile
20+
return result
21+
endfunction "}}}
22+
23+
24+
fun! pymode#motion#vmove(pattern, flags) "{{{
25+
let end = pymode#motion#move(a:pattern, a:flags)
26+
normal! gv
27+
call cursor(end)
28+
endfunction "}}}
29+
30+
31+
fun! pymode#motion#pos_le(pos1, pos2) "{{{
32+
return ((a:pos1[0] < a:pos2[0]) || (a:pos1[0] == a:pos2[0] && a:pos1[1] <= a:pos2[1]))
33+
endfunction "}}}
34+
35+
36+
fun! pymode#motion#select(pattern, inner) "{{{
37+
let orig = getpos('.')[1:2]
38+
let start = pymode#motion#move(a:pattern, 'bW')
39+
let eline = pymode#motion#block(start[0])
40+
let end = [eline, len(getline(eline))]
41+
call cursor(orig)
42+
43+
if pymode#motion#pos_le(start, orig) && pymode#motion#pos_le(orig, end)
44+
if a:inner
45+
let start = [start[0] + 1, start[1]]
46+
let eline = prevnonblank(end[0])
47+
let end = [eline, len(getline(eline))]
48+
endif
49+
normal! v
50+
call cursor(start)
51+
normal! o
52+
call cursor(end)
53+
endif
54+
endfunction "}}}

doc/pymode.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ PythonMode. These options should be set in your vimrc.
8686
|'pymode_options_other'| Set default pymode options for
8787
python codding
8888

89+
|'pymode_motion'| Enable pymode motion stuff
8990

9091
Note:
9192
Also see |ropevim.txt|
@@ -285,6 +286,26 @@ If this option is set to 1, pymode enable next options for python buffers: >
285286
setlocal nowrap
286287
setlocal textwidth=80
287288
<
289+
------------------------------------------------------------------------------
290+
*'pymode_motion'*
291+
Values: 0 or 1.
292+
Default: 1.
293+
294+
If this option is set to 1, pymode enable some python motions. Pymode-motion
295+
is beta.
296+
297+
================ ============================
298+
Key Command
299+
================ ============================
300+
[[ Jump on previous class or function (normal, visual, operator modes)
301+
]] Jump on next class or function (normal, visual, operator modes)
302+
[m Jump on previous class or method (normal, visual, operator modes)
303+
]m Jump on next class or method (normal, visual, operator modes)
304+
ac Select a class. Ex: vac, dac, yac, cac (normal, operator modes)
305+
ic Select inner class. Ex: vic, dic, yic, cic (normal, operator modes)
306+
am Select a function or method. Ex: vam, dam, yam, cam (normal, operator modes)
307+
im Select inner function or method. Ex: vim, dim, yim, cim (normal, operator modes)
308+
================ ============================
288309

289310

290311
==============================================================================

ftplugin/python/pymode.vim

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ if !pymode#Default('g:pymode_syntax', 1) || g:pymode_syntax
77
let python_highlight_all=1
88
endif
99

10+
11+
" Options {{{
12+
1013
" Python indent options
1114
if !pymode#Default('g:pymode_options_indent', 1) || g:pymode_options_indent
1215
setlocal cinwords=if,elif,else,for,while,try,except,finally,def,class
@@ -27,7 +30,7 @@ if !pymode#Default('g:pymode_options_fold', 1) || g:pymode_options_fold
2730
setlocal foldlevel=99
2831
setlocal foldmethod=indent
2932
endif
30-
33+
3134
" Python other options
3235
if !pymode#Default('g:pymode_options_other', 1) || g:pymode_options_other
3336
setlocal complete+=t
@@ -37,6 +40,11 @@ if !pymode#Default('g:pymode_options_other', 1) || g:pymode_options_other
3740
setlocal textwidth=80
3841
endif
3942

43+
" }}}
44+
45+
46+
" Paths {{{
47+
4048
" Fix path for project
4149
if g:pymode
4250
py curpath = vim.eval('getcwd()')
@@ -48,7 +56,11 @@ if g:pymode_virtualenv && exists("$VIRTUAL_ENV")
4856
call pymode#virtualenv#Activate()
4957
endif
5058

51-
" Python documentation
59+
" }}}
60+
61+
62+
" Documentation {{{
63+
5264
if g:pymode_doc
5365

5466
" DESC: Set commands
@@ -59,6 +71,8 @@ if g:pymode_doc
5971

6072
endif
6173

74+
" }}}
75+
6276

6377
" PyLint
6478
if g:pymode_lint
@@ -86,7 +100,7 @@ if g:pymode_rope
86100
noremap <silent> <buffer> <C-c>m :emenu Rope.<TAB>
87101
inoremap <silent> <buffer> <S-TAB> <C-R>=RopeLuckyAssistInsertMode()<CR>
88102
89-
let s:prascm = g:pymode_rope_always_show_complete_menu ? "<C-P>" : ""
103+
let s:prascm = g:pymode_rope_always_show_complete_menu ? "<C-P>" : ""
90104
exe "inoremap <silent> <buffer> <Nul> <C-R>=RopeCodeAssistInsertMode()<CR>" . s:prascm
91105
exe "inoremap <silent> <buffer> <C-space> <C-R>=RopeCodeAssistInsertMode()<CR>" . s:prascm
92106

@@ -118,3 +132,5 @@ call pymode#Default("g:pymode_utils_whitespaces", 1)
118132
if g:pymode_utils_whitespaces
119133
au BufWritePre <buffer> :call setline(1,map(getline(1,"$"),'substitute(v:val,"\\s\\+$","","")'))
120134
endif
135+
136+
" vim: fdm=marker:fdl=0

plugin/pymode.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let g:pymode_version = "0.4.8"
1+
let g:pymode_version = "0.5.0"
22

33
com! PymodeVersion echomsg "Current python-mode version: " . g:pymode_version
44

0 commit comments

Comments
 (0)