how to reverse a region of several words?
  Home FAQ Contact Sign in
gnu.emacs.help only
 
Advanced search
POPULAR GROUPS

more...

gnu.emacs.help Profile…
 Up
how to reverse a region of several words?         


Author: sunway
Date: Jul 28, 2008 01:11

e.g. the region contains words like "aaa bbb ccc ddd",I want to
reverse it to "ddd ccc bbb aaa"
10 Comments
Re: how to reverse a region of several words?         


Author: Thierry Volpiatto
Date: Jul 28, 2008 02:03

sunway gmail.com> writes:
Show full article (0.65Kb)
no comments
Re: how to reverse a region of several words?         


Author: tyler
Date: Jul 28, 2008 08:00

sunway gmail.com> 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:
Show full article (0.91Kb)
no comments
Re: how to reverse a region of several words?         


Author: Pascal J. Bourguignon
Date: Jul 28, 2008 10:44

sunway gmail.com> writes:
> e.g. the region contains words like "aaa bbb ccc ddd",I want to
> reverse it to "ddd ccc bbb aaa"

Select it and M-x reverse-line RET

--
__Pascal Bourguignon__ http://www.informatimago.com/
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay
no comments
Re: how to reverse a region of several words?         


Author: tyler
Date: Jul 28, 2008 11:51

pjb@informatimago.com (Pascal J. Bourguignon) writes:
> sunway gmail.com> writes:
>
>> e.g. the region contains words like "aaa bbb ccc ddd",I want to
>> reverse it to "ddd ccc bbb aaa"
>
> Select it and M-x reverse-line RET

What version are you running? 23.0.60.1 doesn't have reverse-line...

Tyler

--
Tired of spyware? Try Firefox:

www.firefox.com
no comments
Re: how to reverse a region of several words?         


Author: sunway
Date: Jul 28, 2008 20:13

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

On Jul 28, 11:00 pm, tyler wrote:
> sunway gmail.com> writes:
>> e.g. the region contains words like "aaa bbb ccc ddd",I want to
>> reverse it to "ddd ccc...
Show full article (1.15Kb)
no comments
Re: how to reverse a region of several words?         


Author: Thierry Volpiatto
Date: Jul 28, 2008 22:35

sunway gmail.com> 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 wrote:
>> sunway gmail.com> writes:
>>> e.g. the region contains words like "aaa bbb ccc ddd",I want to
>>> reverse it to "ddd...
Show full article (1.84Kb)
no comments
Re: how to reverse a region of several words?         


Author: Pascal J. Bourguignon
Date: Jul 28, 2008 22:46

sunway gmail.com> writes:
> I want to transpose "one two" to " two one"

put the cursor between one and two and type:
M-x transpose-words RET or M-t

--
__Pascal Bourguignon__ http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
no comments
Re: how to reverse a region of several words?         


Author: sunway
Date: Jul 29, 2008 23:27

no, I want to transpose "one two three four" to "four three two one"

On Jul 29, 1:46 pm, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> sunway gmail.com> writes:
>> I want to transpose "one two" to " two one"
>
> put the cursor between one and two and type:
> M-x transpose-words RET or M-t
>
> --
> __Pascal Bourguignon__                    http://www.informatimago.com/
>
> NOTE: The most fundamental particles in this product are held
> together by a "gluing" force about which little is currently known
> and whose adhesive power can therefore not be permanently
> guaranteed.
no comments
Re: how to reverse a region of several words?         


Author: Pascal J. Bourguignon
Date: Jul 30, 2008 00:00

sunway gmail.com> writes:
>
> On Jul 29, 1:46 pm, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> sunway gmail.com> writes:
>>> I want to transpose "one two" to " two one"
>>
>> put the cursor between one and two and type:
>> M-x transpose-words RET or M-t
>
> no, I want to transpose "one two three four" to "four three two one"

(defun reverse-words (start end)
(interactive "r")
(let ((words (reverse (split-string (buffer-substring start end)))))
(delete-region start end)
(dolist (word words)
(insert word " "))
(backward-char 1)
(delete-char 1)))
Show full article (1.04Kb)
no comments
1 2