help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: behaviour of shell-command-on-region


From: Pascal J. Bourguignon
Subject: Re: behaviour of shell-command-on-region
Date: Mon, 22 Feb 2010 11:05:31 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (darwin)

tomas@tuxteam.de writes:

> On Sun, Feb 21, 2010 at 12:38:10PM -0500, Dan Davison wrote:
>> I'm having trouble understanding the output-buffer and replace arguments
>> to shell-command-on-region:
>> 
>> The argument list and docstring are reproduced below.
>> 
>> If I put point on the last parenthesis and do C-x C-e I was expecting
>> this to insert the date after point. However, it erases the current
>> buffer and inserts the date:
>> 
>> (shell-command-on-region (point-min) (point-max) "date" 'current-buffer)
>> 
>> It's seeming to me that the docstring and behaviour don't match. Where
>> am I going wrong?
>> 
>> Dan
>> 
>> emacs-version 23.1.1 ubuntu 9.10
>> 
>> 
>> The argument list for shell-command-on-region is:
>> 
>> (shell-command-on-region start end command &optional output-buffer
>> replace error-buffer display-error-buffer)
>> 
>> The docstring says:
>> 
>>     If the optional fourth argument output-buffer is non-nil,
>>     that says to put the output in some other buffer.
>>     If output-buffer is a buffer or buffer name, put the output there.
>>     IF OUTPUT-BUFFER IS NOT A BUFFER AND NOT NIL,
>>     INSERT OUTPUT IN THE CURRENT BUFFER.
>>     In either case, the output is inserted after point (leaving mark after 
>> it).
>>     
>>     If replace, the optional fifth argument, is non-nil, that means insert
>>     the output in place of text from start to end, putting point and mark
>>     around it.
>
> You are right -- this looks like a bug. When the argument is nil,
> the whole buffer gets replaced, regardless of the args START and END.
> But when the arg is t, the region gets respected, so this might be a
> workaround:
>
>     (shell-command-on-region (point) (point) "date" 'current-buffer t)
>
> (I'm somewhat surprised that the symbol 'current-buffer works there: I'd
> use (current-buffer) instead -- but this seems to work).

You're only surprized because you cannot read.

>>     If output-buffer is not a buffer and not nil,
>>     insert output in the current buffer.


-- 
__Pascal Bourguignon__


reply via email to

[Prev in Thread] Current Thread [Next in Thread]