unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <ronaldo.mercado@diamond.ac.uk>
To: <dgutov@yandex.ru>, <guivho@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: RE: using lisp in replacement string
Date: Wed, 24 Dec 2014 21:36:05 +0000	[thread overview]
Message-ID: <3D65E04168FA09429B823CA3FE25C4478C5528B2@EXCHMBX01.fed.cclrc.ac.uk> (raw)
In-Reply-To: <549AD331.3030008@yandex.ru>

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

  parent reply	other threads:[~2014-12-24 21:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-24 14:25 using lisp in replacement string Guido Van Hoecke
2014-12-24 14:27 ` Dmitry Gutov
2014-12-24 14:40   ` Guido Van Hoecke
2014-12-24 14:52     ` Dmitry Gutov
     [not found]       ` <CAEySM9GB6z1yBJSy8AzwN4a6LK4KRQBYQZ2-fZRDtmQ0XTCYng@mail.gmail.com>
2014-12-24 16:25         ` Guido Van Hoecke
     [not found]         ` <mailman.16678.1419438348.1147.help-gnu-emacs@gnu.org>
2014-12-24 16:43           ` Barry Margolin
2014-12-24 21:36       ` ronaldo.mercado [this message]
2014-12-24 14:56 ` Nicolas Richard
2014-12-25  9:25 ` Andreas Röhler
2014-12-25 11:50   ` Guido Van Hoecke
     [not found] <mailman.16672.1419431131.1147.help-gnu-emacs@gnu.org>
2014-12-29  4:40 ` Emanuel Berg
2014-12-29 17:55   ` Guido Van Hoecke

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D65E04168FA09429B823CA3FE25C4478C5528B2@EXCHMBX01.fed.cclrc.ac.uk \
    --to=ronaldo.mercado@diamond.ac.uk \
    --cc=dgutov@yandex.ru \
    --cc=guivho@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).