[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using lisp in replacement string
From: |
Emanuel Berg |
Subject: |
Re: using lisp in replacement string |
Date: |
Mon, 29 Dec 2014 05:40:21 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Guido Van Hoecke <guivho@gmail.com> 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
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,
Emanuel Berg <=