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: Tue, 29 Jul 2008 07:35:48 +0200	[thread overview]
Message-ID: <878wvl6ymj.fsf@tux.homenetwork> (raw)
In-Reply-To: <6d2c67ca-89f5-4a72-81d1-be69ff37d4fe@x29g2000prd.googlegroups.com> (sunway's message of "Mon, 28 Jul 2008 20:13:20 -0700 (PDT)")

sunway <sunwayforever@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 <tyler.sm...@mail.mcgill.ca> wrote:
>> sunway <sunwayfore...@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:
>>
>> (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	other threads:[~2008-07-29  5:35 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 [this message]
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

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=878wvl6ymj.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).