unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: sunway <sunwayforever@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: how to reverse a region of several words?
Date: Wed, 30 Jul 2008 09:43:56 +0200	[thread overview]
Message-ID: <87od4f95qb.fsf@tux.homenetwork> (raw)
In-Reply-To: <d82d5efc-da8e-468d-9810-5d5c52795b42@v13g2000pro.googlegroups.com> (sunway's message of "Tue, 29 Jul 2008 23:27:14 -0700 (PDT)")

sunway <sunwayforever@gmail.com> 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, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> sunway <sunwayfore...@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.
>

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




      parent reply	other threads:[~2008-07-30  7:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-28  8:11 how to reverse a region of several words? sunway
2008-07-28  9:03 ` Thierry Volpiatto
2008-07-28 15:00 ` tyler
2008-07-28 17:44 ` Pascal J. Bourguignon
2008-07-28 18:51   ` tyler
     [not found] ` <mailman.15498.1217257259.18990.help-gnu-emacs@gnu.org>
2008-07-29  3:13   ` sunway
2008-07-29  5:35     ` Thierry Volpiatto
2008-07-29  5:46     ` Pascal J. Bourguignon
2008-07-30  6:27       ` sunway
2008-07-30  7:00         ` Pascal J. Bourguignon
2008-07-30  7:43         ` Thierry Volpiatto [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87od4f95qb.fsf@tux.homenetwork \
    --to=thierry.volpiatto@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=sunwayforever@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).