|
1 | 1 | " DESC: Save file if it modified and run python code |
2 | 2 | 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 |
4 | 11 | 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') |
6 | 15 | call pymode#WideMessage("Code running.") |
7 | 16 | try |
| 17 | + call setqflist([]) |
8 | 18 | 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 |
14 | 37 |
|
15 | 38 | catch /.*/ |
16 | 39 |
|
|
0 commit comments