Emacs (Cocoa Emacs) vs Aquamacs for running Clojure on Mac OS X - emacs

I used Aquamacs so far, and I need to install and run Clojure using SLIME. I googled to get some way to use Clojure on SLIME of Aquamacs, but without success.
Questions
Is it possible to install Clojure on Aquamacs? Or, can you guess why Clojure on Aquamacs doesn't work?
Is it normal that Emacs and Aquamacs can't share the same ELPA?
Is it possible to use ELPA to install Conjure on Emacs/Aquamacs?
I was told that one can use 'lein swank' to run as a server, do you know how to do that?
Sequences that I tried (and half succeeded)
I tried with Mac OS X Emacs, and by following the steps I could make it work. I mean, I could run Clojure with SLIME.
Emacs for Mac OS X
Step 1) Install ESK.
Git clone and copy all the files into the .emacs.d directory
Add the following code to .emacs and relaunch
(when
(load
(expand-file-name "~/.emacs.d/package.el"))
(package-initialize))
Step2) Install using ELPA
M-x package-list-packages to select packages
Install
clojure-mode, clojure-test-mode
slime, slime-repl
swank-clojure
M-x slime to install the clojure
Add the following code to .emacs and relaunch
;; clojure mode
(add-to-list 'load-path "/Users/smcho/.emacs.d/elpa/clojure-mode-1.7.1")
(require 'clojure-mode-autoloads)
(add-to-list 'load-path "/Users/smcho/.emacs.d/elpa/clojure-test-mode-1.4")
(require 'clojure-test-mode-autoloads)
;; slime
;(setq inferior-lisp-program "/Users/smcho/bin/clojure")
(add-to-list 'load-path "/Users/smcho/.emacs.d/elpa/slime-20100404")
(require 'slime-autoloads)
(add-to-list 'load-path "/Users/smcho/.emacs.d/elpa/slime-repl-20100404")
(require 'slime-repl-autoloads)
;; swank-clojure
(add-to-list 'load-path "/Users/smcho/.emacs.d/elpa/swank-clojure-1.1.0")
(require 'slime-repl-autoloads)
Aquamacs
Now I could use Clojure on Emacs, I tried the same(or very similar) method to run Clojure on Aquamacs once more.
Step 1) Install ESK for Aquamacs
Copy the files to ~/Library/Preference/Aquamacs Emacs
Modify "~/Library/Preferences/Aquamacs Emacs/Preferences.el" to add the following
(setq kitfiles-dir (concat (file-name-directory
(or (buffer-file-name) load-file-name)) "/aquamacs-emacs-starter-kit"))
; set up our various directories to load
(add-to-list 'load-path kitfiles-dir)
(require 'init)
Step2)
* Follow the same step as before to install all the (same) packages, but "M-x slime" gives me the following error message. "Symbol's function definition is void: define-slime-contrib"
ELPA
I tried to combine the packages from Emacs and Aquamacs, but they don't combine. I thought I could use the ELPA itself, not from the ESK to make it shared.
The result was not good, as ELPA couldn't download the swank-conjure package.
Success - Running Aquamacs/Clojure with 'lein swank'.
Please refer to this.

Aquamacs most definitely works with Clojure, since the author of Clojure uses it. However, I use Emacs, and after you perform the steps above in the Emacs section, I recommend checking out labrepl,
http://github.com/relevance/labrepl
If you don't have leiningen, the link to get and install it is in the instructions of the labrepl readme file. I found it extremely helpful when first learning how to set up an environment for Clojure programming. You can take apart the project.clj file in labrepl and piece together how it works pretty easily. Not to mention the lessons and training in the built in web application that comes with labrepl.
If you want to use lein swank instead:
Make sure you have leiningen installed. In your project.clj dev dependencies you want to have an entry like this:
[leiningen/lein-swank "1.1.0"]
http://clojars.org/leiningen/lein-swank
Then after you've done lein deps you should be able to run lein swank and then from within Emacs run M-x slime-connect and just press enter through the defaults.
If you're going to go this route, here is the link directly to leiningen so you can skip the labrepl repository: http://github.com/technomancy/leiningen

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.

Paul Barry gives an lecture how to use Aquamacs and Clojure.
It's simple as you can add this code to the .emacs file,
(add-to-list 'load-path "~/clojure/clojure-mode")
(setq inferior-lisp-program "/Users/smcho/bin/clj")
(require 'clojure-mode)
(setq auto-mode-alist
(cons '("\\.clj\\'" . clojure-mode)
auto-mode-alist))
(add-hook 'clojure-mode-hook
(lambda ()
(define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-sexp)))
I could run 'M-x clojure-mode', and C-c C-z for REPL.
And as is asked and answered in Running Clojure and other Lisp at the same time on Emacs, I could use both Clojure/Lisp on Aquamacs.

Related

How to stop a package from initializing with package-initialize on emacs (slime)

I've been trying to get slime+sbcl working on my emacs (26.3) for a while. I first installed slime via melpa and that didn't work. I finally got slime able to work on a clean emacs (emacs -q) using quicklisp and the following code:
(load "~/quicklisp/slime-helper.el")
(setq inferior-lisp-program "sbcl")
However, when I put it into my actual init file and run it, it doesn't work. I figured that if I put package-enable-at-startup to nil and commented out package-initialize, that slime works. My guess is that the installed slime through melpa is "overriding" the slime initialization using slime-helper. I can't uninstall slime via melpa because of package dependencies and am worried I might mess something up. But I also need all of my packages to initialize except slime. So I was wondering if there was anyway to initialize all my packages, but suppress the slime package.
I think the easiest method would be to disable the loading of "elpa slime" with package-load-list. See its documentation with C-hv package-load-list Return. In short you'd put something like this in your init file.
(require 'package)
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/")
'("gnu" . "https://elpa.gnu.org/packages/"))
(setq package-load-list '((slime nil))) ;; don't load slime
(package-initialize)
(load (expand-file-name "~/quicklisp/slime-helper.el"))
(setq inferior-lisp-program "sbcl")
package-initialize will skip loading slime (and manipulating your load-path), allowing the "quicklisp slime" to appear first on your load-path. This may or may not break dependencies loaded by the package system. If they do break, I'd see if quicklisp can manage them and deal with them that way, or I would manually manage them.

How do I change slime's default inferior lisp when emacs ignores the .emacs file?

I am trying to configure emacs24 on my Ubuntu 15.10 laptop. I have both SBCL and CLISP installed (and both will run from the command line just fine). I have Slime installed, and I configured the .emacs file thus:
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/")
(setq inferior-lisp-program "/usr/bin/clisp")
(require 'slime)
(slime-setup)
With Emacs24 running I hit M-x slime and slime starts up, but it's running SBCL, not CLISP. I don't understand why it's ignoring the inferior-lisp-program line. I know that Emacs24 is reading the .emacs file because if I delete everything in the file slime won't run at all. It just doesn't seem to care how I set setq.
I've double checked my paths and both slime and clisp are where the path descriptions indicate. Very confusing! Any help would be greatly appreciated.

Setting up SLIME & Inferior-Lisp for Clojure in Emacs

SLIME
I'm pretty new to both Clojure & emacs and I've been trying to set up SLIME for Clojure. The official documentation implicitly assumes you know what your doing with emacs. There isn't just a bunch of code you can stick into your configuration files. Since I am interested in Clojure for Data Analysis, I don't really want to deal with Leiningen if at all possible, but I want the dynamic environment that slime provides.
I have installed Clojure from git in /opt/clojure/ and clojure-contrib in /opt/clojure-contrib and I can get a repl. I installed swank-clojure, clojure-mode, and slime from github in `~/.bin following this tutorial. I changed a few things around when this wasn't working by adding some stuff from the comments section of the official documentation.
When I start slime with M-x slime I get a continuous Polling "/tmp/slime.14113".. (Abort with 'M-x slime-abort-connection'.).
Here is my init-clj.el:
;; clojure-mode
(add-to-list 'load-path "~/.bin/clojure-mode")
;; swank-clojure
(add-to-list 'load-path "~/.bin/swank-clojure")
(setq swank-clojure-jar-path "/opt/clojure/clojure.jar"
swank-clojure-extra-classpaths (list
"~/.bin/swank-clojure/src/swank"
"/opt/clojure/clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar"))
(require 'swank-clojure)
;; slime
(eval-after-load "slime"
'(progn (slime-setup '(slime-repl))))
(add-to-list 'load-path "~/.bin/slime")
(require 'slime)
(eval-after-load 'slime '(setq slime-protocol-version 'ignore))
(slime-setup '(slime-repl))
(require 'clojure-mode)
(require 'clojure-test-mode)
Here is the error I get when I call it when ants.clj is open:
(progn (load "/home/kca/.bin/slime/swank-loader.lisp" :verbose t) (funcall (read- from-string "swank-loader:init")) (funcall (read-from-string "swank:start-server") "/tmp/slime.14113" :coding-system "iso-latin-1-unix"))
Clojure 1.2.0-master-SNAPSHOT
user=> java.lang.Exception: Unable to resolve symbol: progn in this context (NO_SOURCE_FILE:1)
Inferior Lisp
I made a script in .bin/ called clj-repl that holds the java command to start a repl. I then M-x set-variable inferior-lisp-program /home/wdkrnls/.bin/clj-repl. Emacs complains its the wrong type.
The best way to use Clojure is to start by installing Leiningen.
Then install Swank Clojure as a Leiningen plugin.
Next, I'd recommend stripping your current custom Clojure setup from .emacs, and installing ELPA, and then setting up the following initialization code in your .emacs file:
;; Find this line, added by ELPA:
(require 'package)
;; and add the following expression:
(add-to-list 'package-archives
'("marmalade" .
"http://marmalade-repo.org/packages/") t)
;; ... and the rest of the ELPA init code
(package-initialize)
Then, run package-list-packages and install clojure-mode and slime (and paredit for good measure), and anything else you might want.
This should have you all set up and ready to use SLIME in (Leiningen) Clojure projects. And despite the seemingly complex procedure here, you can create a single "uberjar" from your projects to deploy on other servers with absolutely no dependency hassle.
Try the method detailed here. It takes a couple of minutes to set everything up from scratch on a clean unix or mac box:
http://www.learningclojure.com/2010/08/clojure-emacs-swank-slime-maven-maven.html

What is wrong with my emacs/slime setup (compile-and-load/eval not working)?

I can run emacs and start slime (with M-x slime). At this point I get the REPL in the inferior-lisp buffer and can run lisp there. But when I open up lisp code in another buffer none of the slime-goodness works (C-x C-e, C-c C-k etc.) and I keep seeing this in the Messages buffer (with an increasing count-number):
slime-connection: Not connected.
Polling
"/var/folders/B9/B9B5J15dH+aNt5J5gkROEk+++TI/-Tmp-/slime.3202".. (Abort with `M-x
slime-abort-connection'.) [69 times]
Makes me think slime is not connecting to the correct lisp interpreter, but since I am very new to emacs and lisp I am stuck here. My setup is:
Mac OSX Snow Leopard
GNU Emacs 23.2
emacs-starter-kit
very few customizations: arnab.el and the files under arnab/
The following is what I did to get Common Lisp and Clojure to work in the same Emacs installation, along with the excellent emacs-starter-kit. This won't let you use both at the same time (you have to restart Emacs to switch from CL to Clojure or vice versa)
I believe that the version of SLIME in ELPA is old, but works for Clojure. Newer version of SLIME won't work for Clojure. Additionally, this version of SLIME seems to be stripped down (no swank-loader.el?) and won't work with Common Lisp.
These are the steps I did to get this to work, it's just what worked for me. All of the bits are under active development, so I think breakage in this area is pretty likely.
With a fresh Emacs (no configuration at all, so move anything .emacs somewhere else for the moment) install ELPA:
http://tromey.com/elpa/install.html
From within Emacs, install the packages "slime" and "slime-repl". (M-x package-list-packages then C-s slime then i to select and x to install)
Move the files in ~/.emacs.d/elpa/slime-20100404 and ~/.emacs.d/elpa/slime-repl-20100404 to a new directory like ~/hacking/lisp/elpa-slime.
Throw out the ELPA install: $ rm -rf .emacs.d.
Now clone the emacs-starter-kit and move it to .emacs.d. I only did this with a fresh copy from technomancy's Github, so try that first if you have problems.
Get the latest SLIME with CVS:
cvs -d :pserver:anonymous:anonymous#common-lisp.net:/project/slime/cvsroot co cvs-slime
I don't think OS X comes with CVS installed, so you'll need to install it from Macports, Homebrew or something.
I put cvs-slime in ~/hacking/lisp.
Hopefully it's obvious what the Emacs Lisp below does:
(defun slime-common-lisp ()
(interactive)
(setq inferior-lisp-program "/usr/local/bin/sbcl") ; your Common Lisp impl
(add-to-list 'load-path "~/hacking/lisp/cvs-slime/") ; your SLIME from CVS directory
(require 'slime)
(slime-setup '(slime-repl))
(slime))
(defun slime-clojure ()
(interactive)
(add-to-list 'load-path "~/hacking/lisp/elpa-slime")
(require 'slime)
(slime-setup '(slime-repl))
(slime-connect "localhost" 4005))
For Clojure you'd have to start the Clojure runtime and swank-clojure on port 4005, I think using Leiningen is the approved method:
Create a new project:
$ lein new project
$ cd project
In project.clj:
(defproject newclj "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]]
:dev-dependencies [[swank-clojure "1.2.1"]])
Then:
$ lein deps
$ lein swank
Edited to add:
If you find that Paredit in the SLIME REPL is broken while using this setup, check this out:
http://www.emacswiki.org/emacs/ParEdit#toc3
At least one other potential issue with this is that, AFAICT, if you open a Common Lisp source file and then start SLIME, you won't be able to send forms from the first buffer to the SLIME buffer. So open a SLIME buffer before opening any Common Lisp source files, and it should work. This doesn't seem to apply to Clojure.
References:
emacs setup for both clojure and common lisp with slime-fancy (slime-autodoc)
https://github.com/technomancy/swank-clojure/issues/closed#issue/31/comment/544166
If u have correctly install slime in your system then better use sbcl and add the following line in your ~/.emacs
(setq inferior-lisp-program "/usr/bin/sbcl")
/usr/bin/sbcl can be different according to your sbcl installation path.

How do I set up Aquamacs for Clojure development?

I've tried to migrate to Emacs several times for Clojure development, following a variety of blogposts, screencast and tutorials, but somewhere along the way something always went wrong - keybindings that didn't work, incompatible versions, etc, and I found myself scrambling back to Vim. But I know I want Paredit and SLIME.
So, I'm going to try again, this time backed by the powerful Stack Overflow™ community.
I hope that the answer to this question will remain up-to-date, and can serve as a reference for tentative converts like me.
What I'd like is:
The latest stable release of Clojure
Aquamacs (if it's good enough for Rich Hickey, it's good enough for me), a recent version
Clojure Mode
SLIME/SWANK
Paredit
Anything else that's indispensible?
Step-by-step instructions to install the above would be excellent - preferably in shell script format. I'd also like some hints on how to get started with the most common Clojure-related actions (including key-bindings), including links to documentation and cheatsheets.
These are the steps I took to set them up without using ELPA. Hope this helps.
Get SLIME using MacPorts
sudo port -v install slime
Get paredit
curl -O http://mumble.net/~campbell/emacs/paredit.el
Get clojure & clojure-contrib
Either using MacPorts
sudo port -v install clojure clojure-contrib
Or downloading directly
curl -O http://build.clojure.org/snapshots/org/clojure/clojure/1.1.0-master-SNAPSHOT/clojure-1.1.0-master-20091202.150145-1.jar
curl -O http://build.clojure.org/snapshots/org/clojure/clojure-contrib/1.1.0-master-SNAPSHOT/clojure-contrib-1.1.0-master-20091212.205045-1.jar
Get clojure-mode and swank-clojure (Emacs side)
git clone http://github.com/technomancy/clojure-mode.git
git clone http://github.com/technomancy/swank-clojure.git
Get swank-clojure (Clojure side)
Either downloading pre-built jar file
curl -O http://repo.technomancy.us/swank-clojure-1.1.0.jar
Or building from source (assuming lein is installed)
cd path/to/dir/swank-clojure
lein jar
Put clojure, clojure-contrib and swank-clojure .jar files in ~/.swank-clojure or ~/.clojure (the default places where swank-clojure.el searches for them).
Add to either ~/.emacs or ~/Library/Preferences/Aquamacs Emacs/customization.el (change paths to match your own settings)
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime/")
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime/contrib/")
;; Change these paths to match your settings
(add-to-list 'load-path "path/to/dir/clojure-mode/")
(add-to-list 'load-path "path/to/dir/swank-clojure/")
(add-to-list 'load-path "path/to/dir/paredit/")
;; Customize swank-clojure start-up to reflect possible classpath changes
;; M-x ielm `slime-lisp-implementations RET or see `swank-clojure.el' for more info
(defadvice slime-read-interactive-args (before add-clojure)
(require 'assoc)
(aput 'slime-lisp-implementations 'clojure
(list (swank-clojure-cmd) :init 'swank-clojure-init)))
(require 'slime)
(require 'paredit)
(require 'clojure-mode)
(require 'swank-clojure)
(eval-after-load "slime"
'(progn
;; "Extra" features (contrib)
(slime-setup
'(slime-repl slime-banner slime-highlight-edits slime-fuzzy))
(setq
;; Use UTF-8 coding
slime-net-coding-system 'utf-8-unix
;; Use fuzzy completion (M-Tab)
slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
;; Use parentheses editting mode paredit
(defun paredit-mode-enable () (paredit-mode 1))
(add-hook 'slime-mode-hook 'paredit-mode-enable)
(add-hook 'slime-repl-mode-hook 'paredit-mode-enable)))
;; By default inputs and results have the same color
;; Customize result color to differentiate them
;; Look for `defface' in `slime-repl.el' if you want to further customize
(custom-set-faces
'(slime-repl-result-face ((t (:foreground "LightGreen")))))
(eval-after-load "swank-clojure"
'(progn
;; Make REPL more friendly to Clojure (ELPA does not include this?)
;; The function is defined in swank-clojure.el but not used?!?
(add-hook 'slime-repl-mode-hook
'swank-clojure-slime-repl-modify-syntax t)
;; Add classpath for Incanter (just an example)
;; The preferred way to set classpath is to use swank-clojure-project
(add-to-list 'swank-clojure-classpath
"path/to/incanter/modules/incanter-app/target/*")))
Download and install Aquamacs.
Download and install ELPA (http://tromey.com/elpa/install.html)
Do M-x package-list-packages
Mark the lines called "clojure-mode" and "swank-clojure" with "I" then press "X".
Done.
Here's a blog post that mentions Aquamacs: Setting up Clojure, Incanter, Emacs, Slime, Swank, and Paredit
There seems to be a fairly easy way to set up Aquamacs 2.4 and SLIME for clojure:
Install Clojure
Install Aquamacs 2.4 from here "http://aquamacs.org/"
Install the Aquamacs SLIME package from here "http://aquamacs.org/download.shtml"
This will not work so...
Get the latest version of SLIME from here "http://common-lisp.net/project/slime/#downloading" - you want the CVS snapshot tar file
Unpack the SLIME tar file and copy it into
/Library/Application Support/Aquamacs Emacs/SLIME
Seems to work OK for me...
I know the OP wants to use Emacs for Clojure dev. I'm an emacs fan myself, but I found using Enclojure (http://www.enclojure.org/home) to be a great way to get started quickly with hacking Clojure.
Today I would head for https://github.com/tehcurtis/aquamacs-emacs-starter-kit/network
this is for ruby and wont work at first but anyway. git clone and copy things to Preferences.el according to readme. Fix the brokenness by edit the ~/Library/Preferences/Aquamacs Emacs/ and comment out almost everything in modes.el (I have only (setq-default indent-tabs-mode nil) left in the file)
The good part: you have installed elpa-package-manager with less hassle
now: use
M-x package-list-packages
go to
clojure-mode (press I)
slime (press I)
slime-repl (press I)
Press X to install
done.
Caveat: clojure-jack-in wont work so you have to
M-x slime-connect
and press enter twice and y to start.