I tried to execute 'cider-jack-in' from emacs without a Clojure project that I simply want to run Clojure REPL. But I've found that cider is trying to run /usr/local/bin/clojure instead /usr/local/bin/lein which don't refer my profiles.clj for Leiningen settings. It's normally work with lein when I try with a Clojure project.
I'm wondering there is any reason for that even there's no problem when I tried lein repl without a Clojure project in terminal which I've expected Cider to do so, and a way for setting up to run Leiningen through Cider without a Clojure project.
I'll appreciate for any comments on this.
On CIDER 0.18 (the current stable version) you need to set cider-jack-in-default to a symbol, not a string (e.g. 'lein).
(define-obsolete-variable-alias 'cider-default-repl-command 'cider-jack-in-default)
(defcustom cider-jack-in-default (if (executable-find "clojure") 'clojure-cli 'lein)
"The default tool to use when doing `cider-jack-in' outside a project.
This value will only be consulted when no identifying file types, i.e.
project.clj for leiningen or build.boot for boot, could be found.
As the Clojure CLI is bundled with Clojure itself, it's the default.
In the absence of the Clojure CLI (e.g. on Windows), we fallback
to Leiningen."
:type '(choice (const 'lein)
(const 'boot)
(const 'clojure-cli)
(const 'shadow-cljs)
(const 'gradle))
:group 'cider
:safe #'symbolp
:package-version '(cider . "0.9.0"))
The old variable did take a string, that's true. Without seeing the complete stacktrace I can't be certain what's exactly going wrong for you. Generally it's best to bring up such problems on CIDER's issue tracker.
In case someone's wondering why now CIDER uses clojure-cli instead of lein for a projectless REPLs - our thinking was that the Clojure CLI is the only tool we can assume that every Clojure user would have, so it made for a safer default.
Try: (setq cider-jack-in-default 'lein)
Related
I have (except for some additions such as company-mode my emacs 24.5 configured as recommended in the chapter of clojure for the brave and true.
Unfortunately I ran into a problem where I tried to work through some alice in wonderland clojure katas and the REPL would not fire up in the correct namespace. I could switch to the namespace with C-c M-n and the REPL showed the namespace, however any evaluation after that gave me an error „namespace does not exist“.
I tried to update cider-nrepl (simply by changing it in ~/.lein/profiles.clj, but then it gave me an error that Cider and Cider-nREPL version numbers were incompatible. I tried to update with a simple package-install cinder which also did not work but gave me this warnings along the lines of the function cider-find-var is not known and functions being called with the wrong number of arguments.
How do I keep the packages up to date? Is my namespace issue even related to this?
Your namespace issue sounds like a different problem. This happens if you have a namespace in a file, and that file is not loaded automatically when cider starts.
You can switch the repl to that name, though none of the contents will have been loaded until you load the file by pressing Ctrl-cCtrl-k. If you add a require in core.clj (or whatever your project uses as it's start namespace) that requires the namespace in question, than that namespace will get loaded when you start cider.
on to your cider nrepl version matching problem. This can happen when a new verion of cider is released and you do something in emacs that updates the packages. then your cider version gets ahead of the nrepl version. I have had the most pleasant experience by always setting the cider-nrepl version in ~/.lein/profiles.clj to the version listed at the top of the screen when you start cider.
Update: cider nrepl config is no longer required!
The world has improved and you no longer need to set anything in ~/.lein/profiles.clj. You should remove all cider and nrepl references from that file and then install the latest version of cider.el and all this stuff will start working. Specifically cider.el now ads the proper dependency to lein when you run cider-jack-in automatically. So if you have the latest version, and start lein through cider then you no longer need to do any special stuff.
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)
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.
I just set up a new emacs installation, installed ELPA and installed swank-clojure with using ELPA. Although Clojure 1.2 is released, when I hit "M-x slime", it still downloaded Clojure 1.1 for me instead of 1.2
How do I get it to use 1.2 now that it's available? Do I have to do it manually? Do I have to wait for slime/swank to be updated to use 1.2?
Update: Thanks for the recommendations for using leiningen, but what I'm after is for emacs to just launch a REPL itself. Is this problem happening because the swank-clojure package in ELPA is not being updated?
With Leiningen 1.3, it's easy to create a standalone swank session:
$ lein install swank-clojure 1.3.0-SNAPSHOT
$ ~/.lein/bin/swank-clojure
You can add ~/.lein/bin to your $PATH to make this easier.
Then inside Emacs:
M-x slime-connect
Launching swank from inside Emacs can be done with M-x lein-swank if you are inside a project directory. However, auto-download and install of Clojure and other dependencies via swank-clojure.el is error-prone and deprecated.
I believe that with the sort of setup that you describe, M-x slime will put everything in ~/.clojure and ~/.swank-clojure on the classpath. You can customise this by setting the swank-clojure-classpath variable (I have it customised to use ~/.clojure only; that's where I put the basic set of jars useful for launching one-off experimental REPLs.
As soon as you need more stuff on the classpath, the above is inadequate. There are two options for managing those more complex cases:
Option 1: launch Swank, then connect
The most straightforward approach is to use Leiningen. Put this in your project.clj:
(defproject repl-base "1.0.0-SNAPSHOT"
:description "A project to start Swank in."
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.1"]])
Then use lein swank in your project's directory to start a swank server and use M-x slime-connect to connect to it from within Emacs.
As another possibility, David Edgar Liebke's cljr will apparently launch stand-alone Swank instances for you; consult the README for details.
Option 2: launch Swank from within Emacs
Now, to be entirely honest, I tend to start Swank from within Emacs myself -- it's maybe a bit trickier to setup (and thus possibly not advisable in the beginning), but quite convenient later on. See my answer to an older question for one version of a function I use to launch Clojure-specific Swank instances complete with proper classpath configuration for Leiningen-style projects.
I use leiningen to connect emacs slime to the clojure instance. In a project you always end up with a couple of dependencies, which leiningen nicely places on the classpath.
It uses a small clojure file to describe the dependencies, e.g. :
(defproject myprojecy "0.1.0-SNAPSHOT"
:description "A project."
:dependencies [[org.clojure/clojure "1.2.0-beta1"]
[org.clojure/clojure-contrib "1.2.0-beta1"]]
:dev-dependencies [[swank-clojure "1.2.1"]])
You can see that changing versions is just a couple of keystrokes in an editor. Leiningen downloads the dependencies from the 'net which keeps the projects really smal and fast to version control.
running lein swank starts the program and the repl in swank :
ptimac:cljhack pti$ lein swank
user=> Connection opened on local port 4005
#<ServerSocket ServerSocket[addr=localhost/127.0.0.1,port=0,localport=4005]>
you can now connect in emacs using M-x slime-connect and accept the defaults.
You just need to set the swank-clojure-classpath variable before you hit M-x slime
Say if you have the clojure.jar, clojure-contrib.jar and swank-clojure.jar under c:\jars
In the scratch buffer paste this
(setq swank-clojure-classpath '("c:/jars/clojure.jar" "c:/jars/cloure-contrib.jar"
"c:/jars/swank-clojure.jar"))
Hit C-x C-e and the M-x slime , that should do it.
For details checkout
https://github.com/jochu/swank-clojure/blob/master/swank-clojure.el#L32-34
http://en.wikibooks.org/wiki/Clojure_Programming/FAQ#Where_does_swank-clojure_.28SLIME.29_look_for_Clojure.27s_jars.3F
I'm trying to add paths to my classpath in the Clojure REPL that I've set up in Emacs using ELPA. Apparently, this isn't the $CLASSPATH environment variable, but rather the swank-clojure-classpath variable that Swank sets up. Because I used ELPA to install Swank, Clojure, etc., there are a ton of .el files that take care of everything instead of my .emacs file. Unfortunately, I can't figure out how to change the classpath now.
I've tried using (setq 'swank-clojure-extra-classpaths (list ...)) both before and after the ELPA stuff in my .emacs, and I've tried adding paths directly to swank-clojure-classpath in .emacs, .emacs.d/init.el, and .emacs.d/user/user.el, but nothing works.
What I'm ultimately trying to do is to add both the current directory "." and the directory in which I keep my Clojure programs. I'm assuming swank-clojure-classpath is the thing I need to set here. Thanks for your help.
As mac says, you can use
M-x swank-clojure-project
to establish a slime REPL to a clojure project; the command will ask you for your projects root directory, and will establish a classpath that includes a variety of directories including src/ lib/ and resources/ if they are present.
Alternatively, if you are using leiningen, you can start that in a terminal with the command
$ lein swank
from inside your project root directory. This will establish a standard project classpath (as above). From here you can connect to this running process via Emacs with the command
M-x slime-connect
Finally a third option which I'd recommend is to connect via Emacs/slime (with M-x slime-connect) to a process started by your own shell script which specifies a custom set of JVM command line arguments e.g.
#!/bin/bash
java -server -cp "./lib/*":./src clojure.main -e "(do (require 'swank.swank) (swank.swank/start-repl))"
This allows you explicit control over how the VM is started, and is likely similar to what you will likely have to do in production anyway.
You want:
M-x swank-clojure-project
This adds all jars in your /lib dir.
If you want to :use a clojure file (bar.clj), in for instance /foo you would do:
(ns foo
(:use foo.bar))
Sorry I cannot help you with an answer, but maybe your question is wrong:
I myself haven't started a clojure session from within Emacs for ages. I think the better way is to describe all your dependencies in a single place (e.g. the maven pom.xml or leiningen's project.clj) and then start a swank session with those dependencies. I.e. add the swank-clojure lib to your (dev-)dependencies and then use lein swank or maven swank (not sure about the last one -- haven't used that much and not in a while) from the command line to start a swank session and use M-x slime-connect to attach to that session.
The advantage is that you get all the things in your classpath that you need -- and not more, so you cannot mistakenly use something from the repl that your final project doesn't know about.
This blog post gives a good summary how to do this right.