Right now I write expressions in the *scratch*
buffer and test them by evaluating with C-x C-e. I would really appreciate having an interactive interpreter like SLIME or irb, in which I could test Emacs Lisp expressions.

- 6,993
- 7
- 46
- 74

- 9,196
- 2
- 25
- 20
6 Answers
It's easy to evaluate Lisp expressions in Inferior Emacs-Lisp Mode:
M-x ielm
You can read more about this feature in the Emacs manual section on "Lisp Interaction"

- 33,090
- 15
- 73
- 105
Eshell is another option for an interactive Elisp interpreter.
M-x eshell
Not only is it a command shell like bash (or cmd.exe if on Windows) but you can also interactively write and execute Elisp code.
~ $ ls
foo.txt
bar.txt
~ $ (+ 1 1)
2

- 187,153
- 97
- 222
- 204
-
2ok, that's just... fascinating... the mixing ability... I'll definitely have to play more with this. Even though it's an indirect answer to the question, I'm glad this answer is here! `$ echo (buffer-name) | sed -e 's/\*/X/g'` gives `XeshellX`, etc. – lindes Apr 04 '12 at 21:06
Your best bet is the *scratch*
buffer. You can make it more like a REPL by first turning on the debugger:
M-x set-variable debug-on-error t
Then use C-j
instead of C-x C-e
, which will insert the result of evaluating the expression into the buffer on the line after the expression. Instead of things like command history, * * *
and so forth, you just move around the *scratch*
buffer and edit.
If you want things like * * *
to work, more like a usual REPL, try ielm
.
M-x ielm

- 36,964
- 10
- 32
- 35
To run just one elisp expression you can use M-: shortcut and enter expression in mini-buffer. For other cases you can use scratch buffer

- 80,552
- 8
- 87
- 132
In the *scratch*
buffer, just type C-j to evaluate the expression before point.

- 61,471
- 9
- 126
- 175
Well, if you're really interested in a literal REPL for emacs it is possible to write one using the -batch mode of emacs:
(require 'cl)
(defun read-expression ()
(condition-case
err
(read-string "> ")
(error
(message "Error reading '%s'" form)
(message (format "%s" err)))))
(defun read-expression-from-string (str)
(condition-case
err
(read-from-string str)
(error
(message "Error parsing '%s'" str)
(message (format "%s" err))
nil)))
(defun repl ()
(loop for expr = (read-string "> ") then (read-expression)
do
(let ((form (car (read-expression-from-string expr))))
(condition-case
err
(message " => %s" (eval form))
(error
(message "Error evaluating '%s'" form)
(message (format "%s" err)))))))
(repl)
You can call this from the command line, or, as you seem to want, from within an emacs buffer running a shell:
kburton@hypothesis:~/projects/elisp$ emacs -batch -l test.el
Loading 00debian-vars...
> (defvar x '(lambda (y) (* y 100)))
=> x
> (funcall x 0.25)
=> 25.0
>
kburton@hypothesis:~/projects/elisp$

- 26,788
- 9
- 50
- 60
-
This looks more complicated than it should be - running a shell, which runs another emacs in batch mode, which runs the REPL, all inside the main emacs runtime. Anyway, it solves my problem, so thank you for help! – Michał Kwiatkowski Sep 28 '08 at 04:57
-
This REPL implementation doesn't handle multi-line inputs. If you don't end an expression in a single line it gives: Error parsing '(whatever' (end-of-file repl.el) Is there an easy way to fix that? – Michał Kwiatkowski Sep 28 '08 at 05:14