From 5ef34e26c4dc638d2e52991cc674a0a6a2665796 Mon Sep 17 00:00:00 2001 From: Diogo Cordeiro Date: Sun, 18 Nov 2018 22:33:32 +0000 Subject: [PATCH] Add support to SWIProlog --- README.md | 1 + autoload/repl.vim | 2 ++ autoload/repl/prolog.vim | 22 ++++++++++++++++++++++ doc/repl.jax | 1 + plugin/repl.vim | 4 ++++ test/repl_vim.vim | 1 + 6 files changed, 31 insertions(+) create mode 100644 autoload/repl/prolog.vim diff --git a/README.md b/README.md index db31d6b..7515a77 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ Run `:Repl` without saving the code on a file. * Clojure * Idris * Racket +* SWIProlog ## Installation diff --git a/autoload/repl.vim b/autoload/repl.vim index cf41152..ba5ad79 100644 --- a/autoload/repl.vim +++ b/autoload/repl.vim @@ -26,6 +26,8 @@ function! repl#run_repl() abort call repl#idris#open_repl() elseif &filetype ==# 'scheme' call repl#scheme#open_repl() + elseif &filetype ==# 'swiprolog' + call repl#prolog#open_repl() else call repl#echo_error("Sorry, repl.vim didn't support this filetype") endif diff --git a/autoload/repl/prolog.vim b/autoload/repl/prolog.vim new file mode 100644 index 0000000..ff4cf7a --- /dev/null +++ b/autoload/repl/prolog.vim @@ -0,0 +1,22 @@ +scriptencoding utf-8 + +function! repl#prolog#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 = repl#get_filetype_repl('prolog') + 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 %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/doc/repl.jax b/doc/repl.jax index 0480ace..0662fb7 100644 --- a/doc/repl.jax +++ b/doc/repl.jax @@ -76,6 +76,7 @@ https://github.com/user/repl.vim * Javascript (node.js) * Idris * Scheme (racket) +* Prolog (swipl) ============================================================================== 使い方 *repl-usage* diff --git a/plugin/repl.vim b/plugin/repl.vim index 00688dc..3b77490 100644 --- a/plugin/repl.vim +++ b/plugin/repl.vim @@ -40,6 +40,10 @@ let g:repl#default_filetype_repl = { \ 'scheme' : { \ 'repl' : 'racket', \ 'opt' : '-i' +\ }, +\ 'prolog' : { +\ 'repl' : 'swipl', +\ 'opt' : '' \ } \} diff --git a/test/repl_vim.vim b/test/repl_vim.vim index 4036d4e..8ba2e4e 100644 --- a/test/repl_vim.vim +++ b/test/repl_vim.vim @@ -15,6 +15,7 @@ function! s:suite.do_not_throw_exception_when_open_repl() setfiletype javascript | Repl | new setfiletype clojure | Repl | new setfiletype idris | Repl | new + setfiletype swiprolog | Repl | new " repl.vim cannot open repl " but repl.vim don't throw some exception setfiletype unknown | Repl