From: gareth.rees@pobox.com (Gareth Rees)
Subject: Re: copy-region-to-variable
Date: 4 Feb 2004 11:47:44 -0800 [thread overview]
Message-ID: <e867ce6d.0402041147.6bd1658a@posting.google.com> (raw)
In-Reply-To: bvqqpd$uh$1@news.tue.nl
Hans Nieuwenhuizen wrote:
> None of the almost 2000 built-in functions of emacs 21.2 seems to copy
> part of the buffer (region) into a variable.
As others have said, 'buffer-substring' gives you a substring of a
buffer. However, you don't need that to solve your problem.
> You need that e.g. if you have to enlarge the double in the region by
> a factor of say 3.456. Can anybody tell me how to do that?
If you want to do this interactively, use 'query-replace-regexp-eval'.
For example, to multiply each number by 3.456, type:
M-x query-replace-regexp-eval RET
[0-9.]+ RET
(* 3.456 (string-to-number \0)) RET
Non-interactively, you'd write Lisp like this:
(while (re-search-forward "[0-9]+\\(\\.[0-9]+\\)?" nil t)
(replace-match
(number-to-string (* 3.456 (string-to-number (match-string 0))))))
(Note that you need to be a bit more careful with the regexp for numbers
when you're not interactive, and you need 'number-to-string'.)
--
Gareth Rees
prev parent reply other threads:[~2004-02-04 19:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-04 13:06 copy-region-to-variable hans nieuwenhuizen
2004-02-04 13:14 ` copy-region-to-variable Joakim Hove
2004-02-04 13:50 ` copy-region-to-variable Johan Bockgård
2004-02-04 19:47 ` Gareth Rees [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e867ce6d.0402041147.6bd1658a@posting.google.com \
--to=gareth.rees@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.