# Quick calculation in org-mode table

I used to think that you can just type `=13*57` into an org-mode table's cell, hit Tab or Ret, and have it enter the result for you. Today, I learned that this isn't true the hard way as I used this a lot, recomputed the entire table via `C-u C-c C-c`, and performed too many steps to undo the mistakes before I noticed them. Until recently, I didn't recompute entire tables, so I probably got tables using this which will explode upon recomputation.

Apparently, using the above lets the table know that the entire column ought to have that value, for some reason. Upon recomputation of the affected cells, this takes effect.

This yields the question of what I assumed `=13*57` does can be done in a similarly easy fashion.

I know that you could use `:=13*57` but that enters the formula into the table formulas line which can get it cluttered up pretty quickly. I just want the result of the computation to be entered. How it came to be doesn't have to be preserved.

quickly calculating

If you're just using constants, like your example `13*57`, and not referring to other cells in the org table, you can use quick-calc to do this calculation.

`M-x quick-calc` reads an expression from the minibuffer, calculates it, and displays the result in the minibuffer.

inserting at point

With a prefix argument, it will also insert the result at point. So `C-u M-x quick-calc 13*57<RET>` will insert `741` at point in your org table -- and will also work anywhere in Emacs.

older emacsen

If you're on an Emacs older than 25.1, `#'quick-calc` exists, but does not do anything with the prefix argument. You can, when entering the expression, use `C-j` rather than `RET`, to tell `#'quick-calc` to insert the result at point. So the solution becomes `M-x quick-calc 13*57 C-j`.

• `quick-calc` displays the correct result but doesn't enter it into the document when I give it a prefix argument. I tried it both in an org table and in the scratch buffer. I also tried actually putting a number into the prefix argument but it didn't enter it either. Pressing `C-j` instead of `RET`, however, does enter the result into the document. Do you know why `C-u M-x quick-calc 13*57<RET>` doesn't work for me? I SSHed into a sever to check whether it works on the server but it doesn't either. If it did, maybe I could fiddle something together to make it work with a quick shortcut. – UTF-8 Oct 16 '17 at 20:49
• Hrm, are you running an old version of Emacs? Perhaps this is something that's changed recently? If you look at the quick-calc documentation, does it take an optional argument `INSERT`? If so, a simple wrapper around it could be written. – zck Oct 16 '17 at 21:31
• I use 24.5.1 and don't know how to access the documentation of a function. `describe-function` only yields this: pastebin.com/PULgKWJi I'm not sure whether that's what I'm supposed to be looking for. If I follow the link `calc.el, I only see that same text and that that function calls `calc-do-quick-calc`. `describe-function` doesn't even know `calc-do-quick-calc`. Can you please tell me how to access the documentation? – UTF-8 Oct 16 '17 at 22:03
• `#'describe-function` is looking up the documentation for the function. (You can also call it with `C-h f` if you want). I looked at some old NEWS files, and the prefix argument functionality to `#'quick-calc` was added in Emacs 25.1 So you can update to a newer Emacs, or just use `C-j` instead of RET to enter the expression. – zck Oct 17 '17 at 4:36
• Works with Emacs 25, so I came back to accept the fact this answer. Thank you for it and sorry for waiting with accepting it. – UTF-8 Mar 2 '18 at 15:44

You can use the calculator package, see here: https://www.gnu.org/software/emacs/manual/html_node/calc/RPN-Tutorial.html#RPN-Tutorial

You get your result fast and you can paste it into the org-tabular.

• This has the disadvantages that that package uses RPN which I'm not comfortable with atm and that it doesn't use the normal order of operations iirc (either multiplication or division has higher precedence). I don't want to screw up my calculations because of those things. – UTF-8 Oct 16 '17 at 20:53