From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tyler Newsgroups: gmane.emacs.help Subject: Re: how to reverse a region of several words? Date: Mon, 28 Jul 2008 12:00:44 -0300 Message-ID: <87abg2834z.fsf@blackbart.sedgenet> References: <87e3b971-584c-42c5-8f4b-6a0eb32a206b@j1g2000prb.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217257405 28221 80.91.229.12 (28 Jul 2008 15:03:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 28 Jul 2008 15:03:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jul 28 17:04:15 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 1KNUFr-0003kf-SY for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Jul 2008 17:03:20 +0200 Original-Received: from localhost ([127.0.0.1]:42564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNUEx-0004ZK-NC for geh-help-gnu-emacs@m.gmane.org; Mon, 28 Jul 2008 11:02:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KNUDZ-0004JE-5n for help-gnu-emacs@gnu.org; Mon, 28 Jul 2008 11:00:57 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KNUDY-0004Is-DT for help-gnu-emacs@gnu.org; Mon, 28 Jul 2008 11:00:56 -0400 Original-Received: from [199.232.76.173] (port=38489 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNUDY-0004Io-8f for help-gnu-emacs@gnu.org; Mon, 28 Jul 2008 11:00:56 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:41724 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KNUDX-0001Ao-Tq for help-gnu-emacs@gnu.org; Mon, 28 Jul 2008 11:00:56 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KNUDR-0007TR-OM for help-gnu-emacs@gnu.org; Mon, 28 Jul 2008 15:00:49 +0000 Original-Received: from hlfxns0149w-142177090059.ns.aliant.net ([142.177.90.59]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Jul 2008 15:00:49 +0000 Original-Received: from tyler.smith by hlfxns0149w-142177090059.ns.aliant.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 Jul 2008 15:00:49 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 30 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: hlfxns0149w-142177090059.ns.aliant.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) Cancel-Lock: sha1:2jd5E01vA6WoOcxfmzZJiDPHVFA= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:55988 Archived-At: 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 => 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