[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How modify numbers in a region by a multiplier?
From: |
Juanma Barranquero |
Subject: |
Re: How modify numbers in a region by a multiplier? |
Date: |
Mon, 5 Jul 2010 13:46:24 +0200 |
On Mon, Jul 5, 2010 at 11:49, Seweryn Kokot <sewkokot@gmail.com> 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 :-)
> (save-restriction
you should use here
(widen)
> (narrow-to-region beg end)
Juanma
- Re: How modify numbers in a region by a multiplier?, (continued)
- Re: How modify numbers in a region by a multiplier?, Juanma Barranquero, 2010/07/01
- Re: How modify numbers in a region by a multiplier?, Seweryn Kokot, 2010/07/01
- Re: How modify numbers in a region by a multiplier?, Juanma Barranquero, 2010/07/01
- Re: How modify numbers in a region by a multiplier?, Seweryn Kokot, 2010/07/02
- Re: How modify numbers in a region by a multiplier?, Juanma Barranquero, 2010/07/02
- Re: How modify numbers in a region by a multiplier?, Seweryn Kokot, 2010/07/02
- Re: How modify numbers in a region by a multiplier?, Juanma Barranquero, 2010/07/02
- Re: How modify numbers in a region by a multiplier?, Štěpán Němec, 2010/07/02
- Re: How modify numbers in a region by a multiplier?, Juanma Barranquero, 2010/07/02
- Re: How modify numbers in a region by a multiplier?, Seweryn Kokot, 2010/07/05
- Re: How modify numbers in a region by a multiplier?,
Juanma Barranquero <=
- Re: How modify numbers in a region by a multiplier?, Seweryn Kokot, 2010/07/05
Re: How modify numbers in a region by a multiplier?, Dan Davison, 2010/07/01
Re: How modify numbers in a region by a multiplier?, Qiang Guo, 2010/07/01