From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.help Subject: Re: how to reverse a region of several words? Date: Tue, 29 Jul 2008 07:35:48 +0200 Message-ID: <878wvl6ymj.fsf@tux.homenetwork> References: <87e3b971-584c-42c5-8f4b-6a0eb32a206b@j1g2000prb.googlegroups.com> <6d2c67ca-89f5-4a72-81d1-be69ff37d4fe@x29g2000prd.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1217309956 22441 80.91.229.12 (29 Jul 2008 05:39:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Jul 2008 05:39:16 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: sunway Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 29 07:40:05 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 1KNhwK-0008J6-Q0 for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Jul 2008 07:40:05 +0200 Original-Received: from localhost ([127.0.0.1]:52865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNhvQ-0000ds-HY for geh-help-gnu-emacs@m.gmane.org; Tue, 29 Jul 2008 01:39:08 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KNhun-0000cT-DH for help-gnu-emacs@gnu.org; Tue, 29 Jul 2008 01:38:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KNhuk-0000aP-Jg for help-gnu-emacs@gnu.org; Tue, 29 Jul 2008 01:38:27 -0400 Original-Received: from [199.232.76.173] (port=39449 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNhuk-0000aC-Bo for help-gnu-emacs@gnu.org; Tue, 29 Jul 2008 01:38:26 -0400 Original-Received: from ug-out-1314.google.com ([66.249.92.174]:61757) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KNhuj-0004VD-Pp for help-gnu-emacs@gnu.org; Tue, 29 Jul 2008 01:38:26 -0400 Original-Received: by ug-out-1314.google.com with SMTP id l31so103171ugc.48 for ; Mon, 28 Jul 2008 22:38:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:cc:subject:references :date:in-reply-to:message-id:user-agent:mime-version:content-type :content-transfer-encoding; bh=b9c4YrI0UtgYdGRB39+RPHLJ4wyPTn6L4iJ0FlEGKkw=; b=LKZBbZa9tg43XB4y8Do7ogDf2oph8QkhFasyK9gWC6lXz4HowULtoJnyB2YLCnVWCY wYn3aYidiLzgnTpq2m4vfRXuoemL+1Ec+9i5XREu5TJtiic7Ya7TT+iehLbWN/68R+co 8ey2MsXYml2rzI1TanGmZ7chSY6jODMR+H6dc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type:content-transfer-encoding; b=S7WXVY3h207n5/8Q/3g9MfRrVsWwEoZWVIAt3ZSywXgt5LKFed92jtRK4L8h+CBEq2 5zInOU0jT93rBOG19I6xPZnBUm7XCKbcAywFR5Ig95UU7Edm1UjNqBDEmMjed3bhOpBK QhLqrah1qSis0nxgUjfHOKJ62mD/kZlrXZQHY= Original-Received: by 10.66.218.15 with SMTP id q15mr3014357ugg.77.1217309904767; Mon, 28 Jul 2008 22:38:24 -0700 (PDT) Original-Received: from tux.homenetwork ( [77.197.77.194]) by mx.google.com with ESMTPS id l4sm688516ugf.7.2008.07.28.22.38.23 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 28 Jul 2008 22:38:23 -0700 (PDT) In-Reply-To: <6d2c67ca-89f5-4a72-81d1-be69ff37d4fe@x29g2000prd.googlegroups.com> (sunway's message of "Mon, 28 Jul 2008 20:13:20 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) 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:56012 Archived-At: sunway 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'. |=20 | It is bound to M-t. |=20 | (transpose-words arg) |=20 | 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. |=20 | [back] `---- > On Jul 28, 11:00=C2=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) >> =C2=A0 "Reverse the order of characters in a region. >> From a program takes two point or marker arguments, BEG1 and END2." >> =C2=A0 (interactive "r") >> =C2=A0 (if (> beg1 end2) >> =C2=A0 =C2=A0 =C2=A0 (let (mid) (setq mid end2 end2 beg1 beg1 mid))) >> =C2=A0 (while (< beg1 (1- end2)) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((end1 (1+ beg1)) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (beg2 (1-= end2))) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (transpose-regions beg1 end1 beg2 end= 2)) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (incf beg1) >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (decf end2))) >> >> Cheers, >> >> Tyler >> -- >> Philosophy of science is about as useful to scientists as ornithology is= to >> birds. =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 --Richard Feynman > --=20 A + Thierry Volpiatto Location: Saint-Cyr-Sur-Mer - France