Skip to content

Commit aa9d049

Browse files
committed
Prepare to python3 support
1 parent 7f9e3ad commit aa9d049

File tree

10 files changed

+45
-41
lines changed

10 files changed

+45
-41
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Contributors:
1111
* Denis Kasak (dkasak);
1212
* Steve Losh (sjl);
1313
* nixon;
14+
* lawrenceakka;
1415
* tramchamploo;
1516
* Benjamin Ruston (bruston);
1617
* Robert David Grant (bgrant);

autoload/pymode.vim

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ fun! pymode#Default(name, default) "{{{
1212
endfunction "}}}
1313

1414

15-
fun! pymode#Execute(expression) "{{{
16-
" DESC: Execute an expression in the default python interpreter
17-
"
18-
execute 'python '.a:expression
19-
endfunction "}}}
20-
21-
2215
fun! pymode#Option(name) "{{{
2316

2417
let name = 'b:pymode_' . a:name

autoload/pymode/breakpoint.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
" Quick set or delete a breakpoints
12
fun! pymode#breakpoint#Set(lnum) "{{{
23
let line = getline(a:lnum)
34
if strridx(line, g:pymode_breakpoint_cmd) != -1
@@ -8,7 +9,7 @@ fun! pymode#breakpoint#Set(lnum) "{{{
89
normal k
910
endif
1011

11-
" Save file
12+
" Save file without any events
1213
if &modifiable && &modified | noautocmd write | endif
1314

1415
endfunction "}}}

autoload/pymode/doc.vim

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ fun! pymode#doc#Show(word) "{{{
55
if a:word == ''
66
echoerr "No name/symbol under cursor!"
77
else
8-
call pymode#Execute("import StringIO")
9-
call pymode#Execute("sys.stdout, _ = StringIO.StringIO(), sys.stdout")
10-
call pymode#Execute("help('".a:word."')")
11-
call pymode#Execute("sys.stdout, out = _, sys.stdout.getvalue()")
8+
Python import StringIO
9+
Python sys.stdout, _ = StringIO.StringIO(), sys.stdout
10+
Python help(vim.eval('a:word'))
1211
call pymode#TempBuffer()
13-
call pymode#Execute("vim.current.buffer.append(str(out).splitlines(), 0)")
12+
Python vim.current.buffer.append(str(out).splitlines(), 0)
1413
wincmd p
1514
endif
1615
endfunction "}}}

autoload/pymode/lint.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fun! pymode#lint#Check() "{{{
1414

1515
let g:pymode_lint_buffer = bufnr('%')
1616

17-
call pymode#Execute("from pymode import lint")
18-
call pymode#Execute("lint.check_file()")
17+
Python from pymode import lint
18+
Python lint.check_file()
1919

2020
endfunction " }}}
2121

@@ -100,8 +100,8 @@ fun! pymode#lint#Auto() "{{{
100100
return 0
101101
endtry
102102
endif
103-
call pymode#Execute("from pymode import auto")
104-
call pymode#Execute("auto.fix_current_file()")
103+
Python from pymode import auto
104+
Python auto.fix_current_file()
105105
cclose
106106
edit
107107
call pymode#WideMessage("AutoPep8 done.")

autoload/pymode/path.vim

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
fun! pymode#path#Activate(plugin_root) "{{{
2-
3-
python << EOF
4-
import sys, vim, os
5-
6-
curpath = vim.eval("getcwd()")
7-
libpath = os.path.join(vim.eval("a:plugin_root"), 'pylibs')
8-
9-
sys.path = [libpath, curpath] + vim.eval("g:pymode_paths") + sys.path
10-
EOF
11-
12-
endfunction "}}}
1+
fun! pymode#path#Activate(plugin_root) "{{{
2+
3+
Python << EOF
4+
import sys, vim, os
5+
6+
pymode_lib = 'pylibs'
7+
8+
if sys.version >= (3, 0, 0):
9+
pymode_lib = 'pylibs3'
10+
11+
curpath = vim.eval("getcwd()")
12+
libpath = os.path.join(vim.eval("a:plugin_root"), pymode_lib)
13+
14+
sys.path = [libpath, curpath] + vim.eval("g:pymode_paths") + sys.path
15+
EOF
16+
17+
endfunction "}}}

autoload/pymode/queue.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fun! pymode#queue#Poll() "{{{
22

33
" Check current tasks
4-
call pymode#Execute("from pymode import queue")
5-
call pymode#Execute("queue.check_task()")
4+
Python from pymode import queue
5+
Python queue.check_task()
66

77
" Update interval
88
if mode() == 'i'

autoload/pymode/virtualenv.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fun! pymode#virtualenv#Activate() "{{{
1212

1313
call add(g:pymode_virtualenv_enabled, $VIRTUAL_ENV)
1414

15-
python << EOF
15+
Python << EOF
1616
import sys, vim, os
1717

1818
ve_dir = vim.eval('$VIRTUAL_ENV')

ftplugin/python/init-pymode.vim

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if pymode#Default('g:pymode', 1) || !g:pymode
1313
endif
1414

1515
" DESC: Check python support
16-
if !has('python')
16+
if !has('python') && !has('python3')
1717
let g:pymode_virtualenv = 0
1818
let g:pymode_path = 0
1919
let g:pymode_lint = 0
@@ -23,6 +23,11 @@ if !has('python')
2323
let g:pymode_run = 0
2424
endif
2525

26+
if has('python')
27+
command! -nargs=1 Python python <args>
28+
elseif has('python3')
29+
command! -nargs=1 Python python3 <args>
30+
end
2631

2732
" Virtualenv {{{
2833

@@ -122,9 +127,9 @@ if !pymode#Default("g:pymode_lint", 1) || g:pymode_lint
122127
let g:pymode_lint_config = expand("<sfile>:p:h:h:h") . "/pylint.ini"
123128
endif
124129

125-
call pymode#Execute("from pymode import queue")
130+
Python from pymode import queue
126131

127-
au VimLeavePre * call pymode#Execute("queue.stop_queue()")
132+
au VimLeavePre * Python queue.stop_queue()
128133

129134
endif
130135

@@ -149,7 +154,7 @@ if !pymode#Default("g:pymode_breakpoint", 1) || g:pymode_breakpoint
149154

150155
if !pymode#Default("g:pymode_breakpoint_cmd", "import pdb; pdb.set_trace() # XXX BREAKPOINT") && has("python")
151156

152-
python << EOF
157+
Python << EOF
153158
from imp import find_module
154159

155160
for module in ('pudb', 'ipdb'):
@@ -244,7 +249,7 @@ if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
244249
call pymode#Default("g:pymode_rope_always_show_complete_menu", 0)
245250

246251
" DESC: Init Rope
247-
call pymode#Execute("import ropevim")
252+
Python import ropevim
248253

249254
fun! RopeCodeAssistInsertMode() "{{{
250255
call RopeCodeAssist()
@@ -255,7 +260,7 @@ if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
255260
if isdirectory(getcwd() . '/.ropeproject')
256261
" In order to pass it the quiet kwarg I need to open the project
257262
" using python and not vim, which should be no major issue
258-
call pymode#Execute("ropevim._interface.open_project(quiet=True)")
263+
Python ropevim._interface.open_project(quiet=True)
259264
return ""
260265
endif
261266
endfunction "}}}
@@ -267,7 +272,7 @@ if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
267272

268273
fun! RopeOmni(findstart, base) "{{{
269274
if a:findstart
270-
call pymode#Execute("ropevim._interface._find_start()")
275+
Python ropevim._interface._find_start()
271276
return g:pymode_offset
272277
else
273278
call RopeOmniComplete()

ftplugin/python/pymode.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
runtime ftplugin/python/init-pymode.vim
22

3-
if pymode#Default('g:pymode', 1) || !g:pymode
3+
if !g:pymode
44
finish
55
endif
66

@@ -76,7 +76,7 @@ if pymode#Option('lint')
7676
" DESC: Run queue
7777
let &l:updatetime = g:pymode_updatetime
7878
au CursorHold <buffer> call pymode#queue#Poll()
79-
au BufLeave <buffer> call pymode#Execute("queue.stop_queue()")
79+
au BufLeave <buffer> Python queue.stop_queue()
8080

8181
endif
8282

0 commit comments

Comments
 (0)