From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: using lisp in replacement string Date: Mon, 29 Dec 2014 05:40:21 +0100 Organization: Aioe.org NNTP Server Message-ID: <87mw67kr0q.fsf@debian.uxu> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1419828025 22501 80.91.229.3 (29 Dec 2014 04:40:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Dec 2014 04:40:25 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 29 05:40:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y5S7t-00063h-VF for geh-help-gnu-emacs@m.gmane.org; Mon, 29 Dec 2014 05:40:18 +0100 Original-Received: from localhost ([::1]:60163 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5S7t-0005hX-Al for geh-help-gnu-emacs@m.gmane.org; Sun, 28 Dec 2014 23:40:17 -0500 Original-Path: usenet.stanford.edu!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 51 Original-NNTP-Posting-Host: feB02bRejf23rfBm51Mt7Q.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:VzwJGFvfpv/nCw63CQDWfOm52T0= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:209464 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:101743 Archived-At: Guido Van Hoecke writes: > 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 Yes, you can do that! I did that once with a file like this: normal bright bk r g y bl m c w bk r g y bl m c w r 0 233 50 170 100 200 0 150 110 255 0 220 133 255 0 190 g 0 0 150 170 100 0 170 150 110 33 190 220 133 0 190 190 b 0 0 50 0 200 200 170 150 110 33 0 0 255 255 190 190 I thought it could be cool to, for example, add 10% to each - the span is (as you see) 0 to 255, so +10% from 150 would be ... 177? Anyway, I got rid of that code because it was much easier and more powerful to just tweak it by hand, digit by digit. Still, it is the exact situation as yours - replace a value by another value, that is a function of the first value - or, replace x by f(x) - so I can tell you how I did it. (Let this be a lesson to naive Elispers - including those who verbalize the lesson - always keep your code, even that which you don't use...) Now: check out this, from the help of `replace-regexp'. (while (re-search-forward REGEXP nil t) (replace-match TO-STRING nil nil)) So instead of the `replace-match' stuff above, you write a function that examines `match-beginning', `match-end', and `match-string', and then use that as input to your Elisp, to produce the on-the-fly TO-STRING (in the phrasing of the above Elisp). Good luck! (And when you get it to work, post it here :)) -- underground experts united