Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I insert directly the text displayed in the echo area? (also wrongly called the minibuffer).

When I for example run (+ 2 2) in a buffer and execute it with C-x C-e it correctly displays the result '2' in the echo area. There is also a '2' in the Messages buffer. I'd like this '2' inserted below the line executed, in the same buffer, or something like that.

Is there a command to, for example, pipe the echo area into the buffer or copy the last line of the Messages buffer into the present working buffer?

share|improve this question
1  
C-u C-x C-e will insert the result into the buffer. Not what you ask, but what you'd like in 2nd paragraph. –  Juancho Feb 2 at 17:52
    
@Juancho: yes, that is what I'd like. –  Quora Feans Feb 2 at 17:59
add comment

2 Answers 2

up vote 2 down vote accepted

In lisp-interaction-mode which is the default mode for the *scratch* buffer you can use eval-print-last-sexp bound to C-j.

Edit:

In any buffer you can switch to lisp-interaction-mode with M-x: lisp-interaction-mode [RET]

Now C-j should be bound by default to eval-print-last-sexp unless the binding is shadowed by another mode. You can check the quick description of the current major-mode with C-h m.

If it is shadowed or simply not bound you can eval

(global-set-key (kbd "C-c p") 'eval-print-last-sexp)

with C-x C-e. That will bind the command to C-c p.

To make the change permanent write it in your .emacs file.

share|improve this answer
    
Isn't the default mode for *scratch* Fundamental? It is on my system. Or is that just a name for lisp-interaction-mode? Your eval-print-last-sexp works fine in Fundamental but C-j us not bound. –  terdon Feb 2 at 17:38
add comment

You need to use one of the EMACS insert commands. To accomplish what you illustrated in your simple example you would need to do the following.

(insert-string (number-to-string (+ 2 2)))
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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