4 Replies - 1560 Views - Last Post: 29 December 2010 - 08:59 AM

#1 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Problem with Emacs/Slime/Clojure

Posted 29 December 2010 - 08:25 AM

Hey guys,

I have successfully installed Clojure on my Arch Linux system and even have clojure-mode success in emacs. However, when connecting to SLIME using
M-x slime



I get no REPL. Instead I get a *

In addition, any Clojure code I try to compile with C-c C-c fails.

Here is my .emacs file; what am I doing wrong?
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )
(put 'upcase-region 'disabled nil)

(setq inferior-lisp-program "/usr/bin/sbcl")
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/")
(require 'slime)
(slime-setup)

;; clojure-mode
(add-to-list 'load-path "~/opt/clojure/clojure-mode")
(require 'clojure-mode)

(setq swank-clojure-jar-home "~/opt/jars")
(setq swank-clojure-deps (list "~/opt/jars/swank-clojure.jar"  "~/opt/jars/clojure.jar" "~/opt/jars/clojure-contrib.jar"))
(add-to-list 'load-path "~/opt/clojure/swank-clojure")
(require 'swank-clojure)




Is This A Good Question/Topic? 0
  • +

Replies To: Problem with Emacs/Slime/Clojure

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with Emacs/Slime/Clojure

Posted 29 December 2010 - 08:43 AM

Nevermind, I had the hooks wrong. Here was the working solution:
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(inhibit-startup-screen t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 )
(put 'upcase-region 'disabled nil)

(add-to-list 'load-path "/home/stephen/opt/clojure/clojure-mode")
(require 'clojure-mode)
(add-to-list 'load-path "/home/stephen/opt/clojure/swank-clojure")
(require 'swank-clojure)
(add-hook 'clojure-mode-hook
          '(lambda ()
             (define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-sexp)
             (define-key clojure-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)))
(eval-after-load "slime"
  `(progn
     (require 'assoc)
     (setq swank-clojure-classpath
           (list "/home/stephen/opt/clojure/clojure/clojure.jar"
                 "/home/stephen/opt/clojure/clojure-contrib/clojure-contrib.jar"
                 "/home/stephen/opt/clojure/swank-clojure/src"))
     (aput 'slime-lisp-implementations 'clojure
           (list (swank-clojure-cmd) :init 'swank-clojure-init))))


Was This Post Helpful? 0
  • +
  • -

#3 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Problem with Emacs/Slime/Clojure

Posted 29 December 2010 - 08:48 AM

You went about that the totally wrong way. Get rid of all SLIME configuration that you put in your .emacs file. Also, get rid of the clojure-mode configuration as well. I'm guessing you read some ancient tutorial on a blog somewhere, didn't you? ;p

What you want to do is get ELPA. You can get it from here: http://tromey.com/elpa/

After you've installed that and removed all of your clojure-mode and slime configuration, open up your .emacs file again and add this:

(add-to-list 'package-archives
             '("technomancy" . "http://repo.technomancy.us/emacs/") t)



After that, restart Emacs again and do M-x package-install and select clojure-mode. Then do M-x package-install and select slime-repl. You'll probably see a shitload of warnings and such during either or both of these steps. Ignore them, they are normal.

After that, restart Emacs once more, and then you should be able to open a Clojure source file and have syntax highlighting. You're going to want to use cake or leiningen to create a new project with a dev-dependency on swank-clojure "1.2.1", and run cake swank or lein swank to start a swank server. Then, all you have to do in Emacs is M-x slime-connect

Note that, in case you don't know, M-x means "Alt+x". When in doubt, there is OFFICIAL information here: https://github.com/t...y/swank-clojure

In any case, if none of this works out and you get frustrated, leave it be. If you're getting really frustrated, it's a sure sign that you need to take a break before you start associating your Emacs problems with Clojure and end up with a bad experience in the end. Remember that there is some support in IntelliJ and Eclipse as well, so even if you don't get Emacs working or don't feel like doing so right now, you can always jump on over to them for a while. And, you don't need Emacs just to get an REPL of course, you can use the Clojure jar or preferably cljr, cake, or leiningen.

EDIT:

I see you've got it working, but what I said above still stands. You've set up your configuration as if Clojure is 'installed' in a single place. Clojure doesn't work like that. You'd be better off doing the above so that one of the build tools can handle the classpath. You don't really 'install' Clojure like this, but rather use something like cake or leiningen which copies the jars around to projects and can manage your REPL for you. You've set yourself up for classpath hell, which is why you got that exception. It can't 'see' your code because your code isn't on the classpath. Do what I said above.

This post has been edited by Raynes: 29 December 2010 - 08:53 AM

Was This Post Helpful? 1
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: Problem with Emacs/Slime/Clojure

Posted 29 December 2010 - 08:49 AM

EDIT: I'll work on ELPA. Ignore all of the folloowing.

Shoot. Another problem.

C-c C-c keeps throwing an exception:
No such namespace: test-project.core
  [Thrown class java.lang.Exception]

Restarts:
 0: [QUIT] Quit to the SLIME top level

Backtrace:
  0: swank.commands.basic$eval855$compile_string_for_emacs__856$fn__857.invoke(basic.clj:170)
      [No Locals]
  1: swank.commands.basic$eval855$compile_string_for_emacs__856.invoke(basic.clj:166)
  2: clojure.lang.Var.invoke(Var.java:417)
  3: user$eval1592.invoke(NO_SOURCE_FILE)
  4: clojure.lang.Compiler.eval(Compiler.java:6222)
  5: clojure.lang.Compiler.eval(Compiler.java:6189)
  6: clojure.core$eval.invoke(core.clj:2680)
  7: swank.core$eval_in_emacs_package.invoke(core.clj:92)
  8: swank.core$eval_for_emacs.invoke(core.clj:239)
  9: clojure.lang.Var.invoke(Var.java:409)
 10: clojure.lang.AFn.applyToHelper(AFn.java:169)
 11: clojure.lang.Var.applyTo(Var.java:518)
 12: clojure.core$apply.invoke(core.clj:600)
 13: swank.core$eval_from_control.invoke(core.clj:99)
 14: swank.core$spawn_worker_thread$fn__455$fn__456.invoke(core.clj:298)
 15: clojure.lang.AFn.applyToHelper(AFn.java:159)
 16: clojure.lang.AFn.applyTo(AFn.java:151)
 17: clojure.core$apply.invoke(core.clj:600)
 18: swank.core$spawn_worker_thread$fn__455.doInvoke(core.clj:294)
 19: clojure.lang.RestFn.invoke(RestFn.java:398)
 20: clojure.lang.AFn.run(AFn.java:24)
 21: java.lang.Thread.run(Thread.java:662)



with this file:
(ns test-project.core)
(defn hello [] "Hello World!")


This post has been edited by Dogstopper: 29 December 2010 - 08:52 AM

Was This Post Helpful? 0
  • +
  • -

#5 Raynes  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 611
  • View blog
  • Posts: 2,815
  • Joined: 05-January 09

Re: Problem with Emacs/Slime/Clojure

Posted 29 December 2010 - 08:59 AM

As a side note, check out the cake README as well: http://github.com/ninjudd/cake it'll help you out a lot when you get ELPA working.

Once you've got ELPA and cake (leiningen will work about the same way here), you're ready to create your project. Do 'cake new test-project' and then navigate to the test-project/ directory and edit project.clj to include [swank-clojure "1.2.1"] in your dev-dependencies. After that, 'cake swank' should start up a swank server with everything you need on the classpath. Then you connect to it as I demonstrated above, and you can start editing source files in src/test_project/core.clj. You can run the code in Emacs through the swank-server by running C-c-C-k.

If you get problems with this code:


(add-to-list 'package-archives
             '("technomancy" . "http://repo.technomancy.us/emacs/") t)



You might need to replace ~/.emacs.d/elpa/package.el with the newer package.el from the Emacs trunk: http://bit.ly/pkg-el

This post has been edited by Raynes: 29 December 2010 - 09:03 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1