unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* redirect eval output to separate buffer in lisp-interaction mode?
@ 2008-07-20 17:43 formido
  2008-07-20 21:04 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 3+ messages in thread
From: formido @ 2008-07-20 17:43 UTC (permalink / raw)
  To: help-gnu-emacs

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. 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.

Michael


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: redirect eval output to separate buffer in lisp-interaction mode?
  2008-07-20 17:43 redirect eval output to separate buffer in lisp-interaction mode? formido
@ 2008-07-20 21:04 ` Pascal J. Bourguignon
  2008-07-20 22:34   ` formido
  0 siblings, 1 reply; 3+ messages in thread
From: Pascal J. Bourguignon @ 2008-07-20 21:04 UTC (permalink / raw)
  To: help-gnu-emacs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: redirect eval output to separate buffer in lisp-interaction mode?
  2008-07-20 21:04 ` Pascal J. Bourguignon
@ 2008-07-20 22:34   ` formido
  0 siblings, 0 replies; 3+ messages in thread
From: formido @ 2008-07-20 22:34 UTC (permalink / raw)
  To: help-gnu-emacs

On Jul 20, 2:04 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> formido <form...@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.

;) Yes, I realize that. Although I don't have the innards of emacs
worked out yet, I know the lore of emacs and its place in the world.

> > 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.

No good. I want to write a little and then evaluate a little and
slowly shape the text in the current buffer into a working whole.
ELISP prompts are just clutter, in the same way that evaluation output
printed to the current buffer is clutter.

> 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?

Oh, this is good. I was using C-j. I'll probably use this from now on.
However, I'd still like to have more control.

> (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)))

[snip]

> Then bind this command to your prefered keys, C-j, C-RET, C-x C-e,
> whatever,
>

[snip]

Oh, and there it is, perfect! Thanks very much.

Michael

> __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.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-07-20 22:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-20 17:43 redirect eval output to separate buffer in lisp-interaction mode? formido
2008-07-20 21:04 ` Pascal J. Bourguignon
2008-07-20 22:34   ` formido

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).