From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Qiang Guo Newsgroups: gmane.emacs.help Subject: Re: How modify numbers in a region by a multiplier? Date: Thu, 01 Jul 2010 10:54:31 -0600 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII X-Trace: dough.gmane.org 1278003324 21197 80.91.229.12 (1 Jul 2010 16:55:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 1 Jul 2010 16:55:24 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Seweryn Kokot Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jul 01 18:55:21 2010 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.69) (envelope-from ) id 1OUN2n-00052J-Ip for geh-help-gnu-emacs@m.gmane.org; Thu, 01 Jul 2010 18:55:21 +0200 Original-Received: from localhost ([127.0.0.1]:36755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUN2m-0000Rg-TP for geh-help-gnu-emacs@m.gmane.org; Thu, 01 Jul 2010 12:55:20 -0400 Original-Received: from [140.186.70.92] (port=45897 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUN2H-0000Ra-RZ for help-gnu-emacs@gnu.org; Thu, 01 Jul 2010 12:54:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OUN2D-0006Mg-20 for help-gnu-emacs@gnu.org; Thu, 01 Jul 2010 12:54:49 -0400 Original-Received: from mail-pw0-f41.google.com ([209.85.160.41]:64233) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OUN2C-0006MH-Ts for help-gnu-emacs@gnu.org; Thu, 01 Jul 2010 12:54:45 -0400 Original-Received: by pwi9 with SMTP id 9so1960402pwi.0 for ; Thu, 01 Jul 2010 09:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:message-id:from:to:cc :subject:in-reply-to:references:user-agent:mime-version:content-type; bh=u6LhF/4jd2rYRP7/5IXxKll8JX/BZ6Ikh7cSSbVQRJQ=; b=hSMe6LuFNgUN9f17vbsmwwU77zpQRHy1Ej4l3FXx9dmslyrCDzIsdmMfF1MS1xvhJ3 Apu9VWNmQrMS8f08pNNXOfSX7ICO9VuuEHGD/Uf0NbU6HZdlg5q5hsm9+5V0jgwPy11D gLue/Za9ThjUDiupZe4xEggGXH0m3IYHbTDTo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:message-id:from:to:cc:subject:in-reply-to:references :user-agent:mime-version:content-type; b=NJ664czxJK3U/rKuIcal15oyTtsATgeiKsbvr/olOAjasYb2ADeBftvd1Qt12aNYZN LjhgrnX3CZow53Qx08sxH5RoHBOe+reQc7vduC9daha2HozOUox0Jl2kr1JL0Vu23ioa 4DL1zR11Q8g0C5kqL1Mh545WElTBYFXJGMd8c= Original-Received: by 10.114.162.24 with SMTP id k24mr12619504wae.158.1278003279617; Thu, 01 Jul 2010 09:54:39 -0700 (PDT) Original-Received: from Qiang-Guos-MacBook-Pro.local.gmail.com (d75-152-224-210.abhsia.telus.net [75.152.224.210]) by mx.google.com with ESMTPS id p10sm29452787waj.6.2010.07.01.09.54.37 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 01 Jul 2010 09:54:38 -0700 (PDT) In-Reply-To: User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.7 Emacs/23.2 (x86_64-apple-darwin10.4.0) MULE/6.0 (HANACHIRUSATO) X-detected-operating-system: by eggs.gnu.org: GNU/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:74033 Archived-At: At Thu, 1 Jul 2010 13:55:11 +0000 (UTC), Seweryn Kokot wrote: > > Hi, > > I would like to modify numbers in a region/buffer by a given multiplier. > > Imagine that I have some numbers > > 33.444 3333 4433.4443 3344 .34234 > > and I want them multiplied for example by 0.1 > > to receive > > 3.3444 333.3 443.34443 334.4 .034234 > > I tried with this function I wrote, but it doesn't work properly. > Any idea why? > > (defun my-multiply-numbers-in-region-or-buffer (multiplier) > (interactive "nGive multiplier: ") > (let (beg end object) > (if (use-region-p) > (progn > (setq object "region") > (setq beg (region-beginning)) > (setq end (region-end))) > (setq object "buffer") > (setq beg (point-min)) > (setq end (point-max))) > (goto-char beg) > (while (re-search-forward "\\([0-9]*\\.?[0-9]*\\)" end t) > (replace-match (format "%.3f" (* (string-to-number (match-string 1)) > multiplier)))) > (message "Numbers in %s modified by multiplier %s." object > multiplier))) > > Hi, The problem is the re-search-forward. It should be dynamically changed according to the replace events, since the (point) would exceed the variable end after replacement. Qiang