[slime-devel] cutting and pasting S-expressions from buffer to REPL
Stelian Ionescu
sionescu at cddr.org
Mon May 14 18:50:03 UTC 2012
On Mon, 2012-05-14 at 23:05 +0530, Faheem Mitha wrote:
> Hello everyone,
>
> I've recently started using SLIME with SBCl on Debian, where SLIME
> defaults to using SBCL, at least when it is installed. So far I am very
> impressed. I haven't been able to take off and fly yet, but I'm on the
> runway.:-)
>
> I'm particularly impressed by the underlining source which has compile
> errors, and doing a popup on mouseover feature. I don't know whose idea
> this was, but it is pretty damn cool. Does anyone know the history of this
> feature?
>
> So, I have a question about SLIME. When debugging, or indeed otherwise, I
> find it useful to copy and paste S-expressions from a buffer to the REPL.
> I've been using the mouse for this, which is decidedly sub-optimal. I hate
> using the mouse. I was thinking that it would be handy to have a command
> which would copy and paste S-expressions from a buffer to the REPL, while
> at the same time switching the buffer to the REPL. The S-expression would
> be chosen by having the cusor to the right of the closing expression. I'm
> not sure if this position has a name.
>
> I don't know if this command already exists. I could not find it in the
> manual. If it doesn't, could someone tell me what code would tell emacs to
> do this? My knowledge of Emacs programming is non-existent.
This is what I have in my .emacs(wasn't written by me and I don't
remember where I copied it from):
(defun slime-send-dwim (arg)
"Send the appropriate forms to CL to be evaluated."
(interactive "P")
(save-excursion
(cond
;;Region selected - evaluate region
((not (equal mark-active nil))
(copy-region-as-kill (mark) (point)))
;; At/before sexp - evaluate next sexp
((or (looking-at "(")
(save-excursion
(ignore-errors (forward-char 1))
(looking-at "(")))
(forward-list 1)
(let ((end (point))
(beg (save-excursion
(backward-list 1)
(point))))
(copy-region-as-kill beg end)))
;; At/after sexp - evaluate last sexp
((or (looking-at ")")
(save-excursion
(backward-char 1)
(looking-at ")")))
(if (looking-at ")")
(forward-char 1))
(let ((end (point))
(beg (save-excursion
(backward-list 1)
(point))))
(copy-region-as-kill beg end)))
;; Default - evaluate enclosing top-level sexp
(t (progn
(while (ignore-errors (progn
(backward-up-list)
t)))
(forward-list 1)
(let ((end (point))
(beg (save-excursion
(backward-list 1)
(point))))
(copy-region-as-kill beg end)))))
(set-buffer (slime-output-buffer))
(unless (eq (current-buffer) (window-buffer))
(pop-to-buffer (current-buffer) t))
(goto-char (point-max))
(yank)
(if arg (progn
(slime-repl-return)
(other-window 1)))))
(define-key slime-mode-map (kbd "C-c s") 'slime-send-dwim)
(define-key slime-mode-map (kbd "C-c M-s") '(lambda () (interactive) (slime-send-dwim 1)))
The advantage of using these as opposed to a simple eval-expression is
that a trace of it remains in the REPL buffer, useful if you're using
cl:dribble or something similar
--
Stelian Ionescu a.k.a. fe[nl]ix
Quidquid latine dictum sit, altum videtur.
http://common-lisp.net/project/iolib
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/slime-devel/attachments/20120514/2cb66da7/attachment.sig>
More information about the slime-devel
mailing list