Skip to content

Commit dc3f408

Browse files
committed
Fix code run
1 parent ae7abda commit dc3f408

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
*.pyc
1+
*.py[cod]
2+
*.sw?
3+
*~
24
.DS_Store
35
.ropeproject
46
tags

autoload/pymode/run.vim

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
" DESC: Save file if it modified and run python code
22
fun! pymode#run#Run(line1, line2) "{{{
3-
if &modifiable && &modified | write | endif
3+
if &modifiable && &modified
4+
try
5+
write
6+
catch /E212/
7+
echohl Error | echo "File modified and I can't save it. Cancel code checking." | echohl None
8+
return 0
9+
endtry
10+
endif
411
py import StringIO
5-
py sys.stdout, _ = StringIO.StringIO(), sys.stdout
12+
py sys.stdout, stdout_ = StringIO.StringIO(), sys.stdout
13+
py sys.stderr, stderr_ = StringIO.StringIO(), sys.stderr
14+
py enc = vim.eval('&enc')
615
call pymode#WideMessage("Code running.")
716
try
17+
call setqflist([])
818
py execfile(vim.eval('expand("%s:p")'))
9-
py sys.stdout, out = _, sys.stdout.getvalue()
10-
call pymode#TempBuffer()
11-
py vim.current.buffer.append(out.split('\n'), 0)
12-
wincmd p
13-
call pymode#WideMessage("")
19+
py out, err = sys.stdout.getvalue().strip(), sys.stderr.getvalue()
20+
py sys.stdout, sys.stderr = stdout_, stderr_
21+
22+
cexpr ""
23+
py for x in err.strip().split('\n'): vim.command('caddexpr "' + x.replace('"', r'\"') + '"')
24+
let l:oldefm = &efm
25+
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
26+
call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, 0)
27+
let &efm = l:oldefm
28+
29+
python << EOF
30+
if out:
31+
vim.command("call pymode#TempBuffer()")
32+
vim.current.buffer.append([x.encode(enc) for x in out.split('\n')], 0)
33+
vim.command("wincmd p")
34+
else:
35+
vim.command('call pymode#WideMessage("No output.")')
36+
EOF
1437

1538
catch /.*/
1639

0 commit comments

Comments
 (0)