2

I am a beginner in clojure & emacs. I am following tutorial for clojure & emacs on clojure-doc.org . After I created my test project with lein, started nrepl in emacs and edited core_test.clj I tried to compile.

Then I got this:

Loading /home/jakov/dev/PROJECTS/clojure/test1/test/test1/core_test.clj...
FileNotFoundException Could not locate test1/core__init.class or test1/core.clj on       
classpath:   clojure.lang.RT.load (RT.java:432)

My project was created with leiningen 2, by lein new test1. I'm using emacs24

What may be the issue here?

EDIT: Here is the file structure of my project:

.
./doc
./doc/intro.md
./.gitignore
./README.md
./project.clj
./src
./src/test1
./src/test1/core.clj
./test
./test/test1
./test/test1/core_test.clj

EDIT:

Here are my files:

core_test.clj

(ns test1.core-test
  (:use clojure.test
        test1.core))

(deftest pairs-of-values
   (let [args ["--server" "localhost"
               "--port" "8080"
               "--environment" "production"]]
      (is (= {:server "localhost"
              :port "8080"
              :environment "production"}
             (parse-args args)))))

core.clj

(ns test1.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

This should give me another error, as I understood it, it should complain about parse args, as I understood. However, the same error happens when I add this to core.clj:

(defn parse-args [args]
  {})
8
  • Did you change the namespace line at the top of the files from what leiningen put on there? Commented Mar 19, 2013 at 23:13
  • No. I tried this multiple times by creating different projects. I followed steps on clojure-doc.org clojure-doc.org/articles/tutorials/emacs.html Commented Mar 19, 2013 at 23:16
  • I even got this error when just trying to compile base leiningen new project, without any changes at all. Commented Mar 19, 2013 at 23:46
  • 1
    Does it work just using lein from the command line? If you do lein run or lein test does it work or do you get these errors? Need to know if this is a general problem or specific to nrepl in emacs. Commented Mar 20, 2013 at 1:37
  • 1
    And just to clarify...are you using inferior lisp, swank + slime or nrepl? Commented Mar 20, 2013 at 3:32

2 Answers 2

2

This was the problem:

emacs seems to need to know of the path of the project prior to starting the nrepl with nrepl-jack-in. If you, however, start nrepl with just nrepl and connect it to the port of repl process started in separate terminal window, then emacs will know ab out path etc, from the repl process it connected to.

So, in order things to work with nrepl-jack-in, what you need is to first open a project file, like core.clj or core_test.clj and then start nrepl-jack-in.

Nrepl page on github adds this: Alternative you can use C-u M-x nrepl-jack-in to specify the name of a lein project, without having to visit any file in it.

Sign up to request clarification or add additional context in comments.

4 Comments

nrepl-jack-in is not very attractive to me, I alwas prefer starting the repl in advance. BTW you don't need to enter the port every time, you can configure a default port in ~/.lein/profiles.clj: {:user {:repl-options {:port 4001} ...}}
There are also issues with output. If you don't have the repl started in a regular terminal window, there will be no place you can monitor the output to System.out/err, for example console logging, e.printStackTrace() etc. In the long run you settle for the terminal window.
But doesnt it all show in the Message buffer? Or in the very nrepl buffer?
I haven't got enough experience with jack-in, but I wouldn't expect it to show up in Messages since this is raw Java output. The nrepl buffer will show writes to *out* (such as (println ...)), which is a level above the raw output. Another thing is, you really don't want massive logging output in an Emacs buffer due to performance issues.
1

Let me give you, for reference, what has worked for me:

$ lein new test1
Generating a project called test1 based on the 'default' template.
To see other templates (app, lein plugin, etc), try `lein help new`.
$ cd test1
$ lein repl
nREPL server started on port 4001
REPL-y 0.1.9
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
          (user/sourcery function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Examples from clojuredocs.org: [clojuredocs or cdoc]
          (user/clojuredocs name-here)
          (user/clojuredocs "ns-here" "name-here")
user=> 

In Emacs:

  • M-x nrepl<RET>
  • open file test/test1/core_test.clj
  • C-c C-k

The *Messages* buffer says:

Loading /Users/marko/dev/clj/test1/src/test1/core.clj...
#'test1.core/foo

Do you perform the exact same steps and get the undesirable outcome?

3 Comments

Your steps gave me this: Loading /home/jakov/dev/PROJECTS/clojure/test1/test/test1/core_test.clj... #'test1.core-test/a-test However, I had to connect emacs nrepl to the exact port of repl running in terminal, as per your example. Does that mean it is necessary to have separate terminal repl running? The tutorial at given page uses nrepl-jack-in without outer process.. I would like to get that working.
Can it have to do with the fact that when I start emacs, and then M-x nrepl-jack-in, I didnt tell emacs nothing about path of my project (I opened project files only afterwards)?
Yeah, that seems to be the issue. I need to open a project file first, so the nrepl knows about the path & environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.