2

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

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.

  • @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 Aug 11 '17 at 1:58
  • @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 Aug 11 '17 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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