0

I would like to learn some Clojure, and I'm trying to run REPL from Emacs, but I cannot get it to work.

I have created a basic project with lein. I open the generated file core.clj in Emacs, and when I try to run the REPL from it (by running the cider-jack-in), I just get the message:

Symbol's function definition is void: nil

I have toggled the debug-on-error, and the backtrace (several last lines) is:

 Debugger entered--Lisp error: (void-function nil)
   nil(#<buffer core.clj>)
   #[257 "  !\203\207\300\207" [exclude predicate] 3 "\n\n(fn ELT)"](#<buffer core.clj>)
   seq-map(#[257 "  !\203\207\300\207" [exclude predicate] 3 "\n\n(fn ELT)"] (#<buffer core.clj> #<buffer  *Minibuf-1*> #<buffer *Warnings*> #<buffer *GNU Emacs*> #<buffer *scratch*> #<buffer  *Minibuf-0*> #<buffer *Messages*> #<buffer  *code-conversion-work*> #<buffer  *Echo Area 0*> #<buffer  *Echo Area 1*>))
   seq-filter(#[257 "r\211q\210\300\301!)\207" [derived-mode-p cider-repl-mode] 3 "\n\n(fn BUFFER)"] (#<buffer core.clj> #<buffer  *Minibuf-1*> #<buffer *Warnings*> #<buffer *GNU Emacs*> #<buffer *scratch*> #<buffer  *Minibuf-0*> #<buffer *Messages*> #<buffer  *code-conversion-work*> #<buffer  *Echo Area 0*> #<buffer  *Echo Area 1*>))
   cider-repl-buffers()
   cider-find-reusable-repl-buffer(nil "~/Development/languages/clojure/playground/test1/")
   cider-jack-in(nil)

When I run lein run in the terminal, the code runs properly.
Also, when I run lein repl in the terminal, the REPL runs properly with the following info:

nREPL server started on port 62741 on host 127.0.0.1 - nrepl://127.0.0.1:62741
REPL-y 0.3.7, nREPL 0.2.12
Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_45-b14

Lein has Cider version 0.14.0, while Emacs has downloaded version 0.15.0.

Could anyone help me figure out which part of the setup I'm missing, or what I'm doing wrong?

Thanks for the help!

EDIT: Bellow is the contents of Emacs init file, with comments removed:

(require 'package)
(add-to-list 'package-archives
           '("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives
           '("tromey" . "http://tromey.com/elpa/") t)
(add-to-list 'package-archives
           '("melpa" . "http://melpa.milkbox.net/packages/") t)

(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(defvar ido-cur-item nil)
(defvar ido-default-item nil)
(defvar ido-cur-list nil)
(defvar predicate nil)
(defvar inherit-input-method nil)

(defvar my-packages
  '(paredit
    clojure-mode
    clojure-mode-extra-font-locking
    cider
    ido-ubiquitous
    smex
    projectile
    rainbow-delimiters
    tagedit
    magit))

(if (eq system-type 'darwin)
    (add-to-list 'my-packages 'exec-path-from-shell))

(dolist (p my-packages)
  (when (not (package-installed-p p))
    (package-install p)))

(add-to-list 'load-path "~/.emacs.d/vendor")
(add-to-list 'load-path "~/.emacs.d/customizations")

(load "shell-integration.el")
(load "navigation.el")
(load "ui.el")
(load "editing.el")
(load "misc.el")
(load "elisp-editing.el")
(load "setup-clojure.el")
(load "setup-js.el")
Stanislav
  • 110
  • 10
  • Did you open a file in your new project when you called `cider-jack-in`? Which version of Emacs are you on? – Stefan Kamphausen Jan 06 '17 at 17:56
  • Yes, I opened the file from the project (`core.clj`) and then called `cider-jack-in`. I'm using Emacs version 24.5. – Stanislav Jan 06 '17 at 18:28
  • How are you installing cider and clojure-mode i.e. by hand or from melpa? What do you have in your emacs init file? – Tim X Jan 07 '17 at 03:13
  • I have edited the question to add Emacs init file. I picked up the configuration from [Brave Clojure](https://github.com/flyingmachine/emacs-for-clojure/archive/book1.zip) and updated packages from melpa, within Emacs. – Stanislav Jan 07 '17 at 07:06
  • Did you check to see if a cider-repl buffer was created? Cider creates this buffer in the background, so you need to open it yourself. Or did you try to evaluate any lines of code in core.clj using the keybinding `C-x C-e` or `C-M-x` ? If those bindings give return an inline value, then the repl is running – practicalli-john Jan 07 '17 at 14:40
  • Ensure you are using the latest version of Leiningen.org, the build tool. As of today that is version 2.7.1. Also suggest you run Java 1.8. Finally, create a new project with lein new project-name and try opening a repl with the project.clj or core.clj file open (unedited) – practicalli-john Jan 07 '17 at 14:43

3 Answers3

3

here's my lein debugging checklist:

  • remove any meniton of cider-nrepl from ~/.lein/profiles.clj
  • run lein repl from a terminal, then cider-connect to localhost from emacs
  • run lein upgrade
  • upgrade to the latest version of the cider emacs package
  • ask in the cider channel on clojure slack before submitting bug reports.

It used to be required to add cider's nrepl middleware to your lein profile to get it included on the classpath when lein start up. Now cider does this automatically and chooses the matching version on it's own. Many people are following instructions from when this was a manual process and run into problems like this, so check that first.

Arthur Ulfeldt
  • 90,827
  • 27
  • 201
  • 284
  • Here is what I tried to do, based on your comments: 1. I removed the `profiles.clj` completely, since only the `cider-nrepl` plugin was referenced there. 2. running `lein repl` and running `cider-connect` produces the same result; 3. I ran `cider-connections-browser` -> no connections are visible 4. I installed leiningen with homebrew - latest supported version is 2.6.1, and I see that the latest version is 2.7.1. Could this cause an issue? 5. All packages are up to date in Emacs. Indeed, I followed instructions where most if it was manual process. :) – Stanislav Jan 07 '17 at 06:46
  • I removed homebrew installed version of leiningen, and installed the latest, 2.7.1, version manually, but I still have the same issue. – Stanislav Jan 07 '17 at 07:36
  • Which port should I choose for localhost? – Pedro Delfino Jun 14 '22 at 16:30
0

Remove your ~/.emacs.d directory and install spacemacs instead

git clone https://github.com/syl20bnr/spacemacs ~/.emacs.d

Once you run Emacs with the new spacemacs ~/.emacs.d directory, you can simply open up a Clojure file and spacemacs will load in the Clojure layer for you.

More details can be found at spacemacs.org and in this tutorial on clojure development with spacemacs https://practicalli.github.io/spacemacs/

practicalli-john
  • 1,836
  • 1
  • 12
  • 8
0

So the error appears to be in cider-client.el at line 102 https://github.com/clojure-emacs/cider/blob/master/cider-client.el#L99. I've got the whole defun posted below:

(defun cider-repl-buffers ()
  "Return the list of REPL buffers."
  (seq-filter
   (lambda (buffer)
     (with-current-buffer buffer (derived-mode-p 'cider-repl-mode)))
   (buffer-list)))

Can you visit this file in your CIDER copy and ensure that this definition looks like this. This code is just looking for repl buffers and is filtering the buffers that emacs knows about.

dpsutton
  • 101
  • 5