* adding calc formatting to table formulas
@ 2013-02-28 13:06 Eric Abrahamsen
0 siblings, 0 replies; only message in thread
From: Eric Abrahamsen @ 2013-02-28 13:06 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]
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
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0036-Allow-calc-group-digits-to-be-specified-in-TBLFMT-fo.patch --]
[-- Type: text/x-patch, Size: 1165 bytes --]
From b2dffa997e59702dfd6480363adb66d0e1e62adf Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-02-28 13:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-28 13:06 adding calc formatting to table formulas Eric Abrahamsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).