[Top][All Lists]

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

Re: how to reverse a region of several words?

From: Thierry Volpiatto
Subject: Re: how to reverse a region of several words?
Date: Tue, 29 Jul 2008 07:35:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

sunway <address@hidden> writes:

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

Put the point on two and hit M-t.

,----[ C-h k M-t ]
| M-t runs the command transpose-words, which is an interactive compiled
| Lisp function in `simple.el'.
| It is bound to M-t.
| (transpose-words arg)
| Interchange words around point, leaving point at end of them.
| With prefix arg arg, effect is to take word before or around point
| and drag it forward past arg other words (backward if arg negative).
| If arg is zero, the words around or after point and around or after mark
| are interchanged.
| [back]

> 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

A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France

reply via email to

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