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: Thierry Volpiatto
Subject: Re: how to reverse a region of several words?
Date: Wed, 30 Jul 2008 09:43:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

sunway <address@hidden> writes:

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

,----
| (defun reverse-sentence-region (&optional separator)
|   (interactive "P")
|   (let ((beg (point))
|         (sentence)
|         (separator))
|     (when current-prefix-arg
|       (setq separator (read-string "Separator: ")))
|     (kill-region beg (mark))
|     (setq sentence (nth 0 kill-ring))
|     (setq sentence (split-string sentence (if separator
|                                               separator)))
|     (setq sentence (reverse sentence))
|     (setq sentence (mapconcat #'(lambda (x) x)
|                               sentence
|                               (if separator
|                                   separator
|                                   " ")))
|     (insert sentence)))
`----
1) Mark region

2) Run M-x reverse-sentence-region
or C-u M-x reverse-sentence-region

if the words in region are separated with something else than " "



> On Jul 29, 1:46 pm, address@hidden (Pascal J. Bourguignon)
> wrote:
>> sunway <address@hidden> 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.
>

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




reply via email to

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