(defun safe-remote-slime ()
(interactive)
(let ((host (ido-completing-read "Host: " (pcmpl-ssh-hosts))))
(when (and safe-tunnel-process
(eq 'run (process-status safe-tunnel-process)))
(if (y-or-n-p "Tunnel already open; kill?")
(ignore-errors (kill-process safe-tunnel-process))
(error "Aborted.")))
(setq safe-tunnel-process
(start-process "safe-tunnel" "*safe-tunnel*" "ssh"
"-L" (format "%s:127.0.0.1:4005" safe-tunnel-port)
TODO host "echo connected && sleep 16"))
(set-process-filter safe-tunnel-process
(lambda (process output)
(with-current-buffer "*safe-tunnel*"
(insert output))
(when (string-match "connected" output)
(slime-connect "localhost" safe-tunnel-port)
(set-process-filter process nil))))))