[OS X Emacs] yank or insert command output
Jack Repenning
jrepenning at collab.net
Mon Feb 14 21:24:43 EST 2011
On 08/02/2011 4:37 ?.?., Marinos K wrote:
> There are several commands that output some text-string in the minibuffer
>
> how can I insert this text at the point the cursor is instead of the
> stdout ???
Some of them already know how to do this themselves. For example, shell-command (which you may know as M-!) has documentation that says:
> shell-command is an interactive compiled Lisp function in `simple.el'.
>
> It is bound to ⌘!, <menu-bar> <tools> <shell>.
>
> (shell-command COMMAND &optional OUTPUT-BUFFER ERROR-BUFFER)
>
> Execute string COMMAND in inferior shell; display output, if any.
> With prefix argument, insert the COMMAND's output at point.
>
> ...
>
> The optional second argument OUTPUT-BUFFER, if non-nil,
> says to put the output in some other buffer.
(You should read the rest of that before trying it; I've left out such important details as "... it first erases OUTPUT-BUFFER ..." Just "C-h f shell-command".)
Its friend shell-command-on-region (M-|) is even nicer:
> Execute string COMMAND in inferior shell with region as input.
> Normally display output (if any) in temp buffer `*Shell Command Output*';
> Prefix arg means replace the region with it. Return the exit code of
> COMMAND.
So, for example, you can select part of your file and do
> M-| sort
and a buffer will pop up with a sorted copy of those lines. If, on the other hand, you select and the
> ^U M-| sort
then the sorted list replaces the formerly unsorted list.
(All this assumes your system has a program named "sort," accessible in the default way, that reads its input, sorts it, and sprays it to its output -- i.e., that you're on some Unix variant, rather than Windows.)
More information about the MacOSX-Emacs
mailing list