Merge pull request #3 from roman/381d40d7482c98b228cc3652f76036951c9ac5ac

Adding support for the latest version of vimshell
This commit is contained in:
ujihisa 2011-07-21 11:28:52 -07:00
commit c89ef290b7

View File

@ -14,28 +14,50 @@ function! Repl()
endif
endfunction
function! s:CreateReplContext()
let l:context = {
\ 'fd': { 'stdin' : '', 'stdout' : '', 'stderr' : '' },
\ 'is_interactive' : 0,
\ 'is_single_command' : 1,
\ 'is_close_immediately': 1
\ }
return l:context
endfunction
function! s:CallVimShell(args)
let l:context = s:CreateReplContext()
call vimshell#commands#iexe#init()
call vimshell#set_context(l:context)
call vimshell#execute_internal_command(
\ 'iexe', vimproc#parser#split_args(a:args),
\ l:context.fd,
\ l:context)
let b:interactive.is_close_immediately = 1
endfunction
function! ReplRuby()
let l:contents = getline(0, expand('$'))
let l:args = 'irb --simple-prompt'
call vimshell#execute_internal_command(
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' },
\ { 'is_interactive' : 0, 'is_single_command' : 1 })
let b:interactive.is_close_immediately = 1
call s:CallVimShell(l:args)
" We pass the ruby program as strings to the
" REPL
for l:line in l:contents
call vimshell#interactive#send_string(l:line . "\n")
call vimshell#interactive#send_string(l:line . "\n", 1)
endfor
endfunction
function! ReplHaskell()
" Setting up the obj file for the current file
let l:tmpfile = tempname() . '.hs'
let l:tmpobj = tempname() . '.o'
call writefile(getline(1, expand('$')), l:tmpfile, 'b')
call vimproc#system('ghc ' . l:tmpfile . ' -o ' . l:tmpobj)
let l:args = 'ghci ' . l:tmpfile
call vimshell#execute_internal_command(
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' },
\ { 'is_interactive' : 0, 'is_single_command' : 1 })
let b:interactive.is_close_immediately = 1
call s:CallVimShell(l:args)
endfunction
function! ReplErlang()
@ -51,36 +73,29 @@ function! ReplErlang()
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' },
\ { 'is_interactive' : 0, 'is_single_command' : 1 })
let b:interactive.is_close_immediately = 1
call vimshell#interactive#send_string(printf("c('%s').\n", l:tmppath))
call vimshell#interactive#send_string(printf("c('%s').\n", l:tmppath), 1)
endfunction
function! ReplPython()
let l:currentFile = expand('%:r') " current file without the extension
let l:args = 'python -'
call vimshell#execute_internal_command(
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin': '', 'stdout': '', 'stderr': '' },
\ { 'is_interactive' : 0, 'is_single_command' : 1 })
let b:interactive.is_close_immediately = 1
call vimshell#interactive#send_string("from " . l:currentFile . " import *\n")
call s:CallVimShell(l:args)
call vimshell#interactive#send_string(
\ "from " . l:currentFile . " import *\n",
\1)
endfunction
function! ReplScala()
let l:currentFile = expand('%')
let l:args = 'scala -i ' . l:currentFile
call vimshell#execute_internal_command(
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' },
\ { 'is_interactive' : 0, 'is_single_command' : 1 })
let b:interactive.is_close_immediately = 1
endfunction
function! ReplClojure()
let l:currentFile = expand('%')
let l:args = 'clj -i ' . l:currentFile . ' -r'
call vimshell#execute_internal_command(
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' },
\ { 'is_interactive' : 0, 'is_single_command' : 1 })
let b:interactive.is_close_immediately = 1
endfunction
"function! ReplScala()
" let l:currentFile = expand('%')
" let l:args = 'scala -i ' . l:currentFile
" call s:CallVimShell(l:args)
"endfunction
"
"function! ReplClojure()
" let l:currentFile = expand('%')
" let l:args = 'clj -i ' . l:currentFile . ' -r'
" call s:CallVimShell(l:args)
"endfunction
command! -nargs=0 Repl call Repl()
nnoremap <Space>i :<C-u>Repl<Cr>