From 5ab8e708a50205d9599d506ca82bf939780e1d3a Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 4 Feb 2016 21:43:00 -0800 Subject: [PATCH] Changes to support js with the node repl. --- README.md | 1 + autoload/repl.vim | 2 ++ autoload/repl/javascript.vim | 24 ++++++++++++++++++++++++ doc/repl.jax | 1 + plugin/repl.vim | 4 ++++ test/repl_vim.vim | 1 + 6 files changed, 33 insertions(+) create mode 100644 autoload/repl/javascript.vim diff --git a/README.md b/README.md index 80dc800..512d991 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/autoload/repl.vim b/autoload/repl.vim index 1826b7e..8faf61c 100644 --- a/autoload/repl.vim +++ b/autoload/repl.vim @@ -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 diff --git a/autoload/repl/javascript.vim b/autoload/repl/javascript.vim new file mode 100644 index 0000000..5c3e52a --- /dev/null +++ b/autoload/repl/javascript.vim @@ -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 diff --git a/doc/repl.jax b/doc/repl.jax index b3c7786..dd29b0b 100644 --- a/doc/repl.jax +++ b/doc/repl.jax @@ -73,6 +73,7 @@ https://github.com/user/repl.vim * Haskell * Python (2 or 3) * Erlang +* Javascript ============================================================================== 使い方 *repl-usage* diff --git a/plugin/repl.vim b/plugin/repl.vim index a3d4377..d6caf08 100644 --- a/plugin/repl.vim +++ b/plugin/repl.vim @@ -24,6 +24,10 @@ let g:repl#default_filetype_repl = { \ 'erlang' : { \ 'repl' : 'erl', \ 'opt' : '' +\ }, +\ 'javascript' : { +\ 'repl' : 'node', +\ 'opt' : '-i' \ } \} diff --git a/test/repl_vim.vim b/test/repl_vim.vim index 0e89ea6..cf466b8 100644 --- a/test/repl_vim.vim +++ b/test/repl_vim.vim @@ -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