Executing Clojure in Emacs with `cider-jack-in` - emacs

I'm trying to run Clojure emacs with cider package installed.
I use Emacs 24.5.1 on Mac OS X 10.10.4.
I downloaded lein script and copied the script in ~/Dropbox/bin.
I checked with lein repl that Clojure works fine.
cider package is installed with M-x package-install. I edited the ~/.emacs.d/init.el to specify the lein script: (add-to-list 'exec-path "~/Dropbox/bin") with the hint from Can't launch `lein` REPL in Emacs.
However, when I started emacs and run M-x cider-jack-in, I have this error message:
When I started lein repl and executed M-x cider-connect (http://xahlee.info/clojure/clojure_emacs_cider.html), I can have the cider-repl running in Emacs.
What might be wrong?

The quickest fix was to symbolically link lein to the path where Emacs can find it. This line of code fixed the issue.
sudo ln -s ~/Dropbox/bin/lein /usr/local/bin/lein
I summarized the steps to install the cider package for running Clojure on emacs without any errors or warnings.
cider - https://github.com/clojure-emacs/cider
Installation
Download lein https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
I copied the file ~/Dropbox/bin after making it executable.
It looks like that /usr/local/bin is not the path that Emacs finds the binary automatically, so I had to set it up.
Run sudo ln -s ~/Dropbox/bin/lein /usr/local/bin/lein
Update ~/.emacs.d/init.el to specify the location of lein script:
(add-to-list 'exec-path "/usr/local/bin")
Update ~/.lein/profiles.clj
Installation of cider-nrepl
{:user {:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]]}}
run lein deps
Errors and solutions
If error The lein executable (specified bycider-lein-command' or cider-boot-command') isn't on your exec-path occurs:
make the symbolic link, and update the init.el as is explained.
If error "Symbol's function definition is void: clojure-project-dir" occurs, it's because of the package version mismatch.
http://www.braveclojure.com/using-emacs-with-clojure/
delete the old packages in ~/emacs.d/elpa
clojure-mode
cider-*
Then, run package-install in Emacs
clojure-mode
cider
Now, all the warnings are gone.
References
Can't launch `lein` REPL in Emacs
Executing Clojure in Emacs with `cider-jack-in`
cider - https://github.com/clojure-emacs/cider
Added
For Mac OS X, brew install leiningen can install the lein, but this caused an issue as in How to upgrade nrepl version of leiningen?. This is the message from the lein brew.
nREPL server started on port 61216 on host 127.0.0.1 - nrepl://127.0.0.1:61216
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14
I had to use the lein from the lein site to get the correct version of tools.
Retrieving org/clojure/clojure/1.2.0/clojure-1.2.0.pom from central
nREPL server started on port 61279 on host 127.0.0.1 - nrepl://127.0.0.1:61279
REPL-y 0.3.7, nREPL 0.2.7
Clojure 1.7.0

Another easy solution is to just use homebrew. While homebrew is overkill just for installing lein, if you already use it, then all you need to do is run
brew update
brew install leiningen
and your done. I use homebrew to install emacs and some other useful apps, so I already have it on my system.

Related

Emacs-Cider nrepl warning

I have installed and setup Emacs for clojure using this wonderful tutorial. If i start the cider using M-x cider-jack-in the repl starts and is very nice! Now i read here that a min project.clj should be {:user {:plugins [[cider/cider-nrepl "0.9.1"]]}}, i change my project.clj in .lein deirectory (which is "0.8.1") to "0.9.1" and when i start repl again i get this warning:
WARNING: The following required nREPL ops are not supported:
inspect-start inspect-reset
Please, install (or update) cider-nrepl 0.8.1 and restart CIDER
WARNING: CIDER's version (0.8.1) does not match cider-nrepl's version (0.9.1)
Any idea how can i fix this?
Your CIDER (the Emacs application) is version 0.8.1, not your cider-nrepl. Update CIDER to 0.9.1 (e.g. from the MELPA Stable repository) and the warning will disappear.

How to upgrade nrepl version of leiningen?

I'm using leiningen and emacs + cider for clojure development. A few days ago, after I upgrade cider through emacs package manager, I'm getting the following warning message when I run M-x cider-connect or M-x cider-jack-in.
; CIDER 0.9.0snapshot (package: 20150222.137) (Java 1.8.0_31, Clojure 1.6.0, nREPL 0.2.6)
WARNING: CIDER requires nREPL 0.2.7 to work properly
user>
The warning message clearly says that I have to upgrade nrepl to 0.2.7, however, I don't know how.
I installed leiningen via brew, and it uses nrepl 0.2.6.
$ lein repl
nREPL server started on port 53218 on host 127.0.0.1 - nrepl://127.0.0.1:53218
REPL-y 0.3.5, nREPL 0.2.6
Clojure 1.6.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_31-b13
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Javadoc: (javadoc java-object-or-class-here)
Exit: Control+D or (exit) or (quit)
Results: Stored in vars *1, *2, *3, an exception in *e
user=>
The content of leiningen profile is:
{:user {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]}}
Question:: How to upgrade the version of nrepl used by leiningen?
I've just had this problem, and I solved it by adding an explicit dependency on the newer version of tools.nrepl to profiles.clj. My ~/.lein/profiles.clj:
{:repl {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]
:dependencies [[org.clojure/tools.nrepl "0.2.7"]]}}
No idea whether that's the best or official way to do it, tho'.
an additional note on top of #matthew-moss's: the tools.nrepl dependency line is only used if you run lein repl from within a clojure project. if you just run lein repl from your home directory, for example, you end up using the version of tools.nrepl that is compiled into leiningen. No idea why.
Hope that saves somebody time.
lein has an upgrade command so in the simplest case
lein upgrade
In case you installed leiningen with a package manager you might need to do something like the below (example for OS X, linux distros have their own wonderful package managers):
brew unlink leiningen
brew update
brew install leiningen
As an addition to the accepted answer: adding dependency on 0.2.7 in user profiles.clj worked for me some days ago but then suddenly I got back to the 0.2.6 warning. Asking "lein deps :tree" had this line in it:
[org.clojure/tools.nrepl "0.2.7" :scope "test" :exclusions [[org.clojure/clojure]]]
Which gave me a clue that probably the lein-test-refresh plugin (defined in the same profiles.clj) is causing some confusion here. Reading some more about profiles I learnt about the ^:replace hint. This line in dependencies works now for me:
^:replace [org.clojure/tools.nrepl "0.2.7"]

Installation of cider-nrepl

I've installed CIDER 0.7.0 and now when I start it inside of Emacs (via M-x cider-jack-in RET), I get the following warning:
WARNING: CIDER's version (0.7.0) does not match cider-nrepl's version (not installed)
I've downloaded cider-nrepl and found out that it consists of closure code, not emacs lisp code. Since I've started exploring Clojure world just today, and there is no installation instructions on the project page, could you tell me how can I install cider-nrepl?
You need to put it into lein project.clj or into global lein configuration. Excerpt from official documentation:
Use the convenient plugin for defaults, either in your project's project.clj file or in the :user profile in ~/.lein/profiles.clj.
:plugins [[cider/cider-nrepl "0.7.0"]]
A minimal profiles.clj for CIDER would be:
{:user {:plugins [[cider/cider-nrepl "0.7.0"]]}}

Exception when connecting to swank-server

When trying to M-x slime-connect to a swank server running in a clojure app I get a user> prompt but as soon as I start typing the connection breaks as the app throws:
exception in read loop
java.lang.RuntimeException: Invalid token: swank::
further down the stack I see:
unreadable message: (:emacs-rex (swank:autodoc (quote ("ns" "" swank::%cursor-marker%)) :print-right-margin 80) "user" :repl-thread 4)
When I start slime I get:
Versions differ: 2010-07-21 (slime) vs. 20100404 (swank). Continue? (y or n)
But this mismatch should be OK.
I have swank-clojure 1.3.3 in my project's dependencies and I have installed the leiningen plugin as well. I start swank-server with (swank.swank/start-server :host "localhost" :port 4005) from inside the app.
My environment:
GNU Emacs 23.2.1 on debian squeeze (stable) amd64
slime installed through the debian repositories
sun-java6-jre
leiningen 1.6.2
swank-clojure 1.3.3
clojure 1.3.0
I should also mention that M-x clojure-jack-in works fine but I need to be able to connect
remotely.
Could the version mismatch be the culprit? Anyone using a similar working setup?
You should upgrade to swank-clojure 1.4.0 and use the version of slime that is bundled with it. There's a 'clojure-jack-in' command in clojure-mode that will handle the loading of slime when you 'jack-in' from a clojure project to swank. All the errors you're seeing will be gone. slime-disconnect[-all] is the correct way to exit.
I uninstalled the debian version of slime and installed slime-repl through ELPA. Everything works now although the installation seemed to fail with a compilation error: lime-repl.el:122:39:Error: No setf-method known for slime-connection-output-buffer
Another question though: what is a "polite" way to exit slime? If I use M-x slime-disconnect, it causes an exception in the remote swank-server instance:
java.lang.Exception: Error reading swank message

Running Clojure with 'lein swank' on Aquamacs problem

I installed leiningen and ran lein swank,
sudo lein deps
lein swank
Aquamacs has everything about SLIME, so it's OK.
Solution to this problem
David helped me to be out of trouble.
As Aquamacs has built-in SLIME, I didn't need anything complex about the setup. I just needed one line - (slime-setup '(slime-repl)).
I had the same problem if I used (slime-setup '(slime-fancy)). Changing it to (slime-setup '(slime-repl)) fixed it.
I found this the easiest setup for the latest version of everything. Here's a quick summary where I"m assuming you have leiningen installed.
Install the swank-clojure plugin
$ lein plugin install swank-clojure 1.3.2
Create your clojure project
$ lein new test-project
$ cd test-project
$ lein deps
Then open one of the clojure files from your project in emacs and run clojure-jack-in
M-x clojure-jack-in
You are now in a slime buffer with clojure and the dependencies for your project loaded.
I found that I needed this in my .emacs to get it to work:
(eval-after-load "slime"
'(progn
(slime-setup '(slime-fancy slime-asdf))))