If I have a new lein project:
lein new foo
I then cd foo and start nREPL: lein repl. Within Emacs via nrepl.el I connect to the nREPL server and navigate to foo/src/foo/core.clj and eval the ns form. Everything works perfectly.
Now, I kill the JVM (shock horror!) and then restart nREPL with lein repl again. After reconnecting Emacs to the nREPL server, when I try to evaluate the ns form again I get the error:
Namespace not found.
It seems that nrepl.el must keep some per-buffer state which doesn't port across JVM instances rendering the buffer broken. If I kill the buffer and re-open it, then things work perfectly again.
It would be nice if there was a process-disconnected hook we could tap into, which would allow us to reset the buffer local vars.
Perhaps such reset code could be triggered by nrepl-sentinel?
Yes I think we would need to do something like this.
The local fix I mention in the comments in issue #138 address this issue. Let me know if you're interested in a pull request, or whether you'd like the fix the issue another way. I'm a bit loathe at having such a significant fork in Emacs Live, but I got crazy annoyed with the current behaviour. I'd rather have something that was blessed by the official nrepl.el.
Since moving from clojure-swank I am constantly battling the "Namespace not found." issue as described above. Until this is resolved is there something I can do to "fix" this without restarting Emacs every time I kill my JVM? Thanks :)
Hi @jappy, you could take a look at https://github.com/samaaron/nrepl.el/tree/ns-fix3 which is what I currently use in Emacs Live to avoid this issue until an official fix is found.
@jappy I have just committed a fix for #187 which should help. Invoking M-x nrepl-quit will reset the buffer local vars, and then you can restart with M-x nrepl. I think this should resolve the issue for you I believe.
I plan to wire this behavior into the sentinel as @samaaron suggested, so that everything is reset when the connection drops and will be in a consistent state when reconnected.
You guys are the best. Thank you! :)
I have added a nrepl-disconnected-hook which by default resets the buffer locals and disables nrepl mode when disconnected.
@samaaron Do you consider this issue addressed? If not - feel free to create that PR you mentioned a few comments back :-)
Yes, this issue is fixed in the lastest master. I'm pretty sure I can retire my Emacs Live fork of nrepl.el at long last :-)