connect multiple different terminals to the same slime instance - emacs

I am still a novice when it comes to working with emacs and slime.
I was wondering if there is a way to start a lisp (say SBCL) on a local port and then connect multiple different slime sessions to it?
For example, if I am using tmux/screen and want to have different emacs sessions between each window, would I be able to connect all the slime instances to the same lisp so that all the emacs sessions were sharing a repl allowing me to compile in any of the emacs sessions and the one running repl will have those changes?

I am using LispWorks 6.1 32 bit Professional Edition. I prefer to use (Spac)emacs for my editing in multiple tmux sessions, one session for each project that I work on.
These are the steps I follow:
Start LispWorks Listener REPL.
Load swank without going through the emacs route:
(load "/path/to/swank-loader.lisp")
(swank-loader:init)
(setf swank:*use-dedicated-output-stream* nil)
(swank:create-server :port 4005 :dont-close t)
Then in my iTerm tab with tmux session for some project 1, I do M-x slime-
connect and connect to host and port as in step 2.
Repeat step 3 for another tmux session with another lisp project code.
With this setup I can load code from multiple projects I am working on in the same lisp image. So far I have not found any major problems while doing so.

This depends on the lisp system you're using, on the features it supports, i.e. whether your SBCL has multi-threading enabled (cf. (member :sb-thread *features*) and on the setting of SWANK:*COMMUNICATION-STYLE*, cf. the Slime docs.

Related

"Hot" Debug and Swap in Common LISP

One of the features that are unique to Common Lisp that is frequently mentioned is that of the "hot" debug. That is, it is the ability to debug, edit and recompile the production code without stopping or taking the latter off line.
While I see this mentioned all the time, I have yet to see a tutorial on how to do it.
How does one do it in, say, Emacs? Are there some simple examples? Is the feature truly as magical as it seems?
The typical way to do this is to enable SWANK in the application that you want to debug. That way you can use M-x slime-connect from Emacs to connect to the running server. From there, you can do anything you can do with a normal SLIME session. You can even set up the way file names re resolved so that when you use M-. to jump to the source of a function, it will be opened on the remote machine using Tramp.
I think the reason you haven't seen a tutorial on it is because it's a natural thing to do, and there really isn't much of a difference between doing local debugging and working on a remote system.
There is a video of a lecture I did once where I demonstrated some of this, so there definitely are videos out there. However, I think linking to external videos is frowned upon on Stackoverflow.
Some notes I took for myself. I largely agree we should have a tutorial out there. In the CL Cookbook ?
(edit: there's now a more complete example here)
Reading http://readevalprint.tumblr.com/post/101841449553/its-alive-the-path-from-library-to-web-app
Another option is hot swapping all the changes. For this purpose my hunchentoot server also starts a swank server like this:
(defun start-app (&optional (port 8080))
(handler-case (swank:create-server :dont-close t)
(error ()))
…
Swank is, of course, the server-side component of SLIME. It runs on a port that is not accessible remotely and can only be connected to locally or via SSH tunnel. I use the latter to connect SLIME on my PC to Swank running on my server, which allows me to apply various fixes without restarting, either from the REPL or by using C-c C-c to recompile some function.
Connect to a remote Slime server:
Install a Common Lisp implementation on the server. (E.g. sbcl, clisp, etc...)
Install quicklisp on the server.
Load SWANK with (ql:quickload :swank)
Start the server with (swank:create-server). The default port is 4005. [On your local machine] Create a SSH tunnel with ssh -L4005:127.0.0.1:4005 [remote machine]
Connect to the running remote swank server with M-x slime-connect.
The host should be 127.0.0.1 and the port 4005.
(reading an old SO doc page, impossible to link to now).

How do I control emacs from a terminal?

I'm trying to drive emacs on OSX using Dragon Naturally Speaking running inside a Windows VM. Rather than running emacs in the VM, I'd like to drive an emacs (built from the HEAD of the repository) already running on the mac side of things. So, after a hunt through the emacs lisp manual I came up with the following snippets of lisp (currently running from the scratch buffer while I work stuff out):
;; This part is run from an emacsclient -t session
(defvar slave-frame last-event-frame)
;; and this is run in a GUI frame
(defadvice handle-switch-frame (after update-slave-redirect-advice activate)
(unless (eq last-event-frame slave-frame)
(redirect-frame-focus slave-frame last-event-frame)))
And all is well. I type into the terminal window, displaying buffer A and my typing appears in the GUI frame busily dsplaying buffer B. Great. Until I do C-x C-f or any other command that needs the minibuffer, at which point I get the error Terminal 1 is locked, cannot read from it.
I'm I barking up the wrong tree here, or is there a way to make redirect-frame-focus work nicely with commands that use the minibuffer?
Piers,
What behavior do you want, redirection to a minibuffer on the (Windows) client or a minibuffer on the server? Also, what version/flavor of emacs are you using?

Swank server startup failure

Emacs SLIME can't connect to swank, because apparently swank cannot initialize correctly.
It says some back end function not implemented. However, my swamp backend is SBCL, which is supported. I am using windows xp os.
A similar issue was found posted at the following link, but no solution.Link to similar issue
Am I missing any configuration file for Swank? Or perhaps emacs and SBCL versions I am using have compatibility issues? In that case, where can I get the correct compatibility matrix for windows?
I'm mostly using Linux, but it's very easy to run into conflicts if you have multiple versions of slime/swank code installed.
The best method is to use quicklisp and make sbcl/emacs not use any other code (at least in your first attempt):
sbcl --no-userinit --no-sysinit --load ~/quicklisp/setup.lisp
(asdf:initialize-source-registry '(:source-registry :ignore-inherited-configuration))
(ql:quickload "quicklisp-slime-helper")
(swank:create-server :port 4545 :dont-close t :coding-system "utf-8-unix")
Then start emacs as:
emacs -q -name SLIME -eval '(progn (load (expand-file-name "~/quicklisp/slime-helper.el")) (slime-connect "localhost" 4545))'
http://www.pchristensen.com/blog/articles/installing-sbcl-emacs-and-slime-on-windows-xp
Use this or any other manual, which describes how to install Emacs, sbcl and slime separately. But using the latest releases. Then it will be easier to find the problem than it is now.
This is not exactly an answer to the problem, more of an alternative.
I think some interfaces/ method definitions that Swank expects, need to be implemented by SBCL. I shifted the lisp implementation to CLisp from SBCL, and after some setup tweaking, got it to work. So, I think Swank is fine but SBCL is not.
Just for information, CLisp cannot work with short windows path, the ones that look like "Progra~1", while SBCL expects short paths. CLisp also gave some problem with the temp folder in Windows, for which a variable had to be added to the .emacs file, but after that was setup quickly.
There seem to be lots of differences between the various Lisp implementations' ports to Windows, which would not be a problem had better documentation been present. All this had to be gleaned from different blogs and mailing list.
As soon as a better answer to the original problem comes along, I'll accept that.

Emacs with Slime and Swank for non-leiningen projects

I found this website which explains how to use emacs with leiningen, swank, and slime. Is there a way to use slime + swank in non-leiningen projects i.e. how can I connect to slime/swank repl to run a ad-hoc Clojure script while I write it as demonstrated here?
You need to have swank-clojure.jar in CLASSPATH and your script should have following code:
(require 'swank.swank)
(swank.swank/start-repl 4005)
to start swank process on port 4005 (or some other)...
P.S. You can look onto Incanter's swank script, that pass this code in environment variable, and later it evaluated as part of boostrap script

What does the 'swank-clojure' do exactly, and do we have 'swank-SOMETHING_ELSE'?

My superficial understanding is that 'swank-clojure' makes 'M-x slime-connect' possible. I mean, it gives a connection to a clojure server something like 'lein swank'. Is my understanding correct? If not, what's the purpose of swank?
Then, is there any 'swank-SOMETHING_ELSE' for other lisp like implementations? For example, swank-clisp?
Do I need 'swank-clojure' for using SLIME/Clojure with 'M-x slime'?
ADDED
I found this link pretty useful.
SLIME and swank form a client server architecture to run and debug lisp programs. SLIME is the emacs frontend and swank is the backend. In between they create a network socket and communicate by sending across messages (S-expressions). In short it is just an RPC mechanism between emacs and the actual lisp backend.
The fact that the slime and swank are separate, are connected over a network and communicate via rpc messages means that they can be anywhere. So, slime can connect to a remote host/port to swank. All other forms you see (lein swank etc etc) do the same. They start swank on a port allowing for a remote connection of slime.
swank-clojure is the clojure port of swank. originally swank-clojure came with a helper elisp file called swank-clojure.el. The job of this file was to enable manual setup of swank parameters like the classpaths, jvm parameters etc. Since other tools like lein came along later, swank-clojure.el was deprecated. But it still lives on at: http://github.com/vu3rdd/swank-clojure-extra and provides the M-x swank-clojure-project which enables starting swank on a lein project.
It should be noted that SLIME originated in (and is still being actively developed for) Common Lisp. Infact, the clojure port of swank only has a subset of the features enjoyed by the original SLIME/swank versions. SLIME exists for all major variants of Common Lisp. There is a partial port of it for Scheme48. There are some partial implementations available under the contrib directory.
If you know that swank is already running on a port, use slime-connect. If you just want to use slime on a project, swank-clojure-project and lein swank seem to be the way to go.
swank-clojure.el is deprecated. Don't use it.
You need slime.el and you need to have swank-clojure "1.2.1" in your dev-dependcies in your project.clj file.
Swank is basically a server that you use slime to connect to from emacs. It it passed, from emacs, what you want run by the Lisp process that it's running.
You should use M-x slime-connect to connect to a swank server after starting with with lein swank.
Swank is the server counterpart to swank clients like emacs SLIME and the MCLIDE lisp development environment for Macintosh. Swank servers exist for many Common Lisp implementations and Lisp dialects such as Clojure and Gambit/scheme.
My understanding is that slime is the emacs part(the client), swank is the common lisp part(the server), swank-clojure is the clojure implementation of the swank server, not the original.