From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.help Subject: Re: How modify numbers in a region by a multiplier? Date: Mon, 5 Jul 2010 13:46:24 +0200 Message-ID: References: <87pqz53g34.fsf@gmail.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: dough.gmane.org 1278330440 17318 80.91.229.12 (5 Jul 2010 11:47:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 5 Jul 2010 11:47:20 +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 Mon Jul 05 13:47:16 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 1OVk8o-0005vY-T5 for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Jul 2010 13:47:15 +0200 Original-Received: from localhost ([127.0.0.1]:54938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OVk8n-0002dF-Q2 for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Jul 2010 07:47:13 -0400 Original-Received: from [140.186.70.92] (port=37313 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OVk8M-0002d8-UE for help-gnu-emacs@gnu.org; Mon, 05 Jul 2010 07:46:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OVk8L-0001pT-T0 for help-gnu-emacs@gnu.org; Mon, 05 Jul 2010 07:46:46 -0400 Original-Received: from mail-bw0-f41.google.com ([209.85.214.41]:38889) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OVk8L-0001pH-Nn for help-gnu-emacs@gnu.org; Mon, 05 Jul 2010 07:46:45 -0400 Original-Received: by bwz9 with SMTP id 9so3428853bwz.0 for ; Mon, 05 Jul 2010 04:46:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=2WUZrS7f9KMUkQXozdbZasli4Lj3nI2r3tFcPxDQWH4=; b=irgopa2whbJcAJieBrrKTPyNfuwazi4wSr+zCbNo5NVtFAqpUqci7PtFuBue3v/xW+ TNguDduHJTwzP70DIrWAFxEnQTE+ArfvGdCOLsjuHyEwsH504dOnjJ4S/o5IqQsrsMsu +huOoebSsxqE3Vhffqeibk/kexYyu/P30Aryw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=QUJu+wkkbQ/swHs4rtYFpfX/ATOXpWYmFrrso19EysDvLLUtOJZfWGtcqViemqjko9 paWse2FcznM+XGGGHH+ZaqkNsJnRRYwc1i3ufLPupa5ZSc42xcvaCWzAAsrPyIXxORni 62TMrg/kFXkZLXViR2Z5aQjPyjP/afgFvFWgM= Original-Received: by 10.204.47.38 with SMTP id l38mr1884766bkf.154.1278330404236; Mon, 05 Jul 2010 04:46:44 -0700 (PDT) Original-Received: by 10.204.53.204 with HTTP; Mon, 5 Jul 2010 04:46:24 -0700 (PDT) In-Reply-To: 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:74072 Archived-At: On Mon, Jul 5, 2010 at 11:49, Seweryn Kokot wrote: > Can we say that the second > version is more elispy (more elegant and safer) than the first one? That is hard to say; different tastes, etc. I personally would write it like this: (defun my-multiply-numbers-in-region-or-buffer (&optional multiplier float-points) (interactive (list (read-number "Specify a multiplier: " 0.001) (read-number "Specify the number of significant figures: " 3))) (let ((region (use-region-p))) (save-restriction (widen) (narrow-to-region (if region (region-beginning) (point-min)) (if region (region-end) (point-max))) (goto-char (point-min)) (while (re-search-forward "\\([0-9.]+\\)" nil t) (replace-match (format (concat "%." (number-to-string float-points) "f" ) (* (string-to-number (match-string 1)) multiplier)))) (message "Numbers in %s modified by multiplier %s." (if region "region" "buffer") multiplier)))) but that does *not* mean that it is more elegant or lispy; just more to my tastes :-) > =C2=A0 =C2=A0 =C2=A0 =C2=A0(save-restriction you should use here (widen) > (narrow-to-region beg end) Juanma