help-gnu-emacs
[Top][All Lists]
Advanced

[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: Wed, 24 Dec 2014 17:25:15 +0100

Hi,

"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 `\,'"
>>
>
I still do not get it. Say following content i​n the *scratch* buffer:

|2+6*21|
|3*15|
|7-3|

(defun test1 ()
  "just display the lisp form rather than execute it"
  (interactive)
  (goto-char (point-min))
  (while (re-search-forward "^|\\([^|]*\\)|$" nil t)
    (replace-match "(calc-eval \"\\1\")" nil nil nil 1)))

(defun test2 ()
  "try to replace the searched string with the result of the lisp form"
  (interactive)
  (goto-char (point-min))
  (while (re-search-forward "^|\\([^|]*\\)|$" nil t)
        (replace-match (calc-eval "\\1") nil nil nil 1)))

M-x test1 replaces the first three lines as follows:
|(calc-eval "2+6*21")|
|(calc-eval "3*15")|
|(calc-eval "7-3")|

C-x C-e of each of the calc-eval statements yields the expected result.

After undoing these changes and returning to the initial three lines,
M-x test2 complains:
while: Wrong type argument: stringp, (0 "Expected a number")

Any help would be highly appreciated,


Guido


reply via email to

[Prev in Thread] Current Thread [Next in Thread]