This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
repl.vim/autoload/repl/erlang.vim

55 lines
1.9 KiB
VimL
Raw Normal View History

2015-12-20 10:53:58 +00:00
scriptencoding utf-8
"#-=- -=- -=- -=- -=- -=- -=- -=- -=-#"
function! s:writefile_with_erlang_module(lines, filepath) abort
let l:module_defined_line = match(a:lines, '-module')
if l:module_defined_line is -1
throw "REPL_VIM: repl.vim couldn't -module difinition !"
endif
let a:lines[l:module_defined_line] = printf('-module(%s).', fnamemodify(a:filepath, ':t:r'))
call writefile(a:lines, a:filepath)
endfunction
"#--- --- ---#"
2015-12-22 13:44:02 +00:00
function! repl#erlang#open_repl() abort
2015-12-20 10:53:58 +00:00
" FIXME: this function messes current directly with a .bean file.
let l:pwd = getcwd()
" Setting up the file for the current file
if &modified
" Create new file temporary
" -module don't allow module name number start
let l:tempname = tempname()
let l:filename = 't' . fnamemodify(l:tempname, ':t') . '.erl'
let l:dirpath = fnamemodify(l:tempname, ':h')
let l:module_file = l:dirpath . '/' . l:filename
try
call s:writefile_with_erlang_module(getline(1, expand('$')), l:module_file)
catch /^REPL_VIM/
call repl#echo_error('REPL_VIM: fatal error')
call repl#echo_error(v:exception)
return
endtry
" Change current directory temporary
execute 'cd' l:dirpath
else
let l:module_file = expand('%:p')
" Change current directory temporary
cd %:p:h
endif
let l:repl = get(g:, 'repl_filetype_repl.erlang.repl', g:repl#default_filetype_repl.erlang['repl'])
let l:opt = get(g:, 'repl_filetype_repl.erlang.opt', g:repl#default_filetype_repl.erlang['opt'])
if !executable(l:repl)
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
return
endif
2015-12-22 14:36:09 +00:00
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command)
2015-12-20 10:53:58 +00:00
2015-12-22 14:36:09 +00:00
execute l:vimshell_interactive l:args
2015-12-20 10:53:58 +00:00
call vimshell#interactive#send(printf('c(%s).', fnamemodify(l:module_file, ':t:r')))
execute 'cd' l:pwd
endfunction