3

I got excited about Calc's power as an embedded mode. Define some variables in natural inline notation and then do operations on them.

But the execution seems a bit messy: you got a separate key bindings when you're in CalcEmbed mode and mistakes are easy to make.

Can the mode be tamed so that the following org-mode buffer:

* Calc test embed!

Let $foo := 342$ and $bar := 2.2$. Now $foo*bar => $!

Could be evaluated to

* Calc test embed!

Let $foo := 342$ and $bar := 2.2$. Now $foo*bar => 752.4$!

With a single key stroke, all the while remaining in org-mode?

mike3996
  • 463
  • 4
  • 15

2 Answers2

5

Maybe not a single keystroke but you could activate embedded mode via C-x * a and then (while point is in, say, the first expression) update all calc expressions with C-x * u. I use embedded mode all the time and it's one of the most understated features of Emacs!

éric
  • 440
  • 3
  • 3
1

To expand on @éric's answer: you can avoid having to activate the formulas explicitly with C-x * a by including these lines:

--- Local Variables: ---
--- eval:(calc-embedded-activate) ---
--- End: ---

In an org-mode file, using just # instead of --- is probably better though. Also notice that this and C-x * a doesn't actually activate embedded mode, but just activates the formulas for embedded mode, so you stay in org-mode. (See doc for calc-embedded-activate for reference.)

Also, you can call C-x * u with a numeric prefix, which will update all activated => formulas, so you don't need to move the point into a formula first (e.g. C-- C-x * u but not C-u C-x * u which will only update formulas in the current region). In itself, C-x * u will only update formulas which are dependent on the current formula (i.e. where the point is pointing at). (See doc for calc-embedded-update-formula for reference.)

David Ongaro
  • 370
  • 4
  • 13