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: Mon, 29 Dec 2014 18:55:21 +0100

Hi Emanuel,


On 29 December 2014 at 05:40, Emanuel Berg <embe8573@student.uu.se> wrote:

> 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:
> ​...
> (And when you get it to work, post it here :))
>
> ​The final solution looks like this (the actual input is an 8 column org
table and the field for the computation is the fifth field):

(let (quantity)
      (while (re-search-forward
              "^|[^|]*|[^|]*|[^|]*|[^|]*|\\([^|]+\\)|.*$" nil t 1)
        (save-match-data
          (setq quantity (calc-eval (match-string-no-properties 1))))
        (delete-region (match-beginning 1) (match-end 1))
        (goto-char (match-beginning 1))
        (insert quantity)
        (end-of-line)))

I never found a working replace-match approach.

Many thanks to all volunteers that helped to come to this solution.


Guido


reply via email to

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