Sometimes, I want to insert the result of an Emacs command (that has been echoed in the echo area) to another buffer or another running X program. So, I'd like to put it to the kill-ring. What would be a convenient way to do this?
For example: I could run a query with a shell command while in dired mode, say: !rpm -qf
(to find out which package owns the selected file in the directory listing), and then want to insert the result somewhere else.
Or, another example: if I needed the filename of the current buffer (as in Is there a user interface in Emacs allowing one to "grab" the buffer's filename conveniently?), and there was not yet any predefined command for this, I could at least do M-:(buffer-file-name)
and then use this general-purpose way to copy the shown result to the kill-ring in order to paste it later. (Of course, I could eval (kill-new (buffer-file-name))
, but this example here is to illustrate what kind of general-purpose way to do the grabbing of the echoed result I'm looking for.)
Best Answer
Type
C-u
before eitherM-:
orM-!
to get the result inserted instead of sent to the echo area.To get things directly into the kill ring, you need to dabble in Elisp. Something like this (untested):