From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: adding calc formatting to table formulas Date: Thu, 28 Feb 2013 21:06:03 +0800 Message-ID: <87ehg07flw.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:60119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UB3UW-0000mA-7m for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 08:25:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UB3UU-0008Cl-Vn for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 08:25:44 -0500 Received: from plane.gmane.org ([80.91.229.3]:55890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UB36a-0001Mj-PN for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 08:01:00 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UB36t-0000H3-KC for emacs-orgmode@gnu.org; Thu, 28 Feb 2013 14:01:19 +0100 Received: from 114.250.104.115 ([114.250.104.115]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 Feb 2013 14:01:19 +0100 Received: from eric by 114.250.104.115 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 28 Feb 2013 14:01:19 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0036-Allow-calc-group-digits-to-be-specified-in-TBLFMT-fo.patch >From b2dffa997e59702dfd6480363adb66d0e1e62adf Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen 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 --=-=-=--