[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: using lisp in replacement string
From: |
ronaldo.mercado |
Subject: |
RE: using lisp in replacement string |
Date: |
Wed, 24 Dec 2014 21:36:05 +0000 |
Hello, the function below performs a global search-replace
(defun hh ()
(interactive)
(let (match-beginning match-end match-string replacement)
(goto-char (point-min))
(while (re-search-forward "|\\([^|]*\\)|" nil t)
(setq match-beginning (match-beginning 0))
(setq match-end (match-end 0))
(setq replacement (concat "|" (calc-eval (match-string 1)) "|") )
(goto-char match-beginning)
(re-search-forward "|\\([^|]*\\)|" match-end nil)
(replace-match replacement t t nil 0))))
I did not understand why I needed to perform re-search-forward twice though.
without the second search, results were garbled.
________________________________________
From: help-gnu-emacs-bounces+ronaldo.mercado=diamond.ac.uk@gnu.org
[help-gnu-emacs-bounces+ronaldo.mercado=diamond.ac.uk@gnu.org] on behalf of
Dmitry Gutov [dgutov@yandex.ru]
Sent: 24 December 2014 14:52
To: Guido Van Hoecke
Cc: help-gnu-emacs
Subject: Re: using lisp in replacement string
On 12/24/2014 04:40 PM, Guido Van Hoecke wrote:
> Not really, if you quote it, it replaces the formulas by the calc-eval
> expression :(
If you don't quote it, it's not a string.
Anyway, check out these lines from `replace-regexp' docstring:
"This function is for interactive use only;
in Lisp code use `re-search-forward' and `replace-match' instead."
...
"In interactive calls, the replacement text may contain `\,'"
You're not using it interactively.
--
This e-mail and any attachments may contain confidential, copyright and or
privileged material, and are for the use of the intended addressee only. If you
are not the intended addressee or an authorised recipient of the addressee
please notify us of receipt by returning the e-mail and do not use, copy,
retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not
necessarily of Diamond Light Source Ltd.
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments
are free from viruses and we cannot accept liability for any damage which you
may sustain as a result of software viruses which may be transmitted in or with
the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and
Wales with its registered office at Diamond House, Harwell Science and
Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
Re: using lisp in replacement string, Nicolas Richard, 2014/12/24
Re: using lisp in replacement string, Andreas Röhler, 2014/12/25