Clojure Emacs Connecting to Remote REPL - emacs

When using plain repl with tramp I can navigate to a remote directory and exetute inferior-lisp and it launches a inferior-lisp process on the remote. With nrepl I can start the repl on the remote machine using lein repl than connect to it using nrepl-jack-in but the problem is with nrepl I have to setup firewall rules or use ssh and forward ports so I can jack in. With inferior-lisp and tramp method I do not need to do anything special just hit M-x inferior-lisp and I am set. Is there a way to achieve similar behaviour using nrepl and tramp?

Depending on your settings, most likely inferior-lisp invokes a local process.
If you just want to work on your Clojure project locally, I would recommend to download the project folder from the remote machine and repl locally using nrepl-jack-in.

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).

Tramp can not connect to remote server

I have upgraded my emacs and updated some el-get packages including tramp (my system is a bit old, and I could not upgrade some emacs packages), and now I can not use tramp to connect to a remote server:
Tramp: Opening connection for server1 using ssh...failed
byte-code: Host `server1' looks like a remote host, `ssh' can only use the local host
I am using tramp version 2.2.13-pre and emacs version 24.5.1. I have compiled emacs myself, in case it matters.
What can be going wrong? What could I try?
EDIT
I am calling tramp like this:
C-x C-f /user#server1:filename
Call emacs -Q. Likely, Tramp will work then. In this case, bisect your .emacs file and restart Emacs, until you find the package which causes the trouble.
One package which didn't cooperate well with Tramp was projectile. Disable it, when you are using it.

Clojure - start a REPL without a project.clj

I started using Clojure with leiningen (and now boot).
Now I sometimes want to get quickly to a Clojure{Script} CIDER REPL in Emacs to execute just a few instructions. I don't want to create a project.clj file for that, since I just want a throwaway REPL.
Is there a way to get a Clojure REPL, for instance in the *scratch* buffer ?
well, you can execute M-x cider-jack-in anywhere you want, even with no project.clj in path. This works for me.
You can just type lein repl in the friendly console / shell / terminal right next to you -- no project.clj required. This will start a REPL as expected, to which you can then connect from Emacs via M-x cider-connect (which in recent versions will handily suggest host and port to connect to).
M-x cider-jack-in basically does the same thing (i.e. lein repl) behind the scenes.
I'm not a boot user, but according to the boot wiki for leiningen users it should be possible to call boot repl -s.
Use M-x cider-jack-in, and if you don't want it to warn you that you're running cider-jack-in without a Clojure project, add the following to your emacs.d/init.el:
(setq cider-allow-jack-in-without-project t)

print output of execution in cider repl

I am wondering if there is a way to have the output of the current execution in emacs cider when using cider-connect.
For instance :
I run lein repl on a project directory
then connect to it in emacs using cider-connect.
Now let's say that I have (println "cider is amazing by the way") in the code of one of my ring handlers, this will only be printed in the console I ran lein repl when a request is made.
How can I have this output also in my nrepl buffer ?
Sorry to say, I suspect that you cannot do this in the way you describe. The output is going strait to the console of that device and not through anything related to nrepl on the way. This also makes sense if you consider that nrepl is often not even running on the same computer. (the "n" in nrepl is for "network").
Perhaps you can arrange for that output to be teed to a file where you can get at it? Then you could start a thread on your nrepl buffer that cated that file. Or have a buffer in emacs that watches the remote file.
If you start leiningen via cider-jack-in you should get the output in the repl buffer.
One way to use this with a remote setup could be to call C-u M-x cider-jack-in and use a specialized server command that will essentially trigger the lein repl command (say over ssh) on the remote machine -- I haven't checked whether this will actually work, but I don't see any reason why it shouldn't. If you can access the code over tramp, it shouldn't matter much whether the code is remote or not.

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