3

Consider this test function (tested in emacs -q):

  (defun foo (start end)
   "for testing purposes"
   (interactive "r")
   (when (region-active-p)
     (cons start end)))

Calling M-x foo gives no results printed in the minibuffer, even when a region is active. If I evaluate M-: (call-interactively #'foo) the cons is printed in the minibuffer.

I'd be happy to know why nothing is printed with M-x foo.

3

You're confusing the echoing of the return value by M-: with the action of M-x.

M-: expressly evaluates a sexp and prints the resulting value. M-x invokes a command.

Your command does not, itself, print or echo or otherwise display its return value.

If you want your command to echo the value, then use function message:

(when (region-active-p)
  (let ((val (cons start end)))
    (message "Result: %S" val)
    val))
2
  • This does not exactly answer my question. I thought in the evaluation loop (read (eval (print))) the evaluation stream was displayed in the mini-buffer. I had never observed it to be otherwise until now.
    – gigiair
    Sep 22 at 6:59
  • 2
    I think it does answer your question. What you thought is wrong "the evaluation stream [is] displayed in the mini-buffer". Display in the echo area is due to explicit calls to functions such as message.
    – Drew
    Sep 22 at 15:25

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.