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.
Related
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.
I'm using emacs live to set up my clojure environment. 1) What command would cause nrepl to try and evaluate the entire file upon jack-in? 2) Is there some place where session state is saved?
For some unknown reason emacs is now trying to evaluate the entire clojure file when I execute M-x nrepl-jack-in. It used to not do that. I have an error in my file and, since the execution fails, I can't start nrepl with this file. This is not the first time I've run into some semantics that change. I've tried restarting emacs but that doesn't help.
Thanks
nrepl's jack-in behavior is dependent on the location of the file backing the buffer you are visiting when you invoke the jack-in command.
To get a vanilla no-project repl, be sure to run nrepl-jack-in from a buffer where there is no Clojure project. To run a repl in a specific project via jack-in, run it while visiting a file in the top level of that project (project.clj is a prime cantidate).
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.
I use Emacs for clojure development, because Swank-clojure is a great tool.
But once I get an error on slime-repl buffer, the error remains, though I fixed it or it's no more.
Reproducing way:
Create a clojure project with a leiningen. $lein new myproject.
At core.clj, define a function that (defn f [] (+ 1 1))
Start a swank-clojure. M-x clojure-jack-in.
On a slime-repl buffer, evaluate (f). Of course it returns 2.
On a slime-repl buffer, evaluate (g). Of course it gets error Unable to resolve symbol: g in this context
After that, this error always appears when I try to evaluate anything in the slime-repl buffer.
C-c C-k doesn't help. So I always restart Emacs.app when I got an error on slime-repl buffer.
My Environment:
Mac OS 10.7.3, Cocoa Emacs 23.4.1, clojure-mode 1.11.5(from a Marmalade), leiningen 1.7.0.
In order to confirm an error and close the debugger, hit Q in the debugger window. (There may be restarts other than the QUIT restart available, but this, at least, should always work.)
I'm using Emacs, integrated with Leiningen's swank. Each time I need to start working with .clj file I have to:
Run emacs pack/my-ns.clj from console.
Type M-x lein-swank.
Compile buffer.
In Clojure REPL change namespace, i.e. type (in-ns 'pack.my-ns).
How can I automate this process to just run from console something like emacs-clj pack/my-ns.clj and get my environment ready to use?
I don't have an answer to the question you posed, but you should be able to replace your 4th step with C-c M-p while in your Clojure file and then emacs should prompt you as to what namespace you want to be in with the namespace of the file auto-detected so you can simply hit enter. C-c M-p maps to slime-repl-set-package.
Update:
Just stumbled across this. Should be able to take what is said in that answer and modify it so upon initial connection to swank files get compiled. Could also set it up to automatically switch to namespace and make the repl buffer active.
Swank should automatically load the namespace pointed to by :repl-init-script in project.clj when it starts, so if you want to set that to your starting namespace, that should get you started.