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: tomas
Subject: Re: behaviour of shell-command-on-region
Date: Mon, 22 Feb 2010 10:16:37 +0100
User-agent: Mutt/1.5.15+20070412 (2007-04-11)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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).

Of course, you can replace (point) by whatever buffer position suits
you.

This won't work when the external command wants real input, though :-(

I'll try to file a bug.

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFLgkt1Bcgs9XrR2kYRAqcsAJ9Aqf6PLaRQU8rj/csS2cG++McnaQCdGdJp
cGMTjXgIeMVYA1eCznO7qwI=
=Qguz
-----END PGP SIGNATURE-----




reply via email to

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