3

According to the Emacs manual, M-: evaluates an Emacs Lisp expression and prints the value in the echo area. How can I direct the value to the current buffer instead?

  • 1
    The contents of the echo area are generally in the *Messages* buffer. You can switch to that buffer using (view-echo-area-messages) which is bound to C-h e by default. From that buffer you can freely copy text. – glucas Apr 4 '17 at 14:47
  • I think the current answer is a better choice because it the question you've asked in the title and #1 & #2 in the text. My comment is really about #3, which seems like a separate question. – glucas Apr 4 '17 at 14:58
  • OK, then I think you need to split this up because you are asking three different things: How does one insert the M-: output in to the current buffer? Why does that not work for one specific case, magit-version? And totally unrelated, how does one get back to text that was shown in the echo area? – glucas Apr 4 '17 at 15:00
  • @glucas: The current answer doesn't answer questions #2 and #3. #3 was in the original post. I can't accept their answer. All three questions are answered by your comment, for all my purposes. – Evan Aad Apr 4 '17 at 15:00
  • To make this site generally useful, it helps to have focused questions -- that way other users with similar questions can find the answers they need. Right now the question you have asked is "How do I insert the output of M-: in to the current buffer", which has already been answered. If the question you really intended to ask was "How can I copy the message echoed by magit-version" then please change the question, because that answer would have nothing to do with M-: at all. – glucas Apr 4 '17 at 15:27
8

use C-u M-: insert the result into current buffer instead of printing it in the echo area.

(eval-expression EXP &optional INSERT-VALUE)

Evaluate EXP and print value in the echo area. When called interactively, read an Emacs Lisp expression and evaluate it. Value is also consed on to front of the variable ‘values’. If the resulting value is an integer, it will be printed in several additional formats (octal, hexadecimal, and character). Optional argument INSERT-VALUE non-nil (interactively, with prefix argument) means insert the result into the current buffer instead of printing it in the echo area.

  • Thanks for replying. I tried to follow your advice and evaluated C-u M-x magit-version RET while in the *sctach* buffer, but the output wrote to the echo area rather than *scratch*. – Evan Aad Apr 4 '17 at 9:04
  • C-u M-: (magit-version) <RET> – 南山竹 Apr 4 '17 at 9:09
  • C-u M-x (magit-version) RET prints [No match] to the minibuffer. – Evan Aad Apr 4 '17 at 9:12
  • 1
    The magit-version command returns as a result only the version number, so that is what you can insert in to the buffer. If you look at the source for magit-version you'll find that the additional information is displayed via the (message ....) function -- so if you want that text you would need to temporarily advise / override message. – glucas Apr 4 '17 at 14:45
  • 1
    What @glucas said. Or just pick up some of the code that prints that info in *Messages* (or similar) and use it to print the info wherever else you want. – Drew Apr 4 '17 at 14:47

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.