Running Clojure with 'lein swank' on Aquamacs problem - emacs

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

Related

Unable to install cider to emacs - package not found

Fresh install of Ubuntu 20.04
Added openjdk-11 and lein 2.9.3
$ sudo apt-add-repository ppa:kelleyk/emacs
Installed
GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14)
of 2020-03-26, modified by Debian
Tried the instructions on the cider Getting Started page
M-x package-refresh-contents
M-x package install <RET>
cider <RET>
The cider package isn't found. Tried to package-list-packages - list doesn't contain cider.
What am I missing?
Finally did the steps from the following link to get it to work
Brave Clojure book companion repo
Not sure why the cider instructions don't mention this.
You need to create a ~/.emacs.d/init.el file with the following contents
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
Save and restart emacs.
M-x package-list-packages check the archive column shows packages from gnu as well as melpa archives.
Sometimes you would see an error Failed to download ‘gnu’ archive. - this one is a flaky one. A restart and/or M-x package-refresh-contents fixed it for me.
Now we have the sources configured correctly.
Install:
M-x package-install <RET> cider <RET>
M-x package-list-packages - Move to the end of the listing to see Status=installed packages.
Test: M-x cider-jack-in. Answer no to the prompt indicating you are not in a clojure project. Soon you should be dropped to a user> prompt - ready to REPL and roll.
You may also consider trying out popular existing "bundle setups' like Spacemacs and Prelude Both of which have all the tooling necessary for Clojure development built-in.
Instead of modifying .emacs or init file manually, you can just change the package-archives variable by typing the following:
M-x customize-variable package-archives
By default, you should only have a GNU source set. Go ahead and add Melpa's name and URL (https://melpa.org/packages/) too by clicking INS. Then apply the changes. Next, type the following commands into the terminal:
M-x package-refresh-contents [RET]
M-x package-install [RET] cider [RET]
You should be all set.
CIDER is available on the two major package.el community maintained repos - MELPA Stable and MELPA.
After adding the following in my ./emacs, i could install CIDER.
(setq package-archives
'(("Elpa" . "https://elpa.gnu.org/packages/")
("Melpa Stable" . "https://stable.melpa.org/packages/")
("Melpa" . "https://melpa.org/packages/")
("marmalade" . "http://marmalade-repo.org/packages/"))
package-archive-priorities
'(("MELPA Stable" . 10)
("GNU ELPA" . 5)
("MELPA" . 0)))

process inferior-lisp not running

I installed sbcl
sudo apt-get install sbcl
then loaded quicklisp
sbcl --load ~/Downloads/quicklisp.lisp
then ran the installation command for installing quicklisp
(quicklisp-quickstart:install)
added quicklisp to my init file
(ql:add-to-init-file)
and then installed slime
(ql:quickload "quicklisp-slime-helper")
which then printed out:
(load (expand-file-name "~/quicklisp/slime-helper.el"))
;; Replace "sbcl" with the path to your implementation
(setq inferior-lisp-program "sbcl")
Which I dutifully copied to my Emacs initialization file.
Upon running M-xslime I got the following error:
Searching for program: No such file or directory, sbcl
so I changed inferior-lisp-program to "/usr/bin/sbcl" as such:
(setq inferior-lisp-program "/usr/bin/sbcl")
Now, when I run M-xslime I get:
Process inferior-lisp not running
and in ielm when I enter inferior-lisp-program I get
ELISP> inferior-lisp-program
"/usr/bin/sbcl"
So I am all out of ideas of what I might have gone wrong. This is a new install by me, and I have used Common Lisp and SBCL in the past with no hiccups. What did I screw up?
edit:
It turns out I was getting this information in the **Inferior Lisp** buffer:
emacs: /usr/bin/sbcl: No such file or directory
Process inferior-lisp exited abnormally with code 127
Turns out it is because I installed Emacs via Flatpak. Emacs installed via Ubuntu's default repository is able to use SBCL and other binaries.

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

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