all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: tyler <tyler.smith@mail.mcgill.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: how to reverse a region of several words?
Date: Mon, 28 Jul 2008 12:00:44 -0300	[thread overview]
Message-ID: <87abg2834z.fsf@blackbart.sedgenet> (raw)
In-Reply-To: 87e3b971-584c-42c5-8f4b-6a0eb32a206b@j1g2000prb.googlegroups.com

sunway <sunwayforever@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





  parent reply	other threads:[~2008-07-28 15:00 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 [this message]
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

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

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

  git send-email \
    --in-reply-to=87abg2834z.fsf@blackbart.sedgenet \
    --to=tyler.smith@mail.mcgill.ca \
    --cc=help-gnu-emacs@gnu.org \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.