[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using lisp in replacement string
From: |
Guido Van Hoecke |
Subject: |
Re: using lisp in replacement string |
Date: |
Thu, 25 Dec 2014 12:50:39 +0100 |
Hi Andreas,
On 25 December 2014 at 10:25, Andreas Röhler <andreas.roehler@easy-emacs.de>
wrote:
> On 24.12.2014 15:25, Guido Van Hoecke wrote:
>
>>
>> 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: \,
>>
>
> 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) )))
>
> Works like a charm, thanks a lot!
Guido
Re: using lisp in replacement string, Nicolas Richard, 2014/12/24
Re: using lisp in replacement string, Andreas Röhler, 2014/12/25
- Re: using lisp in replacement string,
Guido Van Hoecke <=