Unable to get `cider-jack-in` to work - clojure

See an error message: error in process sentinel: Could not start nREPL server: That’s not a task. Use "lein help" to list all tasks.
In the *Messages* buffer, the full form of the error is:
error in process sentinel: nrepl-server-sentinel: Could not start nREPL server: That’s not a task. Use "lein help" to list all tasks.
M-x cider-version shows
CIDER 0.15.0snapshot (package: 20170525.255)
Tried fiddling around with ~/.lein/profiles.clj to explicitly add in
{:user {:plugins [[cider/cider-nrepl "0.15.0snapshot"]]}}`
... but that didn't change anything.
(getting back to Clojure after a while with a "fresh" install (Emacs, clojure-mode, cider, etc. so might have missed some small environment setup step, just don't know what that is!)

Turns out the incompatibility was not with the nRepl middleware, but with Leiningen itself.
Once I uninstalled the version I had installed using apt-get, and self-installed using the downloaded script, and made sure this new version was what which lein led to, this problem went away.
More details: Running cider-jack-in was triggering a call to lein update-in with further arguments, but the version of Leiningen I had simply didn't show update-in as one of the options when I ran lein help.

Related

How to load this Clojure project in my cider REPL? Why I am receiving the message "The clojure executable isn’t on your ‘exec-path’" (NixOS)?

Recently, I started learning Clojure. I have been using Emacs, and cider (REPL). Also, I have NixOS as OS.
I have been able to successfully program in Clojure using this environment. Usually, I create the files, then I go to the directory where the .clj are, I execute cider-jack-in, a REPL is created, and interactive programming magic happens. Thus, I am able to load the file, load new versions of old functions, etc.
It also works if I just start Emacs and execute `cider-jack-in. The mini-buffer asks:
Are you sure you want to run `cider-jack-in' without a Clojure project? (y or n)
After answering y, everything works fine.
While reading the book Clojure for the Brave and True, I have also successfully used:
$ lein run
For learning purposes, I decided to explore some open source projects. Thus, I did a git clone of this open-source project.
Being on the folder, I decided to reproduce the steps that have worked so far. However, it does not work. After executing cider-jack-in, the mini-buffer echoes the following:
The clojure executable isn’t on your ‘exec-path
Also, if I try with lein I get:
[pedro#system:~/projects/http-cron]$ lein run
No :main namespace specified in project.clj.
Obs.: If I type clojure on the shell, this is what I get:
[pedro#system:~]$ clojure
The program 'clojure' is not in your PATH. You can make it available in an
ephemeral shell by typing:
nix-shell -p clojure
Why is this happening?
How can I solve this (considering that I am using NixOS)?
Going the imperative route, depending on whether you use NixOS with channels (default) or flakes, you can permanently install clojure into your environment with:
channels: nix-env -f '<nixpkgs>' -iA clojure
flakes: nix profile install nixpkgs#clojure
The preferred (declarative) way would however be adding clojure to environment.systemPackages in /etc/nixos/configuration.nix and running sudo nixos-rebuild switch.

Git Bash for Windows not working 'lein repl' command

I'm actually using git bash instead of default windows command shell (cmd).But I cannot run 'lein repl' in git bash. It doesn't show anything and I must press crtl + c to regain control.
Any suggestion?
Thank you.
-- EDIT
I'm running lein instead of lein.bat because I added alias lein=lein.bat in my .bashrc, so I don't think it is a problem.
lein run is working fine in Git Bash and leiningen works fine in windows cmd. The problem is explicity with lein repl.
When I run which lein I got which: no lein in ([MY-PATH-VAR])
First Check if you have installed lein.bat in windows using below command in command prompt
lein --version
Then if lein is available, then in your git bash type the below command
alias lein='lein.bat'
Thein run your lein command it will work for sure...
I had exactly the same problem as ThomasH where calling lein repl from an Emacs shell would get me the introductory messages and a prompt ...
nREPL server started on port 55801 on host 127.0.0.1 - nrepl://127.0.0.1:55801
REPL-y 0.4.4, nREPL 0.8.3
Clojure 1.10.1
Java HotSpot(TM) 64-Bit Server VM 15.0.2+7-27
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
... but seemingly freeze when I try to get it to do anything, like:
user=> (+ 1 2 3 8)
When I open up the Task Manager, I could see the underlying Java program continuously at ~30% CPU for no apparent reason, and the only way I could reliably get out of it was to end the Java process from there.
But through a lot of effort, I finally figured out that the reason this was happening was a shell environment variable TERM=emacs. Whenever you call M-x shell, the function comint-term-environment puts it in for you.
(According to the source code in comint.el, it's done so that it "lets us specify a width". And it also mentions that "Some programs that use terminfo get very confused if TERM is not a valid terminal type". So there you have it - it looks like Java is one of those.)
To resolve this, you can set the variable system-uses-terminfo to 't before calling M-x shell.
(setq system-uses-terminfo t)
After having done so, Java is now finally responsive and I can evaluate things in the repl.
user=> (+ 1 2 3 8)
14
If you have this problem and got fortunate enough to stumble here, I hope this helps! =D
The following worked for me to get this running in Git bash on Windows 10. When I originally got this working, it was freezing, but this post helped me figure out how to fix by including winpty.
If you haven't added the lein.bat file to your Path variable, then do steps 1-3. Otherwise, skip to 4. In the System Properties -> Advanced -> Environment Variables area, select the Path variable
Click Edit and add the directory containing lein.bat to this. Mine was C:\Program Files (x86)\lein - lein.bat was stored inside the lein folder
Click OK until you close out of the prompts
Confirm the update worked by opening a command prompt (windows key, then type cmd)
Enter lein. If you haven't already, it should prompt you to run the install command. Do this if prompted, then enter lein again to make sure it worked (should output help menu)
Close out of Git bash if already open, then open again
Enter alias repl='winpty lein.bat repl'. You can choose what you want the alias to be, I used repl
Type repl (or whatever alias you added). Should take a second, then begin a REPL prompt
Using GitBash as your terminal, you can install the lein script rather than the lein.bat script.
The lein script will run correctly in GitBash (as it is effectively a Unix environment).
I recommend installing the lein script in a directory called bin in your user account directory, e.g.:
c:/Users/your-account/bin
Placing the lein script in bin will allow you to run the lein command anywhere on the GitBash command line.
A Note about Emacs, lein and windows
The lein script will also be called correctly from Emacs, assuming you run Emacs from the GitBash terminal, ie. runemacs. Add Emacs install directory to your user account PATH environment variable and GitBash will find it on the command line.
Emacs installed on Windows works better when run from the GitBash terminal, as you can then use ediff in Emacs, which requires the diff command that GitBash terminal provides.
My recommended Emacs installs for windows
zklhp emacs-w64 optomised
Chocolatey Emacs 64bit
My experience was that lein repl (and I do use the lein bash script) would start up ok, also printing the startup messages of the lein command to the shell, but would then stop to output anything (although the process might be running fine), part. not providing an interactive prompt (except for the first), not echoing user input (except for the first), nor printing evaluation results. When terminating the process with Ctrl-C all my inputs would be passed to the underlying shell (with funny results like $ (+ 3 4) bash: +: command not found).
My solution is to use Git CMD for interactive commands like lein repl, lein figwheel etc., which (unfortunately, as it might seem) works fine. Running a Git sh process inside a different terminal emulation (Cmder) also gives me a working interactive environment.

ClojureScript bRepl does not respond at all

I've been tinkering with clojure and clojurescript for some time and I always found the browser repl to be extremely unresponsive. It usually hangs on without giving a result, or throws a broken pipe exception. Now I'm in a situation where it always refuses to work.
Let's say I download the modern-cljs tutorial part 2 and I do all the steps to start the page, load the compiled javascript and start the bRepl. When I try to evaluate something as simple as (+ 3 4) well, it just doesn't work.
I'm on OSX 10.8.4 and my leiningen version is 2.3.2 on Java 1.6.0_51 Java HotSpot(TM) 64-Bit Server VM. Any help is extremely appreciated.
I would suggest to clone the modern-cljs repo, then checkout the tutorial-02 branch, then clean and recompile.
git clone https://github.com/magomimmo/modern-cljs.git
cd modern-cljs
git checkout tutorial-02
lein do clean, cljsbuild clean
lein cljsbuild once
Be sure to have your http-server running (I'm assuming the port is 3000) and its root set to modern-cljs/resources/public directory
Then run the repl-listen substask as follows:
lein trampoline cljsbuild repl-listen
Wait for the cljs prompt. Then visit the localhost:3000/simple.html URL and wait that the connection with the brepl is ready.
At the cljs prompt you should now be able to evaluate cljs expressions. Eventually, reload the above URL.
If it still does not work, try to delete your maven repository:
rm -rf ~/.m2/repository
and redo everything from the lein do chain of commands.
Eventually you can follow the https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-18.md#the-need-of-a-more-comfortable-brepl-experience tutorial to set up a more comfortable bREPL which uses https://github.com/cemerick/piggieback
HIH
I've had a few problems with this topic too. And here are the tricks that help me:
Clean leain deps: rm -rf ~/.m2/*
download lein deps: lein deps in your project root
I saw this message: "broken pipe" when there was too much time from the last brepl interaction. So, refresh the browser and that's all
sometimes my brepl hung on the first time i was trying to evaluate the code, again try to refresh the browser
don't forget to run: lein cljsbuild once before start the brepl
Good luck
PS: Anyway if you want to have a comfortable brepl experience you have to take a look to https://github.com/cemerick/austin . I have tested this brepl and works fine https://github.com/juanantonioruz/client
You should try using Chromium unsafely:
OS X:
open -a Chromium --args --disable-web-security
Linux:
chromium --disable-web-security
Then visit your page in the unsafe browser and try to connect to the brepl.
Explanation:
Because while brepl is running on port 9000, the web server hosting the page is necessarily using a different port, which constitutes XSS (see [this stack overflow discussion]).
The easiest way to get around this is to use Chromium unsafely for debugging, but you can enable XSS by some other means if you want.
What ClojureScript release are you specifying in your project.clj? If you aren't specifying a specific release, this likely the source of your troubles. 0.0-1913 is the latest one.
I've also seen a complete hang in the REPL when I forget to call repl/connect from within the browser. Since there is no output, it's hard to diagnose. It's worth verifying before you try more intrusive remedies.

Slimv setup for clojure

Has anyone recently tried to setup slimv for clojure that would be willing to describe how to do so? Slimv will currently autodetect lisp on my machine but fails to load on .clj files. I've also added the following to my .vimrc
let g:slimv_swank_clojure = '! xterm -e lein swank &'
but it has no effect (lein is installed and executable).
Sorry if this is a basic question but I am very new to both vim and clojure.
First you should check in your terminal command prompt that lein swank does really run the swank server from within the directory where your .clj file resides. If it doesn't start then you need to make a command that runs the swank server, then embed it in '! xterm -e {swank_command} &' and store it in g:slimv_swank_clojure.
If the swank command looks OK, then you should check it from within Slimv via :echo SlimvSwankCommand() that prints the actual swank command built and used by Slimv.
You may also run the swank server in a separate terminal window outside of Vim, Slimv will connect it if the port number is the same on both sides (4005 by default).
There is another Swank server embedded in Slimv, but this is only autodetected if the lein command does not exits for the user (and g:slimv_swank_clojure is not explicitly defined).
If still no luck then please contact me, I'm the author of Slimv, you can find my email address in the documentation.
Unless you are certain there are something you need in Slimv, there's very good plugin called VimClojure.

How to fix backtrace in clojure & slime

I'm a clojure noob trying to get emacs & slime set up. There doesn't seem to be one true way to do this, so I've followed a few blog posts and the swank-clojure and leiningen READMEs.
Mostly it works. My problem is that if I try to select restart 0 [QUIT] from a backtrace, I get
'error in process filter: Wrong number of arguments: nil, 0'
(I also see a warning on 'M-x slime-connect' about slime and swank being mismatched versions, but Googling suggests this is expected).
This is Debian Lenny. I got slime via 'git clone git://git.boinkor.net/slime.git'.
Clojure and clojure-contrib are 1.2.0, and swank-clojure is 1.2.1.
Anyone seen this? Alternatively, is there an up-to-date list of compatible versions of all the pieces? Many thanks.
Edit:
Looks like it is probably this issue. I followed the same blog post as the OP in that thread.
Edit:
Yes. Getting slime and slime-repl packages using ELPA fixed it.
Don't get slime via git, but use ELPA. See the links in my edits to the question.
the clojure ecosystem has changed a lot over this last year so many of the most linked tutorials sort of do things the hard way. you dont really need to build clojure/contrib and install it anymore. both Maven2 and leinengen do this ver well for you.
you may be able to get up and clojureing just by installing lein (from the tutorial) and then making a new project. this is enough to keep me happy even on my larger projects. you dont really need to install clojure system wide.
from a (ubuntu-10.10) system that has never seen clojure before i run:
dev:~$ lein new foo
Created new project in: foo
dev:~$ cd foo
dev:~/foo$ ls
project.clj README src test
dev:~/foo$ lein repl
Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.pom from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.pom from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.pom from clojure
Transferring 4K from clojure
Downloading: org/clojure/clojure/1.2.0/clojure-1.2.0.jar from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.jar from central
Downloading: org/clojure/clojure-contrib/1.2.0/clojure-contrib-1.2.0.jar from clojure
Transferring 466K from clojure
Copying 2 files to /home/arthur/foo/lib
"REPL started; server listening on localhost:20092."
user=> (+ 1 2 3)
and thats all you really need. have fun :) (of course there is a LOT more to the clojure ecosystem though there is no need to really rush into it)
ps: add swank-clojure as a dev dependency and run lein swank and then slime-connect from within emacs
ps: I hit 'q' to exit the backtraces.
Here's an update for google: things have changed since the previous answers and the correct way to start swank/slime is now via the clojure-jack-in command in recent versions of clojure-mode, which uses the corresponding lein jack-in command in recent versions of swank-clojure. Using clojure-jack-in, all the Emacs dependencies other than clojure-mode are automatically installed for you. DO NOT install slime.el or slime-repl.el manually, via ELPA or via git.