From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: sunway Newsgroups: gmane.emacs.help Subject: Re: how to reverse a region of several words? Date: Mon, 28 Jul 2008 20:13:20 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6d2c67ca-89f5-4a72-81d1-be69ff37d4fe@x29g2000prd.googlegroups.com> References: <87e3b971-584c-42c5-8f4b-6a0eb32a206b@j1g2000prb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1217302850 7918 80.91.229.12 (29 Jul 2008 03:40:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Jul 2008 03:40:50 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 29 05:41:39 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KNg5h-0001QP-7h for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Jul 2008 05:41:37 +0200 Original-Received: from localhost ([127.0.0.1]:55982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNg4m-0005iz-Rs for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Jul 2008 23:40:40 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!x29g2000prd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 34 Original-NNTP-Posting-Host: 123.127.134.57 Original-X-Trace: posting.google.com 1217301200 32702 127.0.0.1 (29 Jul 2008 03:13:20 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 29 Jul 2008 03:13:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x29g2000prd.googlegroups.com; posting-host=123.127.134.57; posting-account=ngAdqwoAAAA0uK1OfC15kE5UvDiCOvxy User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.51 (X11; Linux i686; U; zh-cn),gzip(gfe),gzip(gfe) X-HTTP-Via: 1.0 localhost.localdomain:8080 (squid/2.6.STABLE18) Original-Xref: news.stanford.edu gnu.emacs.help:160661 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:56011 Archived-At: I want to transpose "one two" to " two one" On Jul 28, 11:00=A0pm, tyler wrote: > sunway 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 =3D> two one? If not, if you want to completely > reverse the text, i.e., one two =3D> owt eno, I use the following > function: > > (defun reverse-string (beg1 end2) > =A0 "Reverse the order of characters in a region. > From a program takes two point or marker arguments, BEG1 and END2." > =A0 (interactive "r") > =A0 (if (> beg1 end2) > =A0 =A0 =A0 (let (mid) (setq mid end2 end2 beg1 beg1 mid))) > =A0 (while (< beg1 (1- end2)) > =A0 =A0 =A0 =A0 (let ((end1 (1+ beg1)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (beg2 (1- end2))) > =A0 =A0 =A0 =A0 =A0 (transpose-regions beg1 end1 beg2 end2)) > =A0 =A0 =A0 =A0 (incf beg1) > =A0 =A0 =A0 =A0 (decf end2))) > > Cheers, > > Tyler > -- > Philosophy of science is about as useful to scientists as ornithology is = to > birds. =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 --= Richard Feynman