Picking up from “Remote login with SSH key pair” and the updated “Setting up Lisp & Hunchentoot on a web server”, when i run emacs locally and connect to my running lisp + hunchentoot process on the server, the REPL alone, although awesome, is insufficient for my hacking need. I’ll need some way to work with remote files…
First let’s see how we can open a remote lisp file that we will later on use to test compiling. First we must start an ssh tunnel to the remote box (look at step 13 in “Setting up Lisp & Hunchentoot on a web server”). Start up emacs and slime-connect to the remote box. To open up a remote file i do C-x C-f and then on the interaction line:
1 |
Find file: ssh://hunchentoot@sample.ponto-dot.com:/var/lib/hunchentoot/test.lisp |
Here we are logging in through ssh to sample.ponto-dot.com with user hunchentoot and we want to open file /var/lib/hunchentoot/test.lisp on the remote filesystem. Inside type:
1 2 |
(defun test-remote-compilation () (print "Testing remote compilation")) |
I save it and when i try to compile it with C-c C-k i end up with something like:
1 2 3 4 5 6 7 |
failed to find the TRUENAME of /scp:hunchentoot@sample.ponto-dot.com:/var/lib/hunchentoot/test.lisp: No such file or directory [Condition of type SB-INT:SIMPLE-FILE-ERROR] Restarts: 0: [ABORT] Return to SLIME's top level. 1: [TERMINATE-THREAD] Terminate this thread (#<THREAD "worker" RUNNING {ACA9991}>) |
As you can see it tries to load a non-existing file because it is not translating the pathnames. Let’s setup slime-tramp filename translations, for this you must load slime-tramp together with slime in emacs, either with:
(require 'slime-tramp)
Or the way i’m doing it, by means of slime-setup (from looking at the slime documentation i believe this is the recommended way of doing this now):
slime-setup '(slime-repl slime-tramp)
Now whenever slime is loaded slime-tramp will be loaded as well, here’s a list of current available packages/modules that can be loaded with slime.
We now have setup emacs to load slime-tramp but we still haven’t explained slime how to translate stuff, for this we start by slime-connect’ing to the remote lisp process and from the repl run:
1 2 3 |
CL-USER>(cl:machine-instance) "la45-12" CL-USER> |
Take note of the result, here it’s la45-12 and it is the name of our remote machine instance that we’ll need to setup the translations. Open your .emacs and set something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
(add-hook 'slime-connected-hook (lambda () (push (list ".*" (lambda (filename) filename) (lambda (filename) filename)) slime-filename-translations) (push (list "li47-21" (lambda (filename) (subseq filename (length "/ssh:hunchentoot@sample.ponto-dot.com#5201:"))) (lambda (filename) (concat "/ssh:hunchentoot@sample.ponto-dot.com#5201:" filename))) slime-filename-translations))) |
Note: The ssh url used here is for my login, you’ll need to change the user and domain name/ip address to reflect your own ssh login string.
This piece of code will execute when slime connects and run two PUSH forms. The first form (‘.*’ is a regular expression that will match any value) and it’s purpose is to deal with local files, this is a safeguard in case you ever run slime with a local lisp process, if i only had the second PUSH form and tried to compile a local file in a local lisp session emacs would spit the following error:
No filename-translations for hostname: workstation
The second PUSH will add the translation functions for interacting with the machine-instance “li45-12” (if you remember you noted this value when you ran (cl:machine-instance) on the remote repl).
Where workstation is my local machine-instance.
Now, restart emacs, slime-connect again and, open the remote file we just created:
1 |
Find file: ssh://hunchentoot@sample.ponto-dot.com:/var/lib/hunchentoot/test.lisp |
Now when i retry compiling the file it compiles successfully, we can test this by switching our buffer to the slime repl.
1 2 3 4 5 |
CL-USER> (test-remote-compilation) "Testing remote compilation" "Testing remote compilation" CL-USER> |
Now finally i can go ahead and hack away at my remote lisp environment. Hope this was helpful to anyone, i know it will definitely come in handy to me in a few months.
Thanks, this really helped.
I had found some old snippets of elisp on paste.lisp.org – but they didn’t work with modern slime versions. This worked perfectly though.
Hi Shaneal,
Thank you for the feedback, i’m really happy this article was helpful for someone else other than me.