|
|
I want to transpose "one two" to " two one"
On Jul 28, 11:00 pm, tyler <tyler.sm...@xxxxxxxxxxxxxx> wrote:
> sunway <sunwayfore...@xxxxxxxxx> 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
|
|