[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: redirect eval output to separate buffer in lisp-interaction mode?
From: |
Pascal J. Bourguignon |
Subject: |
Re: redirect eval output to separate buffer in lisp-interaction mode? |
Date: |
Sun, 20 Jul 2008 23:04:32 +0200 |
User-agent: |
Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux) |
formido <formido@gmail.com> writes:
> How does one redirect evaluation output to a separate buffer in lisp-
> interaction mode?
> I'm just getting started with emacs, but it's quite
> similar to an AppleScript environment called Smile that I'm very
> familiar with.
It's the reverse, it's that AppleScript environment that is quite
similar to emacs.
> By default, you start in an interactive script shell
> there, too, and the first thing I do after a new install is change the
> prefs to redirect output to the "console". Hopefully I can achieve a
> similar effect here, cos it makes incrementally developing a script
> easier, I think.
Normally, emacs "scripts" don't have output. What they do is to
_edit_ some buffer.
You could use M-x ielm RET to try out emacs lisp expressions in a
separate REPL.
When you edit your emacs code, if you type C-x C-e after an expression
its output goes to the mini-buffer (and to the *Message* buffer).
Isn't it enough for you? If you type M-x eval-region RET or M-x
eval-buffer RET output goes to the *Message* buffer, isn't it enough?
(You can also type C-u C-x C-e to have the result be inserted at the point).
If you really want what you say you want, you can just do it:
(defvar *emacs-lisp-interaction-output-buffer*
(lambda () (current-buffer)))
(defun eval-print-last-sexp/output ()
"Evaluate sexp before point; print value into the buffer indicated
by *emacs-lisp-interaction-output-buffer* ; it may be either a buffer,
or a function returning a buffer.
If `eval-expression-debug-on-error' is non-nil, which is the default,
this command arranges for all errors to enter the debugger.
Note that printing the result is controlled by the variables
`eval-expression-print-length' and `eval-expression-print-level',
which see."
(interactive)
(let ((expr (preceding-sexp)))
(let ((standard-output
(etypecase *emacs-lisp-interaction-output-buffer*
(buffer *emacs-lisp-interaction-output-buffer*)
(function (funcall *emacs-lisp-interaction-output-buffer*)))))
(with-current-buffer standard-output
(terpri)
(if (null eval-expression-debug-on-error)
(eval-last-sexp-print-value (eval expr))
(let ((value
(let ((debug-on-error eval-last-sexp-fake-value))
(cons (eval-last-sexp-print-value (eval expr))
debug-on-error))))
(unless (eq (cdr value) eval-last-sexp-fake-value)
(setq debug-on-error (cdr value)))
(car value)))
(terpri)))))
Then bind this command to your prefered keys, C-j, C-RET, C-x C-e,
whatever,
(local-set-key (kbd "C-x C-e") 'eval-print-last-sexp/output)
and assign a buffer to *emacs-lisp-interaction-output-buffer*
(setf *emacs-lisp-interaction-output-buffer*
(get-buffer "output"))
--
__Pascal Bourguignon__ http://www.informatimago.com/
READ THIS BEFORE OPENING PACKAGE: According to certain suggested
versions of the Grand Unified Theory, the primary particles
constituting this product may decay to nothingness within the next
four hundred million years.