How do I correctly use lein try in cider? - emacs

In Emacs/Cider, how do I correctly add some clojure libraries that I want to try?
If I do it from the shell, I just start
$ lein try clj-time
But how do I do that from the Emacs/Cider?

The easiest way is to run lein try clj-time on the command line and then connect to that repl from emacs with M-x cider (use localhost and the port number printed to the console when you started lein-try).

Related

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

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.

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"]

run sml console at emacs - searching for program: no such file or directory?

I installed SML on Ubuntu 12.04.
Here is more info:
nazar_art#nazar-desctop:~$ sml -version
Standard ML of New Jersey v110.75 [built: Mon Sep 2 23:36:16 2013]
And added to emacs this package:
M x list-packages + Enter
find sml-mode and install by mouse click.
But when I tried write easy .sml file I want to open sml console at emacs.
I press C c + C s => I see SML command: sml and press Enter.
And see this message:
Searching for program: no such file or directory
Instead of opening sml console.
I couldn't figure out why this happen?
How to solve this trouble?
Update:
Here is my which sml:
/usr/local/SML/bin/sml
and emacs version - GNU Emacs 24.3.1
Installed from here but only for emacs24, not for emacs-snapshot.
Option 4: Eval the following with: C-M-: (setq exec-path (cons "/usr/local/SML/bin" exec-path)) return/enter or put it into $home/.emacs to make it persist over all sessions.
Your problem is that the sml executable isn't on the PATH that Emacs sees.
And you can launch sml from bash probably because you modify path
in ~/.bashrc.
Option 1: modify PATH
In ~/.profile (you'll need to log out once):
export PATH=$PATH:/usr/local/SML/bin/
Option 2: create link
sudo ln -s /usr/local/SML/bin/sml /usr/bin/sml
Option 3: apt installs for me sml to /usr/bin/ (Emacs knows this path)
sudo apt-get install smlnj
Just elaborating on the steps mentioned by the Bleeding fingers:
Step1: Launch emacs from terminal.
step2: Press ctrl+x+f.
step3: You will get something in the bottom saying "Find a file:~/" then there write "/.emacs".
step4: Paste this line "setq exec-path (cons "/usr/local/SML/bin" exec-path))" in that.
step5: Press Ctrx+x+s to save the changes and then restart the emacs.

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