3

In emacs --batch (also, emacs --script),

(message "My Message")

will print "My Message" to standard error (file descriptor 2) along with a trailing newline.

What if I don't want the newline? I see that theoretically,

(princ "My Message" standard-error)` 

would work, if standard-error were defined.

Confusingly, standard-output and standard-input are defined, however.

Is this even possible?

  • I found that (defvar standard-error 'external-debugging-output) makes the above behave nicely, thanks to @wasamasa – Joel M Ward Jan 18 '17 at 19:10
4

According to the manual, anything printing a message in batch mode will use stderr for this. The print/prin1/princ family will continue printing to stdout unless you pass the optional argument for picking a different char printing function, therefore the following will work:

(princ "My Message" 'external-debugging-output)

Apparently the Emacs developers consider stderr only for reporting errors and debug output ;)

  • How did you find that out? – Joel M Ward Jun 12 '16 at 15:47
  • I jumped to the sources of princ with find-function, then searched the sources for usage of stderr. Eventually I found that special char printing function... – wasamasa Jun 12 '16 at 18:38

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.