(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: launch swank if needed
                         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))))))

Generated by Phil Hagelberg using scpaste at Wed May 25 12:01:39 2011. PDT. (raw)