Skip to content

Commit d80cf6e

Browse files
authored
Merge pull request #60 from claudiocabral/vim_terminal
Use vim terminal instead of standalone terminal window
2 parents a39ef2a + 13472e8 commit d80cf6e

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ The following variables are available for configuration in your `.vimrc` file:
9999
| `g:scFlash` | Highlighting of evaluated code | `0` |
100100
| `g:scSplitDirection` | Default window orientation when using a terminal multiplexer | `"h"` |
101101
| `g:scSplitSize` | Post window size (% of screen) when using a terminal multiplexer | `50` |
102+
| `g:scTerminalBuffer` | If set to `"on"` use vim's `:term` to launch `g:sclangTerm` | `"off"` |
102103

103104
Example `.vimrc` line for gnome-terminal users:
104105

ftplugin/supercollider.vim

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ if exists("g:scSplitSize")
7878
let s:scSplitSize = g:scSplitSize
7979
endif
8080

81+
82+
let s:scTerminalBuffer = "off"
83+
if exists("g:scTerminalBuffer")
84+
let s:scTerminalBuffer = g:scTerminalBuffer
85+
endif
86+
8187
" ========================================================================================
8288

8389
function! FindOuterMostBlock()
@@ -219,13 +225,39 @@ endfunction
219225

220226
let s:sclangStarted = 0
221227

228+
function s:TerminalEnabled()
229+
return exists(":term") && (s:scTerminalBuffer == "on")
230+
endfunction
231+
232+
function s:KillSClangBuffer()
233+
if bufexists(bufname('start_pipe'))
234+
exec 'bd! start_pipe'
235+
endif
236+
endfunction
237+
222238
function SClangStart(...)
223239
let l:tmux = exists('$TMUX')
224240
let l:screen = exists('$STY')
225-
if l:tmux || l:screen
226-
let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection
227-
let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize
228-
241+
let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection
242+
let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize
243+
if s:TerminalEnabled()
244+
let l:term = ":term "
245+
if !has("nvim")
246+
let l:term .= "++curwin ++close "
247+
endif
248+
let l:isVertical = l:splitDir == "v"
249+
let l:splitCmd = (l:isVertical) ? "vsplit" : "split"
250+
let l:resizeCmd = (l:isVertical) ? "vertical resize " : "resize "
251+
vsplit
252+
wincmd w
253+
call s:KillSClangBuffer()
254+
exec "vertical resize " .(l:splitSize * 2) ."%"
255+
exec "set wfw"
256+
exec "set wfh"
257+
exec l:term .s:sclangPipeApp
258+
exec "normal G"
259+
wincmd w
260+
elseif l:tmux || l:screen
229261
if l:tmux
230262
let l:cmd = "tmux split-window -" . l:splitDir . " -p " . l:splitSize . " ;"
231263
let l:cmd .= "tmux send-keys " . s:sclangPipeApp . " Enter ; tmux select-pane -l"
@@ -241,16 +273,17 @@ function SClangStart(...)
241273
call system("screen -S " . l:screenName . " -X resize " . l:splitSize . '%')
242274
call system("screen -S " . l:screenName . " -X bindkey -k k5")
243275
endif
244-
245276
else
246277
call system(s:sclangTerm . " " . s:sclangPipeApp . "&")
247278
endif
248-
249279
let s:sclangStarted = 1
250280
endfunction
251281

252282
function SClangKill()
253283
call system(s:sclangDispatcher . " -q")
284+
if has("nvim")
285+
call s:KillSClangBuffer()
286+
endif
254287
endfunction
255288

256289
function SClangKillIfStarted()

0 commit comments

Comments
 (0)