Hello Clojuriasts, This one is for the few aficionados of Emacs and the SLIME.
I once got really tired of typing "M-x slime-connect RET RET ... etc." everytime I needed to bounce my VM in order to reconnect my Emacs to it. This happened often enough to me, because like Stuart (S) in a previous email, I also bork my VM on a regular basis and need to restart several times/coding session. So I came up with the following function, which uses the default connection values and tries to connect every second until it succeeds (I never shared it, but here it is anyhow): (defun slime-reconnect () "A more convenient function to reconnect to a LISP VM. This function uses the default parameters for the connection so you don't have to specify them, on failure waits and retries automatically until the connection succeeds (for slow VMs to start in the background), and saves and restores the window configuration to avoid showing the repl (you don't need it most of the time if you use SLIME)." (interactive) (slime-disconnect-all) (message "Connecting to Swank on port %S.." slime-port) (save-window-excursion (let ((count 0)) (while (not (condition-case nil (let* ((process (slime-net-connect slime-lisp-host slime-port slime-net-coding-system)) (slime-dispatching-connection process)) (slime-setup-connection process) ) (error ;;(message "Waiting for VM...") (sleep-for 0 700) (message (format "Attempting reconnection to Swank... (%s times)" count)) (setq count (1+ count) ) nil)))) (sleep-for 0 300) ))) (defalias 'sc 'slime-reconnect) This did okay for a while, but unfortunately, that's a BLOCKING call, so your Emacs is frozen until your either interrupt it (C-g) or it succeeds once the slow-starting VM's Swank is ready. But it's still a bit annoying, you have to invoke it. So tonight I was mucking around with Emacs to make a globalized minor mode that automatically attempts to reconnect to a Clojure VM in the background, when it disconnects. Basically, you would enable something like "connected-minor-mode" and if you'd lose your connection (because you kill and restart your VM), Emacs would automatically attempt to reconnect to it. Minimal disturbance. I had it pretty much working, BUT... As I was rummaging in the SLIME, I found a nifty "slime-auto-connect" feature, which, upon evaluation of an expression, if a connection is not already established, will attempt to automatically start an inferior process for SLIME. This seemed to me a much more elegant solution to the previous "reconnecting attempts" idea... Unfortunately, this feature doesn't appear to support network connects to an already running Swank; SLIME supports an inferior process by default (via the "(slime)" command). The following tidbit of Elisp fixes this problem and modifies SLIME to make it possible to auto-connect to a Clojure VM: ;; Override the default command to support optinal network connection instead of ;; always just starting an inferior process. (defadvice slime (around slime-auto-net-connect activate) (if slime-default-is-connect (save-window-excursion (slime-connect slime-lisp-host slime-port) (sleep-for 0 300)) ad-do-it)) ;; Automatically connect when disconnected. (setq slime-auto-connect 'always) ;; Indicate that the default connection should be via the network, not an ;; inferior process. (setq slime-default-is-connect t) (Note that I suppress window changes because the slime-repl extension (required for Clojure and SLIME) pops up the REPL and thus messes with the window configuration and that's annoying.) So basically, if you bounce your VM, the next time you evaluate something, SLIME automatically reestablishes the connection. I think this is a better solution to this minor annoyance. I hope someone out there finds this useful. Cheers, -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en