From 686eaf57a9b0c3330d0feef04d8d908250702025 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 4 Oct 2019 08:57:14 +0200 Subject: [PATCH 01/14] make first prototype for vim internal terminal --- ftplugin/supercollider.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index ec8a6b6..56b7e2b 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -226,7 +226,7 @@ function SClangStart(...) let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize - if l:tmux + if l:tmuxclose let l:cmd = "tmux split-window -" . l:splitDir . " -p " . l:splitSize . " ;" let l:cmd .= "tmux send-keys " . s:sclangPipeApp . " Enter ; tmux select-pane -l" call system(l:cmd) @@ -242,8 +242,14 @@ function SClangStart(...) call system("screen -S " . l:screenName . " -X bindkey -k k5") endif - else - call system(s:sclangTerm . " " . s:sclangPipeApp . "&") + else "if has :term + vsplit + vertical resize 150% + wincmd w + term s:sclangPipeApp + wincmd w + "else + "call system(s:sclangTerm . " " . s:sclangPipeApp . "&") endif let s:sclangStarted = 1 From df3b81a23f37b55984b3ca5d683a77c5e0d5785a Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 4 Oct 2019 09:02:28 +0200 Subject: [PATCH 02/14] remove accidentally added close to tmux variable --- ftplugin/supercollider.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 56b7e2b..db99125 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -226,7 +226,7 @@ function SClangStart(...) let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize - if l:tmuxclose + if l:tmux let l:cmd = "tmux split-window -" . l:splitDir . " -p " . l:splitSize . " ;" let l:cmd .= "tmux send-keys " . s:sclangPipeApp . " Enter ; tmux select-pane -l" call system(l:cmd) From a5bbf662848ee16629a709c601b1508d8aa3c892 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 4 Oct 2019 09:17:34 +0200 Subject: [PATCH 03/14] concatenate term and s:sclangPipeApp --- ftplugin/supercollider.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index db99125..ec3a8fb 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -246,7 +246,7 @@ function SClangStart(...) vsplit vertical resize 150% wincmd w - term s:sclangPipeApp + exec 'term ' .s:sclangPipeApp wincmd w "else "call system(s:sclangTerm . " " . s:sclangPipeApp . "&") From fc29aaf205cf3db2aacb865a7b4ec1b2a3abf946 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 4 Oct 2019 09:27:56 +0200 Subject: [PATCH 04/14] call term conditionally --- ftplugin/supercollider.vim | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index ec3a8fb..21a90f9 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -241,17 +241,15 @@ function SClangStart(...) call system("screen -S " . l:screenName . " -X resize " . l:splitSize . '%') call system("screen -S " . l:screenName . " -X bindkey -k k5") endif - - else "if has :term + elseif exists(":term") vsplit vertical resize 150% wincmd w - exec 'term ' .s:sclangPipeApp + exec "term " .s:sclangPipeApp wincmd w - "else - "call system(s:sclangTerm . " " . s:sclangPipeApp . "&") + else + call system(s:sclangTerm . " " . s:sclangPipeApp . "&") endif - let s:sclangStarted = 1 endfunction From 303b7a978944878e716b3552d0acd65fd0403500 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 4 Oct 2019 09:42:26 +0200 Subject: [PATCH 05/14] let user configure split direction and window size This pull request runs sclangpipe app inside a vim terminal buffer, making scvim independent of tmux or screen. It automatically detects if a terminal buffer is available and reverts to the old behaviour in case it's not --- ftplugin/supercollider.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 21a90f9..4fea97c 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -222,10 +222,9 @@ let s:sclangStarted = 0 function SClangStart(...) let l:tmux = exists('$TMUX') let l:screen = exists('$STY') + let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection + let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize if l:tmux || l:screen - let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection - let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize - if l:tmux let l:cmd = "tmux split-window -" . l:splitDir . " -p " . l:splitSize . " ;" let l:cmd .= "tmux send-keys " . s:sclangPipeApp . " Enter ; tmux select-pane -l" @@ -242,9 +241,12 @@ function SClangStart(...) call system("screen -S " . l:screenName . " -X bindkey -k k5") endif elseif exists(":term") + let l:isVertical = l:splitDir == "v" + let l:splitCmd = (l:isVertical) ? "vsplit" : "split" + let l:resizeCmd = (l:isVertical) ? "vertical resize " : "resize " vsplit - vertical resize 150% wincmd w + exec "vertical resize " .(l:splitSize * 2) ."%" exec "term " .s:sclangPipeApp wincmd w else From 125cbc45373ae7c81f751c160d286940ed9319ad Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 4 Oct 2019 17:59:08 +0200 Subject: [PATCH 06/14] go to the end of window for auto scrolling --- ftplugin/supercollider.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 4fea97c..5ceb314 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -248,6 +248,7 @@ function SClangStart(...) wincmd w exec "vertical resize " .(l:splitSize * 2) ."%" exec "term " .s:sclangPipeApp + exec "normal G" wincmd w else call system(s:sclangTerm . " " . s:sclangPipeApp . "&") From 8bcd338f58a03180c0cd204a2f61a5ae5e023569 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Thu, 31 Oct 2019 11:16:09 +0100 Subject: [PATCH 07/14] fix window size --- ftplugin/supercollider.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 5ceb314..ceacd55 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -247,6 +247,8 @@ function SClangStart(...) vsplit wincmd w exec "vertical resize " .(l:splitSize * 2) ."%" + exec "set wfw" + exec "set wfh" exec "term " .s:sclangPipeApp exec "normal G" wincmd w From 6072ffd6fe4bd679adedc920a90d190716650931 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Thu, 31 Oct 2019 13:04:35 +0100 Subject: [PATCH 08/14] destroy start_pipe buffers on Start and Kill --- ftplugin/supercollider.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index ceacd55..a47f6e2 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -246,6 +246,7 @@ function SClangStart(...) let l:resizeCmd = (l:isVertical) ? "vertical resize " : "resize " vsplit wincmd w + exec "bd! start_pipe" exec "vertical resize " .(l:splitSize * 2) ."%" exec "set wfw" exec "set wfh" @@ -260,6 +261,7 @@ endfunction function SClangKill() call system(s:sclangDispatcher . " -q") + exec "bd! start_pipe" endfunction function SClangKillIfStarted() From 6d22d3d7c466fba9c9102c5d6d8ea83cc33a671a Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Thu, 31 Oct 2019 13:15:23 +0100 Subject: [PATCH 09/14] proper buffer cleanup --- ftplugin/supercollider.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index a47f6e2..40940db 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -219,6 +219,12 @@ endfunction let s:sclangStarted = 0 +function s:KillSClangBuffer() + if bufexists(bufname('start_pipe')) + exec 'bd! start_pipe' + endif +endfunction + function SClangStart(...) let l:tmux = exists('$TMUX') let l:screen = exists('$STY') @@ -246,7 +252,7 @@ function SClangStart(...) let l:resizeCmd = (l:isVertical) ? "vertical resize " : "resize " vsplit wincmd w - exec "bd! start_pipe" + call s:KillSClangBuffer() exec "vertical resize " .(l:splitSize * 2) ."%" exec "set wfw" exec "set wfh" @@ -261,7 +267,7 @@ endfunction function SClangKill() call system(s:sclangDispatcher . " -q") - exec "bd! start_pipe" + call s:KillSClangBuffer() endfunction function SClangKillIfStarted() From 238558fa868cf2d03868f55a0c0ac0c7665071bd Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 8 Nov 2019 09:03:26 +0100 Subject: [PATCH 10/14] in vim, open terminal in same window --- ftplugin/supercollider.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 40940db..71c3210 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -247,6 +247,10 @@ function SClangStart(...) call system("screen -S " . l:screenName . " -X bindkey -k k5") endif elseif exists(":term") + let l:term = ":term " + if !has("nvim") + let l:term .= "++curwin " + endif let l:isVertical = l:splitDir == "v" let l:splitCmd = (l:isVertical) ? "vsplit" : "split" let l:resizeCmd = (l:isVertical) ? "vertical resize " : "resize " @@ -256,7 +260,7 @@ function SClangStart(...) exec "vertical resize " .(l:splitSize * 2) ."%" exec "set wfw" exec "set wfh" - exec "term " .s:sclangPipeApp + exec l:term .s:sclangPipeApp exec "normal G" wincmd w else From 0ac3393e2724d2d49a36447c04a60fc60ff743a3 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 8 Nov 2019 23:11:46 +0100 Subject: [PATCH 11/14] only kill buffer if nvim --- ftplugin/supercollider.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 71c3210..7fadcd9 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -249,7 +249,7 @@ function SClangStart(...) elseif exists(":term") let l:term = ":term " if !has("nvim") - let l:term .= "++curwin " + let l:term .= "++curwin ++close " endif let l:isVertical = l:splitDir == "v" let l:splitCmd = (l:isVertical) ? "vsplit" : "split" @@ -271,7 +271,9 @@ endfunction function SClangKill() call system(s:sclangDispatcher . " -q") - call s:KillSClangBuffer() + if has("nvim") + call s:KillSClangBuffer() + endif endfunction function SClangKillIfStarted() From e9799b9362b5e054beb6df207e796e54f6d854f4 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Fri, 8 Nov 2019 23:29:13 +0100 Subject: [PATCH 12/14] add variable to toggle buffer --- ftplugin/supercollider.vim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 7fadcd9..02c9228 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -78,6 +78,12 @@ if exists("g:scSplitSize") let s:scSplitSize = g:scSplitSize endif + +let s:scTerminalBuffer = "off" +if exists("g:scTerminalBuffer") + let s:scTerminalBuffer = g:scTerminalBuffer +endif + " ======================================================================================== function! FindOuterMostBlock() @@ -219,6 +225,10 @@ endfunction let s:sclangStarted = 0 +function s:TerminalEnabled() + return exists(":term") && (s:scTerminalBuffer == "on") +endfunction + function s:KillSClangBuffer() if bufexists(bufname('start_pipe')) exec 'bd! start_pipe' @@ -246,7 +256,7 @@ function SClangStart(...) call system("screen -S " . l:screenName . " -X resize " . l:splitSize . '%') call system("screen -S " . l:screenName . " -X bindkey -k k5") endif - elseif exists(":term") + elseif s:TerminalEnabled() let l:term = ":term " if !has("nvim") let l:term .= "++curwin ++close " From 905ca5941d256dbe0a07e5182a2f62b019ade234 Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Sun, 1 Dec 2019 11:06:50 +0100 Subject: [PATCH 13/14] check if user wants terminal buffer before checking for multiplexers --- ftplugin/supercollider.vim | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index 02c9228..ab5bf10 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -240,23 +240,7 @@ function SClangStart(...) let l:screen = exists('$STY') let l:splitDir = (a:0 == 2) ? a:1 : s:scSplitDirection let l:splitSize = (a:0 == 2) ? a:2 : s:scSplitSize - if l:tmux || l:screen - if l:tmux - let l:cmd = "tmux split-window -" . l:splitDir . " -p " . l:splitSize . " ;" - let l:cmd .= "tmux send-keys " . s:sclangPipeApp . " Enter ; tmux select-pane -l" - call system(l:cmd) - elseif l:screen - " Main window will have focus when splitting, so recalculate splitSize percentage - let l:splitSize = 100 - l:splitSize - let l:splitDir = (l:splitDir == "v") ? "" : " -v" - let l:screenName = system("echo -n $STY") - call system("screen -S " . l:screenName . " -X split" . l:splitDir) - call system("screen -S " . l:screenName . " -X eval focus screen focus") - call system("screen -S " . l:screenName . " -X at 1# exec " . s:sclangPipeApp) - call system("screen -S " . l:screenName . " -X resize " . l:splitSize . '%') - call system("screen -S " . l:screenName . " -X bindkey -k k5") - endif - elseif s:TerminalEnabled() + if s:TerminalEnabled() let l:term = ":term " if !has("nvim") let l:term .= "++curwin ++close " @@ -273,6 +257,22 @@ function SClangStart(...) exec l:term .s:sclangPipeApp exec "normal G" wincmd w + elseif l:tmux || l:screen + if l:tmux + let l:cmd = "tmux split-window -" . l:splitDir . " -p " . l:splitSize . " ;" + let l:cmd .= "tmux send-keys " . s:sclangPipeApp . " Enter ; tmux select-pane -l" + call system(l:cmd) + elseif l:screen + " Main window will have focus when splitting, so recalculate splitSize percentage + let l:splitSize = 100 - l:splitSize + let l:splitDir = (l:splitDir == "v") ? "" : " -v" + let l:screenName = system("echo -n $STY") + call system("screen -S " . l:screenName . " -X split" . l:splitDir) + call system("screen -S " . l:screenName . " -X eval focus screen focus") + call system("screen -S " . l:screenName . " -X at 1# exec " . s:sclangPipeApp) + call system("screen -S " . l:screenName . " -X resize " . l:splitSize . '%') + call system("screen -S " . l:screenName . " -X bindkey -k k5") + endif else call system(s:sclangTerm . " " . s:sclangPipeApp . "&") endif From 13472e862dab82bfb79f652956fc9b1d009ea25a Mon Sep 17 00:00:00 2001 From: Claudio Cabral Date: Sun, 1 Dec 2019 11:07:35 +0100 Subject: [PATCH 14/14] add g:scTerminalBuffer descripption to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e14460f..706e332 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ The following variables are available for configuration in your `.vimrc` file: | `g:scFlash` | Highlighting of evaluated code | `0` | | `g:scSplitDirection` | Default window orientation when using a terminal multiplexer | `"h"` | | `g:scSplitSize` | Post window size (% of screen) when using a terminal multiplexer | `50` | +| `g:scTerminalBuffer` | If set to `"on"` use vim's `:term` to launch `g:sclangTerm` | `"off"` | Example `.vimrc` line for gnome-terminal users: