Skip to content

Commit ec56898

Browse files
committed
Merge pull request python-mode#273 from codito/extract-python-execute
Extract python execute
2 parents 228053d + 225508d commit ec56898

File tree

8 files changed

+50
-35
lines changed

8 files changed

+50
-35
lines changed

autoload/pymode.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ 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+
1522
fun! pymode#Option(name) "{{{
1623

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

autoload/pymode/doc.vim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ fun! pymode#doc#Show(word) "{{{
55
if a:word == ''
66
echoerr "No name/symbol under cursor!"
77
else
8-
py import StringIO
9-
py sys.stdout, _ = StringIO.StringIO(), sys.stdout
10-
py help(vim.eval('a:word'))
11-
py sys.stdout, out = _, sys.stdout.getvalue()
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()")
1212
call pymode#TempBuffer()
13-
py vim.current.buffer.append(str(out).split('\n'), 0)
13+
call pymode#Execute("vim.current.buffer.append(str(out).splitlines(), 0)")
1414
wincmd p
1515
endif
1616
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-
py from pymode import lint
18-
py lint.check_file()
17+
call pymode#Execute("from pymode import lint")
18+
call pymode#Execute("lint.check_file()")
1919

2020
endfunction " }}}
2121

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

autoload/pymode/path.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 "}}}

autoload/pymode/queue.vim

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

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

67
" Update interval
78
if mode() == 'i'

autoload/pymode/run.vim

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,24 @@ fun! pymode#run#Run(line1, line2) "{{{
88
return 0
99
endtry
1010
endif
11-
py import StringIO
12-
py sys.stdout, stdout_ = StringIO.StringIO(), sys.stdout
13-
py sys.stderr, stderr_ = StringIO.StringIO(), sys.stderr
14-
py enc = vim.eval('&enc')
11+
call pymode#Execute("import StringIO")
12+
call pymode#Execute("sys.stdout, stdout_ = StringIO.StringIO(), sys.stdout")
13+
call pymode#Execute("sys.stderr, stderr_ = StringIO.StringIO(), sys.stderr")
14+
call pymode#Execute("enc = vim.eval('&enc')")
1515
call setqflist([])
1616
call pymode#WideMessage("Code running.")
1717
try
18-
py context = globals()
19-
py context['raw_input'] = context['input'] = lambda s: vim.eval('input("{0}")'.format(s))
20-
py execfile(vim.eval('expand("%:p")'), context)
21-
py out, err = sys.stdout.getvalue().strip(), sys.stderr.getvalue()
22-
py sys.stdout, sys.stderr = stdout_, stderr_
18+
call pymode#Execute("context = globals()")
19+
call pymode#Execute("context['raw_input'] = context['input'] = lambda s: vim.eval('input(\"{0}\")'.format(s))")
20+
call pymode#Execute("execfile(vim.eval('expand(\"%:p\")'), context)")
21+
call pymode#Execute("out, err = sys.stdout.getvalue().strip(), sys.stderr.getvalue()")
22+
call pymode#Execute("sys.stdout, sys.stderr = stdout_, stderr_")
2323

2424
cexpr ""
25-
py for x in err.strip().split('\n'): vim.command('caddexpr "' + x.replace('"', r'\"') + '"')
25+
python << EOF
26+
for x in err.strip().split('\n'):
27+
vim.command('caddexpr "' + x.replace('"', r'\"') + '"')
28+
EOF
2629
let l:oldefm = &efm
2730
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
2831
call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, 0)

ftplugin/python/init-pymode.vim

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,7 @@ endif
4242
if !pymode#Default('g:pymode_path', 1) || g:pymode_path
4343

4444
call pymode#Default('g:pymode_paths', [])
45-
46-
python << EOF
47-
import sys, vim, os
48-
49-
curpath = vim.eval("getcwd()")
50-
libpath = os.path.join(vim.eval("expand('<sfile>:p:h:h:h')"), 'pylibs')
51-
52-
sys.path = [libpath, curpath] + vim.eval("g:pymode_paths") + sys.path
53-
EOF
45+
call pymode#path#Activate(expand("<sfile>:p:h:h:h"))
5446

5547
endif " }}}
5648

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

133-
py from pymode import queue
125+
call pymode#Execute("from pymode import queue")
134126

135-
au VimLeavePre * py queue.stop_queue()
127+
au VimLeavePre * call pymode#Execute("queue.stop_queue()")
136128

137129
endif
138130

@@ -252,7 +244,7 @@ if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
252244
call pymode#Default("g:pymode_rope_always_show_complete_menu", 0)
253245

254246
" DESC: Init Rope
255-
py import ropevim
247+
call pymode#Execute("import ropevim")
256248

257249
fun! RopeCodeAssistInsertMode() "{{{
258250
call RopeCodeAssist()
@@ -263,7 +255,7 @@ if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
263255
if isdirectory(getcwd() . '/.ropeproject')
264256
" In order to pass it the quiet kwarg I need to open the project
265257
" using python and not vim, which should be no major issue
266-
py ropevim._interface.open_project(quiet=True)
258+
call pymode#Execute("ropevim._interface.open_project(quiet=True)")
267259
return ""
268260
endif
269261
endfunction "}}}
@@ -275,7 +267,7 @@ if !pymode#Default("g:pymode_rope", 1) || g:pymode_rope
275267

276268
fun! RopeOmni(findstart, base) "{{{
277269
if a:findstart
278-
py ropevim._interface._find_start()
270+
call pymode#Execute("ropevim._interface._find_start()")
279271
return g:pymode_offset
280272
else
281273
call RopeOmniComplete()

ftplugin/python/pymode.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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> py queue.stop_queue()
79+
au BufLeave <buffer> call pymode#Execute("queue.stop_queue()")
8080

8181
endif
8282

0 commit comments

Comments
 (0)