Burton Samograd
Burton Samograd

Reputation: 3638

*scratch* buffer using SLIME

I realize that SLIME is the Superior Lisp Interaction Mode but I'm wondering if there is a "Lisp Interaction" buffer that works with Common Lisp like the *scratch* buffer works with Emacs Lisp. I.E. hitting C-j at the end of a form will insert the result of that form in the current buffer.

I ask because I find editing the output as needed is easier this way than with the repl.

Upvotes: 2

Views: 715

Answers (2)

Daimrod
Daimrod

Reputation: 5030

There is M-xslime-scratchRET though I don't know what does C-j by default because I use Paredit.

However C-uC-xC-e does what you want in both *scratch* and *slime-scratch*.

It is bound to C-x C-e.

(eval-last-sexp EVAL-LAST-SEXP-ARG-INTERNAL)

Evaluate sexp before point; print value in minibuffer.
Interactively, with prefix argument, print output into current buffer.
Truncates long output according to the value of the variables
`eval-expression-print-length' and `eval-expression-print-level'.

(and it's slime-eval-last-expression in the *slime-scratch* buffer)

Upvotes: 4

Burton Samograd
Burton Samograd

Reputation: 3638

Binding this function to C-j does the behaviour that I'm looking for:

(defun slime-eval-print-last-sexp ()
  (interactive)
  (newline)
  (insert (cadr (slime-eval `(swank:eval-and-grab-output ,(slime-last-expression)))))
  (newline))

Upvotes: 1

Related Questions