Split filetype files
This commit is contained in:
parent
5e074a331c
commit
5748db0ed0
@ -2,167 +2,27 @@ scriptencoding utf-8
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
"-------------------"
|
||||
"TODO: Branch python2 and python3
|
||||
"TODO: DRY
|
||||
|
||||
|
||||
function! s:echo_error(msg) abort
|
||||
function! repl#echo_error(msg) abort
|
||||
echohl Error
|
||||
echomsg a:msg
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
"function! s:CallVimShell(args)
|
||||
" execute ':VimShellInteractive' a:args
|
||||
"endfunction
|
||||
|
||||
"#-=- -=- -=- -=- -=- -=- -=- -=- -=-#"
|
||||
|
||||
function! repl#run_repl() abort
|
||||
if &filetype ==# 'ruby'
|
||||
call repl#start_ruby()
|
||||
call repl#ruby#open_repl()
|
||||
elseif &filetype ==# 'haskell'
|
||||
call repl#start_haskell()
|
||||
call repl#haskell#open_repl()
|
||||
elseif &filetype ==# 'erlang'
|
||||
call repl#start_erlang()
|
||||
call repl#erlang#open_repl()
|
||||
elseif &filetype ==# 'python'
|
||||
call repl#start_python()
|
||||
elseif &filetype ==# 'scala'
|
||||
call s:echo_error("Sorry, repl.vim didn't support this filetype")
|
||||
"call ReplScala()
|
||||
elseif &filetype ==# 'clojure'
|
||||
call s:echo_error("Sorry, repl.vim didn't support this filetype")
|
||||
"call ReplClojure()
|
||||
call repl#python#open_repl()
|
||||
else
|
||||
call s:echo_error("Sorry, repl.vim didn't support this filetype")
|
||||
call repl#echo_error("Sorry, repl.vim didn't support this filetype")
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"#-=- -=- -=- -=- -=- -=- -=- -=- -=-#"
|
||||
|
||||
function! repl#start_ruby() abort
|
||||
" Setting up the obj file for the current file
|
||||
if &modified
|
||||
let l:module_file = tempname() . '.rb'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.ruby.repl', g:repl#default_filetype_repl.ruby['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.ruby.opt', g:repl#default_filetype_repl.ruby['opt'])
|
||||
if !executable(l:repl)
|
||||
call s:echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
execute ':VimShellInteractive' l:args
|
||||
endfunction
|
||||
|
||||
function! repl#start_haskell() abort
|
||||
" Setting up the file for the current file
|
||||
if &modified
|
||||
" Create new file temporary
|
||||
let l:module_file = tempname() . '.hs'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.haskell.repl', g:repl#default_filetype_repl.haskell['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.haskell.opt', g:repl#default_filetype_repl.haskell['opt'])
|
||||
if !executable(l:repl)
|
||||
call s:echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
execute ':VimShellInteractive' l:args
|
||||
endfunction
|
||||
|
||||
function! repl#start_python() abort
|
||||
" Setting up the file for the current file
|
||||
if &modified
|
||||
" Create new file temporary
|
||||
let l:module_file = tempname() . '.py'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.python.repl', g:repl#default_filetype_repl.python['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.python.opt', g:repl#default_filetype_repl.python['opt'])
|
||||
if !executable(l:repl)
|
||||
call s:echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
execute ':VimShellInteractive' l:args
|
||||
endfunction
|
||||
|
||||
|
||||
function! repl#start_erlang() abort
|
||||
" 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 s:echo_error('REPL_VIM: fatal error')
|
||||
call s: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 s:echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
|
||||
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('%')
|
||||
" 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
|
||||
|
||||
"-------------------"
|
||||
|
||||
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
|
||||
|
||||
"-------------------"
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
53
autoload/repl/erlang.vim
Normal file
53
autoload/repl/erlang.vim
Normal file
@ -0,0 +1,53 @@
|
||||
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
|
||||
|
||||
"#--- --- ---#"
|
||||
|
||||
function! repl#start_erlang() abort
|
||||
" 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
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
|
||||
execute ':VimShellInteractive' l:args
|
||||
call vimshell#interactive#send(printf('c(%s).', fnamemodify(l:module_file, ':t:r')))
|
||||
execute 'cd' l:pwd
|
||||
endfunction
|
21
autoload/repl/haskell.vim
Normal file
21
autoload/repl/haskell.vim
Normal file
@ -0,0 +1,21 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
function! repl#haskell#open_repl() abort
|
||||
" Setting up the file for the current file
|
||||
if &modified
|
||||
" Create new file temporary
|
||||
let l:module_file = tempname() . '.hs'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.haskell.repl', g:repl#default_filetype_repl.haskell['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.haskell.opt', g:repl#default_filetype_repl.haskell['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
execute ':VimShellInteractive' l:args
|
||||
endfunction
|
21
autoload/repl/python.vim
Normal file
21
autoload/repl/python.vim
Normal file
@ -0,0 +1,21 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
function! repl#python#open_repl() abort
|
||||
" Setting up the file for the current file
|
||||
if &modified
|
||||
" Create new file temporary
|
||||
let l:module_file = tempname() . '.py'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.python.repl', g:repl#default_filetype_repl.python['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.python.opt', g:repl#default_filetype_repl.python['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
execute ':VimShellInteractive' l:args
|
||||
endfunction
|
20
autoload/repl/ruby.vim
Normal file
20
autoload/repl/ruby.vim
Normal file
@ -0,0 +1,20 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
function! repl#ruby#open_repl() abort
|
||||
" Setting up the obj file for the current file
|
||||
if &modified
|
||||
let l:module_file = tempname() . '.rb'
|
||||
call writefile(getline(1, expand('$')), l:module_file)
|
||||
else
|
||||
let l:module_file = expand('%:p')
|
||||
endif
|
||||
|
||||
let l:repl = get(g:, 'repl_filetype_repl.ruby.repl', g:repl#default_filetype_repl.ruby['repl'])
|
||||
let l:opt = get(g:, 'repl_filetype_repl.ruby.opt', g:repl#default_filetype_repl.ruby['opt'])
|
||||
if !executable(l:repl)
|
||||
call repl#echo_error(printf("You don't have repl: '%s'", l:repl))
|
||||
return
|
||||
endif
|
||||
let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file)
|
||||
execute ':VimShellInteractive' l:args
|
||||
endfunction
|
Reference in New Issue
Block a user