unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: help-gnu-emacs@gnu.org
Subject: Re: using lisp in replacement string
Date: Thu, 25 Dec 2014 10:25:44 +0100	[thread overview]
Message-ID: <549BD818.3070502@easy-emacs.de> (raw)
In-Reply-To: <m2tx0lcegf.fsf@gmail.com>

On 24.12.2014 15:25, Guido Van Hoecke wrote:
> Hi,
>
> I am trying to apply what I found in the Emacs manual
> -> Search (15 Searching and replacement)
> -> Replace (15.10 Replacement Commands)
> -> Regexp Replace (15.10.2 Regexp Replacement)
> "You can use Lisp expressions to calculate parts of the replacement
> string.  To do this, write `\,' followed by the expression in the
> replacement string.  Each replacement calculates the value of the
> expression and converts it to text without quoting (if it's a string,
> this means using the string's contents), and uses it in the replacement
> string in place of the expression itself."
>
> So I have a temp buffer with following content
> |2+6*21|
> |3*15|
> |7-3|
> and I want to replace the formulas between the '|' characters by the
> result of passing them to calc-eval:
>
> (replace-regexp "|\\([^|]*\\)|" \\,(calc-eval \\1) nil (point-min)(point-max))
> but this causes Debugger entered--Lisp error: (void-variable \\)
>
> So I try it with single slash:
> (replace-regexp "|\\([^|]*\\)|" \,(calc-eval \\1) nil (point-min)(point-max))
> and then I get : Symbol's value as variable is void: \,
>
> I got the distinct feeling I'm missing something very basic here...
>
> Please advise
>
> TIA,
>
> Guido
>
>

As Dimitry said, \, is for use in interactive call only.
Beside you don't need it, as forms might be evaluated the common way.

Try this:

(defun my-calc-eval ()
   (interactive)
   (let (erg)
     (goto-char (point-min))
     (while (re-search-forward "|\\([^|]+\\)|" nil t 1)
       (save-match-data
	(setq erg (calc-eval (match-string-no-properties 1))))
       ;; (message "%s" (match-string-no-properties 1))
       (delete-region (match-beginning 1) (match-end 1))
       (goto-char (match-beginning 1))
       (insert erg)
       (end-of-line) )))



  parent reply	other threads:[~2014-12-25  9:25 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
2014-12-24 14:56 ` Nicolas Richard
2014-12-25  9:25 ` Andreas Röhler [this message]
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=549BD818.3070502@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --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).