emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-orgmode@gnu.org
Subject: adding calc formatting to table formulas
Date: Thu, 28 Feb 2013 21:06:03 +0800	[thread overview]
Message-ID: <87ehg07flw.fsf@ericabrahamsen.net> (raw)

[-- 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


                 reply	other threads:[~2013-02-28 13:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ehg07flw.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).