diff --git a/README.md b/README.md index 706e332..7460a23 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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,
`"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,
`"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: diff --git a/bin/sc_dispatcher b/bin/sc_dispatcher deleted file mode 100755 index 8ec312d..0000000 --- a/bin/sc_dispatcher +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env ruby -require File.dirname(__FILE__) + '/scpipe/lib/sc' -require 'optparse' - -options = {} - -d = SC::Dispatcher.new - -OptionParser.new do |opts| - opts.banner = "Usage: sc_dispatcher.rb [options]" - opts.separator "----" - - opts.on("-i ", "Interpret SC Code") do |sc_code| - d.interpret(sc_code) - end - - opts.on("-s ", "Interpret SC Code without printing results") do |sc_code| - d.interpret_silent(sc_code) - end - - opts.on("-k", "Recompile the library") do - File.open(SC::Pipe.pid_loc, "r") do |file| - d.interpret_silent("Server.quitAll;") - pid = file.read.chomp - Process.kill('USR1', pid.to_i) - end - end - - opts.on("-q", "Quit SuperCollider and all the belonging prcesses") do - d.interpret_silent("Server.quitAll;") - - File.open(SC::Pipe.pid_loc, "r") do |file| - pid = file.read.chomp - Process.kill('INT', pid.to_i) - end - end - - opts.on_tail("-h", "--help", "Show this message") do - puts opts - exit - end - -end.parse! diff --git a/bin/scpipe/lib/sc.rb b/bin/scpipe/lib/sc.rb deleted file mode 100644 index 329c2a0..0000000 --- a/bin/scpipe/lib/sc.rb +++ /dev/null @@ -1,5 +0,0 @@ -libdir = File.dirname(__FILE__) -$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) - -require 'sc/pipe' -require 'sc/dispatcher' \ No newline at end of file diff --git a/bin/scpipe/lib/sc/dispatcher.rb b/bin/scpipe/lib/sc/dispatcher.rb deleted file mode 100644 index 0dec3c4..0000000 --- a/bin/scpipe/lib/sc/dispatcher.rb +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env ruby - -# copyright 2010 sbl -# part of the supercollider textmate bundle - -require 'fileutils' -require 'sc/pipe' - -module SC - class Dispatcher - def initialize - unless SC::Pipe.exists? - raise "Please run a sclang session first." - end - @pipe = SC::Pipe.pipe_loc - end - - def interpret(sc_code) - open(@pipe, "w") { |io| io << sc_code << "\x0c" } - end - - def interpret_silent(sc_code) - open(@pipe, "w") { |io| io << sc_code << "\x1b" } - end - end -end diff --git a/bin/scpipe/lib/sc/pipe.rb b/bin/scpipe/lib/sc/pipe.rb deleted file mode 100755 index 54228c6..0000000 --- a/bin/scpipe/lib/sc/pipe.rb +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env ruby -# -# SC:Pipe derived from sclang_pipe (SCVIM Package) -# Copyright 2007 Alex Norman under GPL -# -# modified 2010 stephen lumenta -# modified 2012 José Fernández Ramos - -require 'fileutils' -require 'singleton' -require 'tmpdir' - -module SC - - @@sclang_path = `which sclang` - - def self.sclang_path - return @@sclang_path unless @@sclang_path.empty? - # sclang path changed with sc-3.7.2 (https://github.com/supercollider/scvim/pull/11) - @paths = [ - "/Applications/SuperCollider/SuperCollider.app/Contents/MacOS/sclang", - "/Applications/SuperCollider.app/Contents/MacOS/sclang", - "/Applications/SuperCollider/SuperCollider.app/Contents/Resources/sclang", - "/Applications/SuperCollider.app/Contents/Resources/sclang" - ] - @paths.each do |path| - return path if File.exists?(path) - end - warn "Could not find sclang executable.\nPlease make sure that SC is either installed at the default location e.g. '/Applications/SuperCollider.app' on a mac or add sclang to your shells search path." - exit - end - - class Pipe - include Singleton - - @@pipe_loc = File.join(Dir::tmpdir, "sclang-pipe") - @@pid_loc = File.join(Dir::tmpdir, "sclangpipe_app-pid") - - class << self - - def exists? - return File.exists?(@@pipe_loc && @@pid_loc) - end - - def serve - prepare_pipe - clean_up - run_pipe - end - - def pipe_loc - @@pipe_loc - end - - def pid_loc - @@pid_loc - end - - private - - def prepare_pipe - if File.exists?(@@pipe_loc) - warn "there is already a sclang session running, remove it first, than retry" - exit - end - File.open(@@pid_loc, "w"){ |f| - f.puts Process.pid - } - system("mkfifo", @@pipe_loc) - end - - def run_pipe - rundir = Dir.pwd - loop do - begin - IO.popen("#{SC.sclang_path.chomp} -d #{rundir.chomp} -i scvim", "w") do |sclang| - loop do - File.open(@@pipe_loc, "r") do |f| - x = f.read - sclang.print x if x - end - end - end - rescue SignalException => e - # Exit on all signals except usr1, which restarts - unless e.signo == Signal.list["USR1"] - break - end - end - end - end - - def clean_up - at_exit do - remove_files - end - end - - def remove_files - FileUtils.rm(@@pipe_loc) - FileUtils.rm(@@pid_loc) - end - end - end -end diff --git a/bin/start_pipe b/bin/start_pipe deleted file mode 100755 index ff529a7..0000000 --- a/bin/start_pipe +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -require File.dirname(__FILE__) + '/scpipe/lib/sc' - -SC::Pipe.serve diff --git a/ftplugin/supercollider.vim b/ftplugin/supercollider.vim index ab5bf10..4c64921 100644 --- a/ftplugin/supercollider.vim +++ b/ftplugin/supercollider.vim @@ -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") @@ -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 @@ -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 @@ -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 @@ -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