27-Sep-2014: I've made in-place updates to this post.
lein print and println: no longer broken
Using the Clojure REPL in Emacs via Cider, it mostly worked, but the "print" and "println" functions were broken at one point:
user> (print 1)
1NoSuchMethodError clojure.tools.nrepl.StdOutBuffer.length()I ...
Good old Google. A search for the above reveals a Leiningen issue which indicates the "stable" version 2.4.3 has a problem. When this post was first written, the fix was not yet available. Fortunately, there was a workaround: downgrade to version 2.4.2:
lein upgrade 2.4.2
This is no longer necessary: lein 2.5 is fixed:
user> (print 1)
1
nil
To get a productive Emacs-based Clojure environment, you need Emacs packages. I had some initial trouble with it not finding the Marmalade packages I asked for. I read some advice telling me to refresh the packages, but it wasn't exactly clear how to do it all in one go. To complicate matters, I found myself trying out the approaches of several bloggers, leading me to need to clear my config and start over more than once.
(I tried "prelude" Emacs package, but it was rather wonky and VERY slow to start up, so gave up and went with a bunch of stuff in John's config.)
So I created "refresh_pkgs.el" containing the following:
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
(package-refresh-contents)
When I want to clear everything and start over, I do this:
mv .emacs.d .emacs.d.sav
mv .emacs .emacs.sav
emacs -nw -q -l emacs_init/refresh_pkgs.el
When the welcome screen is displayed, exit Emacs with C-x C-c. A new ".emacs.d" directory now exists with a refreshed Marmalade. Now create the desired "init.el" (in the ".emacs.d" dir) and enter Emacs again. This invocation will take a lot longer because it downloads and builds the desired packages. Once again, when the welcome screen is finally displayed, exit Emacs. You should be good to go. (Note: I suspect that the "emacs -nw -q -l emacs_init/refresh_pkgs.el" command will be useful without starting over if there are new packages I want to try out.)
Here's the package loading section of my "init.el":
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
(defvar my-packages '(better-defaults
auto-complete
undo-tree
paredit
auto-indent-mode
projectile
clojure-mode
cider))
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
emacs: melpa v.s. marmalade
Ugh. For various reasons, I combined marmalade with melpa. The net result was a nightmare of things not working quite right. Apparently when both are enabled, the above package list will fetch incompatible versions of different packages. I tried going with melpa-only, and several packages were not available. I could have messed with it for longer, but I just wanted things to work again. So I started from scratch again with the above settings. With the latest lein, I'm back to everything working.
No comments:
Post a Comment