Git Bash for Windows not working 'lein repl' command - clojure

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.

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.

Getting Leiningen & Cygwin Working

I am trying to get Leiningen and Cygwin working together.
One of the problems I think I have is that I have Java installed in "C:\Program Files\Java..." directory. The space appears to be causing issues.
When I try to run the lein script in Cygwin, I am getting the following error:
./lein: line 325: C:\Program Files\Java\jdk1.8.0_05\bin\java.exe : command not found
Then I thought the issue was the space. So I changed line 325 from:
"$LEIN_JAVA_CMD" \
to (for testing purposes):
"$'C:\\\Program Files\\\Java\\\jdk1.8.0_05\\\bin\\\java.exe'" \
But, I am still getting this error:
./lein: line 325: $'C:\\Program Files\\Java\\jdk1.8.0_05\\bin\\java.exe' : commande introuvable
However, this file clearly exists:
Owner#Owner-PC ~
$ ls -alh $'C:\\Program Files\\Java\\jdk1.8.0_05\\bin\\java.exe'
-rwxr-xr-x 1 Owner None 187K 8 mai 15:39 C:\Program Files\Java\jdk1.8.0_05\bin\java.exe
The lein script appears to be properly configuring Leiningen for Cygwin, however I can't get it to work.
Note that I previously installed Leiningen outside of Cygwin (I was running it in Windows' normal shell).
What could be wrong with my setup, any ideas?
I use Leiningen via Cygwin with no problems.
Start over
Start over with a fresh copy of the lein script. There should be no need to edit it.
Set your PATH to include java
The easiest solution is to set your path in ~/.profile to include the path to Java's bin directory. Lein will then find java on the path and you'll have access to java and its related tools in your shell.
export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.8.0_05/"
export PATH="${JAVA_HOME}/bin/:${PATH}"
Restart your shell or source ~/.profile. Verify that which java finds java command. And run java to verify you get the help output.
And/or explicitly set the LEIN_JAVA_CMD and JAVA_CMD variables
Alternatively, set the LEIN_JAVA_CMD and JAVA_CMD variables used by lein in your ~/.profile
export JAVA_HOME="/cygdrive/c/Program Files/Java/jdk1.8.0_05/"
export LEIN_JAVA_CMD="${JAVA_HOME}/bin/java"
export JAVA_CMD=`cygpath -w "${LEIN_JAVA_CMD}"`
Restart your shell or source ~/.profile.
Note: You can also set a separate LEIN_JVM_OPTS and JVM_OPTS if desired, but this should not be necessary.
If you have lein previously installed on Windows and want to reach it from cygwin, then do:
on cmd:
cd C:/Users/%userprofile%/.lein/bin
mklink lein lein.bat
on cygwin:
export CYGWIN=winsymlinks:nativestrict
I feel your pain. I tried something like this myself several years ago.
You have at least two problems. One is getting lein to run as under unix as you noted. There are really two lein scripts - one for unix, the other a batch script for use under windows.
Your bigger problem is java.exe - getting the windows java executable to behave as a cygwin shell, and particular the unix lein script running in a cygwin shell, expects is messy and fragile undertaking.
I would strongly recommend either using a clojure ide that supports Windows (perhaps LightTable) or installing a full linux virtual machine with the unix java SDK and doing clojure development in that environment. Ubuntu running on virtualbox is freely available and an option I have used in the past for just this purpose.
You need to create a symbolic link to the "lein.bat" file.so you use it properly in Cygwin.
Open CMD and go to the ".lein" path (cd %userprofile%\.lein\bin) and run this: mklink lein lein.bat
#a-webb is almost right ,but there are still some steps to complete.First,you will find a folder called “.lein” where you run the lein script in cygwin,go in,copy the folder "self-installs" inside to C:\Users\yourUserName.lein
,then,add C:\Users\yourUserName.lein\bin to the environment variable $Path.
I've found the easiest way is to:
Install via the windows binaries and
Copy the lein bash script into .lein/bin
Then it should just work in cygwin.

error while using nrepl-jack-in

I am getting the below error whenever I try M-x nrepl-jack-in -
error in process sentinel: Could not start nREPL server: /usr/bin/lein: line 260: java: command not found
I am able to start the repl without any issues by lein repl or lein2 repl - both work.
Thanks,
Murtaza
I had the same problem. Let me guess, you are launching Emacs from the application launcher? Applications launched this way apparently do not use your .bashrc file. If you do your PATH set up in your ~/.profile file instead it should work. You'll need to log out and in for it to take effect though.
You may have an different environment inside emacs from inside your shell. Is Java installed in the same place as lein? If you type M-x shell, and run java -help there does it work? What about "M-x shell-command java -help"

Clojure : 'lein repl' history grepping?

I often find myself executing commands like this at bash :
history | grep 'find'
For example to look up a fancy find / xargs command i might have ran.
Im wondering --- where does the "lein repl" store its historical data ? It would be nice to know, because then I could write a leingrep.sh script, which simply grepped through the lein history session.
It is obvious that this is on disk somewhere, since history is preserved from one repl to the next.
Lein is using either readline (if you have it installed) or jline (if you are so unfortunate, I recommend installing readline). I wouldn't bother trying to look up the history file on disk - just press Ctrl-r, type in your search text, and keep hitting Ctrl-r until you find whatever you were looking for. This is a general readline feature, and will work in any readline app (including bash).
Once you get going with readline there are a couple controls to consider, via your ~/.inputrc file.
I'm not finding the default "history size" documented, but I'm guessing it's only ~100. I often lose some older entries I wished I'd had around. Also, "vi-mode" is wonderful thing for vi users. Together these (with a bonus) in .inputrc become:
set history-size 10000
set editing-mode vi
# Only require 1 tab for completion.
set show-all-if-ambiguous on
Note that this config will affect a lot of repl tools, like gdb, irb/pry, lein, psql, ipython, R, ...
Looking at my home folder. Seems like the lein repl has chosen jline.
The files where the history is stored is as follows:
~/.jline-clojure.main.history
~/.jline-reply.history
Hope this helps.
I installed lein through Homebrew on my Mac:
brew install leiningen
and the history file is stored in my home directory:
~/.lein/repl-history
Version is:
% lein --version
Leiningen 2.6.1 on Java 1.8.0_77 Java HotSpot(TM) 64-Bit Server VM
(I don't have no ~/.inputrc nor ~/.jline*)

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.