Merge pull request #4 from bounceme/master
Changes to support js with the node repl.
This commit is contained in:
commit
611356a709
@ -43,6 +43,7 @@ Run `:Repl` without saving the code on a file.
|
||||
* Haskell
|
||||
* Python (You can chose python2 or python3 interpreter)
|
||||
* Erlang
|
||||
* JavaScript
|
||||
|
||||
## Installation
|
||||
|
||||
|
@ -18,6 +18,8 @@ function! repl#run_repl() abort
|
||||
call repl#erlang#open_repl()
|
||||
elseif &filetype ==# 'python'
|
||||
call repl#python#open_repl()
|
||||
elseif &filetype ==# 'javascript'
|
||||
call repl#javascript#open_repl()
|
||||
else
|
||||
call repl#echo_error("Sorry, repl.vim didn't support this filetype")
|
||||
endif
|
||||
|
24
autoload/repl/javascript.vim
Normal file
24
autoload/repl/javascript.vim
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
function! repl#javascript#open_repl() abort
|
||||
" Setting up the file for the current file
|
||||
if &modified
|
||||
" Create new file temporary
|
||||
let l:module_file = tempname() . '.js'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = repl#get_filetype_repl('javascript')
|
||||
let l:exec_name = split(l:repl['repl'], ' ')[0]
|
||||
if !executable(l:exec_name)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:exec_name))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s', l:repl['repl'], l:repl['opt'])
|
||||
let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command)
|
||||
execute l:vimshell_interactive l:args
|
||||
call vimshell#interactive#send('.load ' . l:module_file)
|
||||
endfunction
|
@ -73,6 +73,7 @@ https://github.com/user/repl.vim
|
||||
* Haskell
|
||||
* Python (2 or 3)
|
||||
* Erlang
|
||||
* Javascript
|
||||
|
||||
==============================================================================
|
||||
使い方 *repl-usage*
|
||||
|
@ -24,6 +24,10 @@ let g:repl#default_filetype_repl = {
|
||||
\ 'erlang' : {
|
||||
\ 'repl' : 'erl',
|
||||
\ 'opt' : ''
|
||||
\ },
|
||||
\ 'javascript' : {
|
||||
\ 'repl' : 'node',
|
||||
\ 'opt' : '-i'
|
||||
\ }
|
||||
\}
|
||||
|
||||
|
@ -12,6 +12,7 @@ function! s:suite.do_not_throw_exception_when_open_repl()
|
||||
setfiletype haskell | Repl | new
|
||||
setfiletype erlang | Repl | new
|
||||
setfiletype python | Repl | new
|
||||
setfiletype javascript | Repl | new
|
||||
" repl.vim cannot open repl
|
||||
" but repl.vim don't throw some exception
|
||||
setfiletype unknown | Repl
|
||||
|
Reference in New Issue
Block a user