Unable to evaluate form in nrepl + emacs - emacs

I have installed the nrepl, clojure-mode and starter-kit-lisp packages. I am able to start the nrepl by opening my .clj file and then M-x nrepl-jack-in.
However when I evaluate any form in my .clj file by C-x C-e, I get the following message:
inferior-lisp-proc: No Lisp subprocess; see variable `inferior-lisp-buffer'
How do I get it right?

I have had this problem a number of times. In all cases, it has been because while nrepl has started, the nrepl minor mode has not been enabled in the clj buffer. As a result, any evaluation attempts fail with this error.
There should be a "nrepl" menu item. If there isn't, this may be your problem. M-x nrepl-enable-on-existing-buffers should fix it.
I had this problem for a while, and now it appears to have gone away; you might want to try installing clojure-mode and nrepl afresh.

Are you sure M-x nrepl-jack-in worked? If it did, you should be prompted with a repl in emacs, like so:
nrepl requires leiningen 2, so make sure that you use the right version in your project and that the nrepl plugin is properly installed.
Also make sure that the major mode when editing your .clj file is clojure-mode.
You might want to post a screenshot to make it easier to spot the problem.

Related

Why is cider-jack-in hanging in emacs

I'm working through the following tutorial on Clojure. I've just installed both Emacs and Leiningen. If invoked separately, both work. However, when I am trying to invoke cider-jack-in, as described in the tutorial:
Using Emacs, open the file clojure-noob/src/clojure_noob/core.clj,
which you created in Chapter 1. Next, use M-x cider-jack-in. This
starts the REPL and creates a new buffer where you can interact with
it.
that hangs forever after the last message:
Starting nREPL server via lein repl :headless...
You can run the command `cider-jack-in' with C-c M-j
Starting nREPL server via lein repl :headless...
What am I doing wrong?
Edit: To solve the problem, I upgraded leiningen from 1.7 (that's what apt-get installed) to 2.6.1.
Recently cider changed so you no longer need to add things to ~/.lein/profiles.clj to install cider-nrepl and clj-refactor. Cider will take care of that now. You should remove that part from your config.
In general for these situations it help to run lein from the command line first and make sure it can actually get the projects dependencies. Most of the times it's sitting there downloading a jar file at 3 bytes per second and not actually stalled. Other times it's failing with SSL/TLS certificate validation problems.

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.

How can I clear and reload my nrepl session in emacs?

I am working with emacs and nrepl. How can I do the following:
Exit nrepl (currently I just kill the buffer)
Reload everything I was working with in nrepl.
The problem I'm trying to solve by doing this is that when I have loaded an ns form and it has an error, I am unable to load the correct code because it keeps giving me the previous error.
1) Exit the nrepl (currently I just kill the buffer)
M-x nrepl-quit
2) Reload everything in the nrepl. (I have this problem when I haave
loaded the ns, and it has an error. Then I am unable to load the
correct code, it still keeps giving me the previous error)
You can switch to the buffer and use C-c C-k to load the buffer, or just use C-c C-c to eval an expression. Another option would be:
(use :reload 'my.namespace)
in the REPL.
Check out Stuart Sierra's tools for namespace management at the repl, and read the blog post where he explains how to use it effectively. With a little bit of coding discipline, you won't have to exit your nrepl anymore (or less, in any case).
Good luck.

Why clojure starts with 'M-x slime' for my Aquamacs without any setup?

I have Aquamacs running on my Mac.
I installed the ESK for Aquamacs and it installs ELPA at ~/.emacs.d/elpa. With ELPA, I installed clojure-mode/clojure-est-mode/slime/slime-repl/swank-clojure.
The thing is that when I run 'M-x slime', clojure is run. Why is this? I'm curious as I don't have any setup for slime in my .emacs and even in /Users/smcho/Library/Preferences/Aquamacs Emacs/{Preferences.el, customizations.el}. I mean, I don't have (setq inferior-lisp-program "clojure") or something.
Or, does it have to do with my 'swank-clojure' installation? I see something like this at the inferior-lisp buffer.
(require 'swank.swank)
(swank.swank/ignore-protocol-version nil)
...
#ServerSocket ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=51847]
That's because of swank-clojure.el, a deprecated elisp program. Don't use it, as per my post here, on your next question. It may have bugs and thus isn't suitable to use. Use M-x slime-connect instead, after starting swank up with lein swank.
As Isaac said, swank-clojure.el sets 'slime-lisp-implementations' for clojure (in short, a way to start java with swank-clojure in classpath so that swank can be started). Then slime connects to this port and you get the repl.
The problem with this approach is that, you will need to setup classpath upfront. This gets tedious for each and every project you want to work on. So, best way is to use M-x swank-clojure-project or lein swank and then M-x slime-connect. I prefer swank-clojure-project.