Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autoload/pymode.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ fun! pymode#Default(name, default) "{{{
endfunction "}}}


fun! pymode#Execute(expression) "{{{
" DESC: Execute an expression in the default python interpreter
"
execute 'python '.a:expression
endfunction "}}}


fun! pymode#Option(name) "{{{

let name = 'b:pymode_' . a:name
Expand Down
10 changes: 5 additions & 5 deletions autoload/pymode/doc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ fun! pymode#doc#Show(word) "{{{
if a:word == ''
echoerr "No name/symbol under cursor!"
else
py import StringIO
py sys.stdout, _ = StringIO.StringIO(), sys.stdout
py help(vim.eval('a:word'))
py sys.stdout, out = _, sys.stdout.getvalue()
call pymode#Execute("import StringIO")
call pymode#Execute("sys.stdout, _ = StringIO.StringIO(), sys.stdout")
call pymode#Execute("help('".a:word."')")
call pymode#Execute("sys.stdout, out = _, sys.stdout.getvalue()")
call pymode#TempBuffer()
py vim.current.buffer.append(str(out).split('\n'), 0)
call pymode#Execute("vim.current.buffer.append(str(out).splitlines(), 0)")
wincmd p
endif
endfunction "}}}
Expand Down
8 changes: 4 additions & 4 deletions autoload/pymode/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fun! pymode#lint#Check() "{{{

let g:pymode_lint_buffer = bufnr('%')

py from pymode import lint
py lint.check_file()
call pymode#Execute("from pymode import lint")
call pymode#Execute("lint.check_file()")

endfunction " }}}

Expand Down Expand Up @@ -100,8 +100,8 @@ fun! pymode#lint#Auto() "{{{
return 0
endtry
endif
py from pymode import auto
py auto.fix_current_file()
call pymode#Execute("from pymode import auto")
call pymode#Execute("auto.fix_current_file()")
cclose
edit
call pymode#WideMessage("AutoPep8 done.")
Expand Down
12 changes: 12 additions & 0 deletions autoload/pymode/path.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fun! pymode#path#Activate(plugin_root) "{{{

python << EOF
import sys, vim, os

curpath = vim.eval("getcwd()")
libpath = os.path.join(vim.eval("a:plugin_root"), 'pylibs')

sys.path = [libpath, curpath] + vim.eval("g:pymode_paths") + sys.path
EOF

endfunction "}}}
3 changes: 2 additions & 1 deletion autoload/pymode/queue.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
fun! pymode#queue#Poll() "{{{

" Check current tasks
py queue.check_task()
call pymode#Execute("from pymode import queue")
call pymode#Execute("queue.check_task()")

" Update interval
if mode() == 'i'
Expand Down
23 changes: 13 additions & 10 deletions autoload/pymode/run.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ fun! pymode#run#Run(line1, line2) "{{{
return 0
endtry
endif
py import StringIO
py sys.stdout, stdout_ = StringIO.StringIO(), sys.stdout
py sys.stderr, stderr_ = StringIO.StringIO(), sys.stderr
py enc = vim.eval('&enc')
call pymode#Execute("import StringIO")
call pymode#Execute("sys.stdout, stdout_ = StringIO.StringIO(), sys.stdout")
call pymode#Execute("sys.stderr, stderr_ = StringIO.StringIO(), sys.stderr")
call pymode#Execute("enc = vim.eval('&enc')")
call setqflist([])
call pymode#WideMessage("Code running.")
try
py context = globals()
py context['raw_input'] = context['input'] = lambda s: vim.eval('input("{0}")'.format(s))
py execfile(vim.eval('expand("%:p")'), context)
py out, err = sys.stdout.getvalue().strip(), sys.stderr.getvalue()
py sys.stdout, sys.stderr = stdout_, stderr_
call pymode#Execute("context = globals()")
call pymode#Execute("context['raw_input'] = context['input'] = lambda s: vim.eval('input(\"{0}\")'.format(s))")
call pymode#Execute("execfile(vim.eval('expand(\"%:p\")'), context)")
call pymode#Execute("out, err = sys.stdout.getvalue().strip(), sys.stderr.getvalue()")
call pymode#Execute("sys.stdout, sys.stderr = stdout_, stderr_")

cexpr ""
py for x in err.strip().split('\n'): vim.command('caddexpr "' + x.replace('"', r'\"') + '"')
python << EOF
for x in err.strip().split('\n'):
vim.command('caddexpr "' + x.replace('"', r'\"') + '"')
EOF
let l:oldefm = &efm
set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
call pymode#QuickfixOpen(0, g:pymode_lint_hold, g:pymode_lint_maxheight, g:pymode_lint_minheight, 0)
Expand Down
20 changes: 6 additions & 14 deletions ftplugin/python/init-pymode.vim
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ endif
if !pymode#Default('g:pymode_path', 1) || g:pymode_path

call pymode#Default('g:pymode_paths', [])

python << EOF
import sys, vim, os

curpath = vim.eval("getcwd()")
libpath = os.path.join(vim.eval("expand('<sfile>:p:h:h:h')"), 'pylibs')

sys.path = [libpath, curpath] + vim.eval("g:pymode_paths") + sys.path
EOF
call pymode#path#Activate(expand("<sfile>:p:h:h:h"))

endif " }}}

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

py from pymode import queue
call pymode#Execute("from pymode import queue")

au VimLeavePre * py queue.stop_queue()
au VimLeavePre * call pymode#Execute("queue.stop_queue()")

endif

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

" DESC: Init Rope
py import ropevim
call pymode#Execute("import ropevim")

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

fun! RopeOmni(findstart, base) "{{{
if a:findstart
py ropevim._interface._find_start()
call pymode#Execute("ropevim._interface._find_start()")
return g:pymode_offset
else
call RopeOmniComplete()
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/python/pymode.vim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if pymode#Option('lint')
" DESC: Run queue
let &l:updatetime = g:pymode_updatetime
au CursorHold <buffer> call pymode#queue#Poll()
au BufLeave <buffer> py queue.stop_queue()
au BufLeave <buffer> call pymode#Execute("queue.stop_queue()")

endif

Expand Down