Skip to content

Instantly share code, notes, and snippets.

@kyleburton
Created March 11, 2011 18:28
Show Gist options
  • Save kyleburton/866324 to your computer and use it in GitHub Desktop.
Save kyleburton/866324 to your computer and use it in GitHub Desktop.
Emacs, Slime Helper to augment 'swank' bash function and trigger emacs to connect to the fresh swank server.
#!/usr/bin/env ruby
require 'socket' # Sockets are in standard library
$hostname = 'localhost'
$port = (ARGV[0] || "4005").to_i
attempts = 100
$s = nil
$retry = true
while $retry && (attempts > 0)
begin
$stderr.print '.'
attempts -= 1
$s = TCPSocket.open($host, $port)
$stderr.puts "connected"
break
rescue
if $!.to_s =~ /Connection refused/i
$retry = true
sleep 0.25
else
$stderr.puts "Error: #$!"
$retry = false
end
end
end
if $s
$s.close
$stderr.puts "connected"
exec %Q|emacsclient -e '(progn (setq slime-protocol-version "20100404") (slime-connect "localhost" #{$port}))'|
else
exit -1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment