Hallo, I've been messing about with getting tables to display formula results as for instance 30,00.00: two-place floating-point precision, and commas grouping digits. I realize I can set these as the defaults in org-calc-default-modes, but I wanted to alter the table formula format string to allow per-field formatting.
I made a small edit to org-table.el, which you can see in the attached patch. It assigns the key "G" to add "calc-group-digits t" to the front of org-tbl-calc-modes. I think it's uncovered a bug: it only works if I already have "calc-group-digits" present in org-calc-default-modes, because of the end of org-set-calc-mode: #+BEGIN_SRC emacs-lisp (if (memq var org-tbl-calc-modes) (setcar (cdr (memq var org-tbl-calc-modes)) value) (cons var (cons value org-tbl-calc-modes))) org-tbl-calc-modes) #+END_SRC If the mode is already present (with any value), it is set. If it's not, it's consed onto org-tbl-calc-modes, the resulting new list is jettisoned into the ether, and the original value of org-tbl-calc-modes is returned. I think it would have to look like this to work: #+BEGIN_SRC emacs-lisp (if (memq var org-tbl-calc-modes) (progn (setcar (cdr (memq var org-tbl-calc-modes)) value) org-tbl-calc-modes) (cons var (cons value org-tbl-calc-modes)))) #+END_SRC I'm not terribly confident about this, but perhaps someone could take a look? Thanks, Eric
>From b2dffa997e59702dfd6480363adb66d0e1e62adf Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen <e...@ericabrahamsen.net> Date: Thu, 28 Feb 2013 19:40:46 +0800 Subject: [PATCH 36/36] Allow calc-group-digits to be specified in TBLFMT format string. --- lisp/org-table.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 9cfb4b9..8c684b2 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2504,6 +2504,7 @@ of the new mark." (if (stringp var) (setq var (assoc var '(("D" calc-angle-mode deg) ("R" calc-angle-mode rad) + ("G" calc-group-digits t) ("F" calc-prefer-frac t) ("S" calc-symbolic-mode t))) value (nth 2 var) var (nth 1 var))) @@ -2611,7 +2612,7 @@ not overwrite the stored one." (if (string-match "E" fmt) (setq keep-empty t fmt (replace-match "" t t fmt))) - (while (string-match "[DRFS]" fmt) + (while (string-match "[DRFGS]" fmt) (setq org-tbl-calc-modes (org-set-calc-mode (match-string 0 fmt))) (setq fmt (replace-match "" t t fmt))) (unless (string-match "\\S-" fmt) -- 1.8.1.4