Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f620354
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# quickinteractive.vim | ||
|
||
Open the interactive environment with the code you are writing. | ||
|
||
## Ruby Example | ||
|
||
You are writing the following code in an unnamed buffer. | ||
|
||
class C | ||
def self.f(x) | ||
x + 1 | ||
end | ||
end | ||
|
||
Now you want to try running the code in an interactive environment. Usually you are supposed to (1) save the code on somewhere, (2) open a terminal, (3) run `irb -r {the-file}`. | ||
|
||
If you already installed quickinteractive.vim, you just have to run `:QuickInteractive` or to type `<space>i`. It opens a buffer that is the environment you wanted. | ||
|
||
irb> | ||
|
||
You can do | ||
|
||
irb> C.f 23 | ||
24 | ||
irb> | ||
|
||
## Haskell Example | ||
|
||
import Test.HUnit | ||
foo _ = (1, 2) | ||
test1 = TestCase (assertEqual "for (foo 3)," (1,2) (foo 3)) | ||
tests = TestList [TestLabel "test1" test1] | ||
|
||
Run `:QuickInteractive` without saving the code on a file. | ||
|
||
ghci> runTestTT tests | ||
|
||
## Installation | ||
|
||
$ jolt install quickinteractive | ||
|
||
will be available soon. | ||
|
||
This plugin depends on quickrun, vimshell and their dependencies. | ||
|
||
## Author | ||
|
||
Tatsuhiro Ujihisa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function! QuickInteractive() | ||
if &filetype == 'ruby' | ||
call QuickInteractiveRuby() | ||
elseif &filetype == 'haskell' | ||
call QuickInteractiveHaskell() | ||
endif | ||
endfunction | ||
|
||
function! QuickInteractiveRuby() | ||
let l:tmpfile = tempname() . '.rb' | ||
call writefile(getline(1, expand('$')), l:tmpfile, 'b') | ||
let l:args = 'irb --simple-prompt -r ' . l:tmpfile | ||
call vimshell#execute_internal_command( | ||
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, | ||
\ { 'is_interactive' : 0, 'is_from_command' : 1 }) | ||
endfunction | ||
|
||
function! QuickInteractiveHaskell() | ||
let l:tmpfile = tempname() . '.hs' | ||
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 = 'ghci ' . l:tmpfile | ||
call vimshell#execute_internal_command( | ||
\ 'iexe', vimproc#parser#split_args(l:args), { 'stdin' : '', 'stdout' : '', 'stderr' : '' }, | ||
\ { 'is_interactive' : 0, 'is_from_command' : 1 }) | ||
endfunction | ||
|
||
|
||
command! -nargs=0 QuickInteractive call QuickInteractive() | ||
nnoremap <Space>i :<C-u>QuickInteractive<Cr> |