From a69d896f9b5b1ae3116b82a8ac7eb89442aa1792 Mon Sep 17 00:00:00 2001 From: aiya000 Date: Thu, 17 Dec 2015 16:59:45 +0900 Subject: [PATCH] Support Erlang (erl) --- README.md | 3 --- autoload/repl.vim | 42 +++++++++++++++++++++++++----------------- plugin/repl.vim | 4 ++++ 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ac48922..513a014 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,6 @@ Run `:Repl` without saving the code on a file. * Ruby * Haskell * Python (You can chose python2 or python3 interpreter) - -## TODO - * Erlang ## Installation diff --git a/autoload/repl.vim b/autoload/repl.vim index dc1825f..3392ee9 100644 --- a/autoload/repl.vim +++ b/autoload/repl.vim @@ -24,8 +24,7 @@ function! repl#run_repl() elseif &filetype ==# 'haskell' call repl#start_haskell() elseif &filetype ==# 'erlang' - call s:sorry() - "call ReplErlang() + call repl#start_erlang() elseif &filetype ==# 'python' call repl#start_python() elseif &filetype ==# 'scala' @@ -95,21 +94,30 @@ function! repl#start_python() endfunction -"function! ReplErlang() -" " FIXME: this function messes current directly with a .bean file. -" let l:modulename = get(matchlist(join(getline(1, line('$'))), '-module(\(.\{-}\))\.'), 1, "ujihisa") -" let l:tmppath = substitute(tempname(), "[^/]*$", l:modulename, '') -" let l:tmpfile = l:tmppath . '.erl' -" "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 = 'erl' -" 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(printf("c('%s').\n", l:tmppath), 1) -"endfunction +function! repl#start_erlang() + " FIXME: this function messes current directly with a .bean file. + " Setting up the file for the current file + if &modified + " Create new file temporary + let l:module_file = tempname() . '.erl' + call writefile(getline(1, expand('$')), l:module_file) + else + let l:module_file = expand('%:p') + endif + + let l:repl = exists('g:repl_filetype_repl.erlang') ? g:repl_filetype_repl.erlang['repl'] + \ : g:repl#default_filetype_repl.erlang['repl'] + let l:opt = exists('g:repl_filetype_repl.erlang') ? g:repl_filetype_repl.erlang['opt'] + \ : g:repl#default_filetype_repl.erlang['opt'] + let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file) + + " Change current directory temporary + let l:pwd = getcwd() + cd %:p:h + execute ':VimShellInteractive' l:args + call vimshell#interactive#send(printf('c(%s).', fnamemodify(l:module_file, ':t:r'))) + execute 'cd' l:pwd +endfunction "function! ReplScala() " let l:currentFile = expand('%') diff --git a/plugin/repl.vim b/plugin/repl.vim index 8254d89..74ee0a3 100644 --- a/plugin/repl.vim +++ b/plugin/repl.vim @@ -19,6 +19,10 @@ let g:repl#default_filetype_repl = get(g:, 'repl_filetype_repl', { \ 'python' : { \ 'repl' : 'python', \ 'opt' : '-i' +\ }, +\ 'erlang' : { +\ 'repl' : 'erl', +\ 'opt' : '' \ } \})