Skip to content

add go-sclang compatibility #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ Requirements
Installation
------------

### `go-sclang` installation

Follow [go-sclang installation instructions](https://github.com/WnP/go-sclang#install).

Remember that `go-sclang` **and** `go-sclang-client` are required.

### `scvim` plugin installation

It is highly recommended to use either Vim 8+'s native `packages` or a plugin
Expand Down Expand Up @@ -91,15 +97,17 @@ Path to the tags file

The following variables are available for configuration in your `.vimrc` file:

| Variable | Description | Default |
| -------- | ----------- | ------- |
| `g:sclangTerm` | Command to open a terminal window | `"open -a Terminal.app"` on macOS,<br />`"x-terminal-emulator -e $SHELL -ic"` on Linux |
| `g:sclangPipeApp` | Absolute path to **start_pipe** script | `"~/.vim/bundle/scvim/bin/start_pipe"` |
| `g:sclangDispatcher` | Absolute path to **sc_dispatcher** script | `"~/.vim/bundle/scvim/bin/sc_dispatcher"` |
| `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"` |
| Variable | Description | Default |
| -------- | ----------- | ------- |
| `g:sclangTerm` | Command to open a terminal window | `"open -a Terminal.app"` on macOS,<br />`"x-terminal-emulator -e $SHELL -ic"` on Linux |
| `g:sclangServer` | Absolute path to **go-sclang** binary | `"go-sclang"` - should be in your $PATH |
| `g:goSclangServerOptions` | Options for to **go-sclang** binary | `""` |
| `g:sclangClient` | Absolute path to **go-sclang-client** binary | `"go-sclang-client"` - should bin in your $PATH |
| `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"` |
| `g:scPrintToMiniBuffer` | Print sclang returned value to vim mini buffer | `1` |

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

Expand Down
43 changes: 0 additions & 43 deletions bin/sc_dispatcher

This file was deleted.

5 changes: 0 additions & 5 deletions bin/scpipe/lib/sc.rb

This file was deleted.

26 changes: 0 additions & 26 deletions bin/scpipe/lib/sc/dispatcher.rb

This file was deleted.

105 changes: 0 additions & 105 deletions bin/scpipe/lib/sc/pipe.rb

This file was deleted.

4 changes: 0 additions & 4 deletions bin/start_pipe

This file was deleted.

68 changes: 37 additions & 31 deletions ftplugin/supercollider.vim
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,34 @@ else
let s:sclangTerm = "open -a Terminal.app"
endif

if exists("g:sclangPipeApp")
let s:sclangPipeApp = g:sclangPipeApp
if exists("g:goSclangServerOptions")
let s:goSclangServerOptions = g:goSclangServerOptions
else
let s:sclangPipeApp = s:bundlePath . "/bin/start_pipe"
let s:goSclangServerOptions = ""
endif

if exists("g:sclangDispatcher")
let s:sclangDispatcher = g:sclangDispatcher
if exists("g:sclangServerOptions")
let s:sclangServerOptions = g:sclangServerOptions . " -i scvim -d " . getcwd()
else
let s:sclangDispatcher = s:bundlePath . "/bin/sc_dispatcher"
let s:sclangServerOptions = " -i scvim -d " . getcwd()
endif

if exists("g:scPrintToMiniBuffer")
let s:scPrintToMiniBuffer = g:scPrintToMiniBuffer
else
let s:scPrintToMiniBuffer = 1
endif

if exists("g:sclangServer")
let s:sclangServer = g:sclangServer . " " . s:goSclangServerOptions . " -- " . s:sclangServerOptions
else
let s:sclangServer = "go-sclang ". s:goSclangServerOptions . " -- " . s:sclangServerOptions
endif

if exists("g:sclangClient")
let s:sclangClient = g:sclangClient
else
let s:sclangClient = "go-sclang-client"
endif

if !exists("loaded_kill_sclang")
Expand Down Expand Up @@ -161,28 +179,17 @@ endfunction

" ========================================================================================


function SCFormatText(text)
let l:text = substitute(a:text, '\', '\\\\', 'g')
let l:text = substitute(l:text, '"', '\\"', 'g')
let l:text = substitute(l:text, '`', '\\`', 'g')
let l:text = substitute(l:text, '\$', '\\$', 'g')
let l:text = '"' . l:text . '"'

return l:text
endfunction

function SendToSC(text)
let l:text = SCFormatText(a:text)

call system(s:sclangDispatcher . " -i " . l:text)
let l:val = system(s:sclangClient . " -o", a:text)
redraw!
if (s:scPrintToMiniBuffer)
echo l:val
endif
return l:val
endfunction

function SendToSCSilent(text)
let l:text = SCFormatText(a:text)

call system(s:sclangDispatcher . " -s " . l:text)
call system(s:sclangClient, a:text)
redraw!
endfunction

Expand Down Expand Up @@ -254,13 +261,13 @@ function SClangStart(...)
exec "vertical resize " .(l:splitSize * 2) ."%"
exec "set wfw"
exec "set wfh"
exec l:term .s:sclangPipeApp
exec l:term . s:sclangServer
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"
let l:cmd .= "tmux send-keys \"" . s:sclangServer . "\" Enter ; tmux select-pane -l"
call system(l:cmd)
elseif l:screen
" Main window will have focus when splitting, so recalculate splitSize percentage
Expand All @@ -269,18 +276,18 @@ function SClangStart(...)
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 at 1# exec " . s:sclangServer)
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 . "&")
call system(s:sclangTerm . " " . s:sclangServer . "&")
endif
let s:sclangStarted = 1
endfunction

function SClangKill()
call system(s:sclangDispatcher . " -q")
call system(s:sclangClient . " -k")
if has("nvim")
call s:KillSClangBuffer()
endif
Expand All @@ -293,9 +300,8 @@ function SClangKillIfStarted()
endfunction

function SClangRecompile()
echo s:sclangDispatcher
call system(s:sclangDispatcher . " -k")
call system(s:sclangDispatcher . " -s ''")
echo s:sclangClient
call system(s:sclangClient . " -r")
redraw!
endfunction

Expand Down