5

Create a test.el file as below:

(print "hello world!")

Then run M-x eval-buffer. No output can be seen even in *Messages* buffer. where is the print output for this case?

2 Answers 2

3

Nowhere. See the docstring (C-h f eval-buffer):

(eval-buffer &optional BUFFER PRINTFLAG FILENAME UNIBYTE DO-ALLOW-PRINT)

Execute the accessible portion of current buffer as Lisp code. ...

PRINTFLAG controls printing of output by any output functions in the evaluated code, such as ‘print’, ‘princ’, and ‘prin1’: a value of nil means discard it; anything else is the stream to print to. See Info node ‘(elisp)Output Streams’ for details on streams.

...

DO-ALLOW-PRINT, if non-nil, specifies that output functions in the evaluated code should work normally even if PRINTFLAG is nil, in which case the output is displayed in the echo area.

2
  • @JeanPiere Thanks, but if I do it as ` (eval-buffer nil (get-buffer-create "test"))`, it works but 1) all function name printed automatically. 2) the print output is duplicated. Maybe I missed some configure!
    – lucky1928
    Commented Aug 11, 2017 at 1:58
  • 1
    @lucky1928 If you do C-x C-e (eval-last-sexp) with point after the (print "hello") you will see the text appears two times in the echo area. One is the result of evaluation, the other is the string printed by side effect. Try this with (+ 4 2) for example. What are you trying to achieve?
    – JeanPierre
    Commented Aug 11, 2017 at 8:50
1
(message "hello world!")

will print hello world! to the echo area. That's the same space that's used by the minibuffer: echo area for output, minibuffer for input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.