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

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

Re: how to reverse a region of several words?


From: sunway
Subject: Re: how to reverse a region of several words?
Date: Mon, 28 Jul 2008 20:13:20 -0700 (PDT)
User-agent: G2/1.0

I want to transpose "one two" to " two one"

On Jul 28, 11:00 pm, tyler <address@hidden> wrote:
> sunway <address@hidden> writes:
> > e.g. the region contains words like "aaa bbb ccc ddd",I want to
> > reverse it to "ddd ccc bbb aaa"
>
> I think you probably want the words themselves to stay in the original
> order, i.e., one two => two one? If not, if you want to completely
> reverse the text, i.e., one two => owt eno, I use the following
> function:
>
> (defun reverse-string (beg1 end2)
>   "Reverse the order of characters in a region.
> From a program takes two point or marker arguments, BEG1 and END2."
>   (interactive "r")
>   (if (> beg1 end2)
>       (let (mid) (setq mid end2 end2 beg1 beg1 mid)))
>   (while (< beg1 (1- end2))
>         (let ((end1 (1+ beg1))
>                   (beg2 (1- end2)))
>           (transpose-regions beg1 end1 beg2 end2))
>         (incf beg1)
>         (decf end2)))
>
> Cheers,
>
> Tyler
> --
> Philosophy of science is about as useful to scientists as ornithology is to
> birds.                                 --Richard Feynman



reply via email to

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