diff --git a/autoload/repl.vim b/autoload/repl.vim index b02d62b..1317c8b 100644 --- a/autoload/repl.vim +++ b/autoload/repl.vim @@ -23,6 +23,19 @@ function! repl#run_repl() abort endif endfunction +" Example: +" if you didn't set g:repl_filetype_repl +" echo repl#get_filetype_repl('python') +" => {'repl': 'python', 'opt': '-i'} +function! repl#get_filetype_repl(filetype) abort + if !exists('g:repl_filetype_repl') + return g:repl#default_filetype_repl[a:filetype] + endif + let l:filetype_repl = deepcopy(g:repl#default_filetype_repl) + call extend(l:filetype_repl, g:repl_filetype_repl) + return l:filetype_repl[a:filetype] +endfunction + "-------------------" let &cpo = s:save_cpo unlet s:save_cpo diff --git a/autoload/repl/erlang.vim b/autoload/repl/erlang.vim index ec4412f..99d63cd 100644 --- a/autoload/repl/erlang.vim +++ b/autoload/repl/erlang.vim @@ -39,13 +39,12 @@ function! repl#erlang#open_repl() abort 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)) + let l:repl = repl#get_filetype_repl('erlang') + if !executable(l:repl['repl']) + call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl'])) return endif - let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file) + let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file) let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command) execute l:vimshell_interactive l:args diff --git a/autoload/repl/haskell.vim b/autoload/repl/haskell.vim index 011919a..8737a66 100644 --- a/autoload/repl/haskell.vim +++ b/autoload/repl/haskell.vim @@ -10,13 +10,12 @@ function! repl#haskell#open_repl() abort 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)) + let l:repl = repl#get_filetype_repl('haskell') + if !executable(l:repl['repl']) + call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl'])) return endif - let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file) + let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file) let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command) execute l:vimshell_interactive l:args endfunction diff --git a/autoload/repl/python.vim b/autoload/repl/python.vim index 7f1a52f..5307401 100644 --- a/autoload/repl/python.vim +++ b/autoload/repl/python.vim @@ -10,13 +10,12 @@ function! repl#python#open_repl() abort 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)) + let l:repl = repl#get_filetype_repl('python') + if !executable(l:repl['repl']) + call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl'])) return endif - let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file) + let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file) let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command) execute l:vimshell_interactive l:args endfunction diff --git a/autoload/repl/ruby.vim b/autoload/repl/ruby.vim index f21eff8..44c4ddf 100644 --- a/autoload/repl/ruby.vim +++ b/autoload/repl/ruby.vim @@ -9,13 +9,12 @@ function! repl#ruby#open_repl() abort 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)) + let l:repl = repl#get_filetype_repl('ruby') + if !executable(l:repl['repl']) + call repl#echo_error(printf("You don't have repl: '%s'", l:repl['repl'])) return endif - let l:args = printf('%s %s %s', l:repl, l:opt, l:module_file) + let l:args = printf('%s %s %s', l:repl['repl'], l:repl['opt'], l:module_file) let l:vimshell_interactive = ':VimShellInteractive' . printf("--split='%s'", g:repl_split_command) execute l:vimshell_interactive l:args endfunction diff --git a/plugin/repl.vim b/plugin/repl.vim index 1bb6eb4..99efbb6 100644 --- a/plugin/repl.vim +++ b/plugin/repl.vim @@ -26,7 +26,6 @@ let g:repl#default_filetype_repl = { \ 'opt' : '' \ } \} -call extend(g:repl#default_filetype_repl, get(g:, 'repl_filetype_repl', {})) " 'split' or 'vertical split' let g:repl_split_command = get(g:, 'repl_split_command', 'split') diff --git a/test/can_open.vim b/test/can_open.vim index e6e6d6f..695e19f 100644 --- a/test/can_open.vim +++ b/test/can_open.vim @@ -1,4 +1,4 @@ -let s:suite = themis#suite('can_open') +let s:suite = themis#suite('can_open') function! s:suite.after_each() call UnletReplUserVariables() @@ -16,8 +16,3 @@ function! s:suite.some_repl() " but repl.vim don't throw some exception new | setfiletype unknown | Repl endfunction - -function! s:suite.some_repl_with_split_command() - let g:repl_split_command = 'vertical split' - call s:suite.some_repl() -endfunction diff --git a/test/variable.vim b/test/variable.vim new file mode 100644 index 0000000..cb97b89 --- /dev/null +++ b/test/variable.vim @@ -0,0 +1,32 @@ +let s:suite = themis#suite('variable') +let s:assert = themis#helper('assert') + +function! s:suite.after_each() + call UnletReplUserVariables() +endfunction + +"-------------------" + +function! s:suite.g_repl_filetype_repl_is_valid() + let l:TARGET_FILETYPE = 'ruby' | lockvar l:TARGET_FILETYPE + + " Default value + let l:DEFAULT_REPL_NAME = g:repl#default_filetype_repl[l:TARGET_FILETYPE]['repl'] | lockvar l:DEFAULT_REPL_NAME + let l:DEFAULT_REPL_OPT = g:repl#default_filetype_repl[l:TARGET_FILETYPE]['opt'] | lockvar l:DEFAULT_REPL_OPT + let l:filetype_repl = repl#get_filetype_repl(l:TARGET_FILETYPE) + call s:assert.equals(l:filetype_repl['repl'], l:DEFAULT_REPL_NAME) + call s:assert.equals(l:filetype_repl['opt'], l:DEFAULT_REPL_OPT) + + " Not a default value + let l:REPL_NAME = 'dummy' | lockvar l:REPL_NAME + let l:REPL_OPT = '--dummy' | lockvar l:REPL_OPT + let g:repl_filetype_repl = { + \ l:TARGET_FILETYPE : { + \ 'repl' : l:REPL_NAME, + \ 'opt' : l:REPL_OPT + \ } + \} + let l:filetype_repl = repl#get_filetype_repl(l:TARGET_FILETYPE) + call s:assert.equals(l:filetype_repl['repl'], l:REPL_NAME) + call s:assert.equals(l:filetype_repl['opt'], l:REPL_OPT) +endfunction