From: Jeremie Juste <jeremiejuste@gmail.com>
To: Robert Pluim <rpluim@gmail.com>
Cc: Kein Test <soetwasaberauch@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: org-table-sum
Date: Sat, 24 Oct 2020 17:15:38 +0200 [thread overview]
Message-ID: <874kmju02t.fsf@gmail.com> (raw)
In-Reply-To: <m25z822pvl.fsf@gmail.com> (Robert Pluim's message of "Fri, 25 Sep 2020 10:59:42 +0200")
Hello,
I have slightly improved the org-table-sum function.
It calls directly calc-eval and yield the same result as vsum.
It can not handle better floating points.
> | 171.00 |
> | 4.07 |
> | 4.44 |
> | 2.61 |
> | 12.21 |
> | 6.69 |
> | 19.72 |
> | 23.09 |
> | 6.23 |
> | 15.28 |
> | 250.00 |
> | 250.00 |
> | 250.00 |
> | 78.85 |
> |--------|
> | |
> #+TBLFM:@>$1=vsum(@1$1..@-1$1)
diff --git a/lisp/org-table.el b/lisp/org-table.el
index a3c49874c..ac237af2c 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -4728,6 +4728,18 @@ blank, and the content is appended to the field above."
((equal n 0) nil)
(t n))))
+
+(defun org-table-cell-no-prop (x)
+ "remove property from org-table-cell. If cell is empty output nil. X is a string - a cell from org-table
+usage (org-table-cell-no-prop #(\"foo \" 0 2 (face default))) ==> foo
+"
+ (interactive)
+ (let ( (res (replace-regexp-in-string "\s+" ""
+ (substring-no-properties x))))
+ (when (not (equal res ""))
+ res)
+ ))
+
;;;###autoload
(defun org-table-sum (&optional beg end nlast)
"Sum numbers in region of current table column.
@@ -4769,9 +4781,9 @@ If NLAST is a number, only the NLAST fields will actually be summed."
(t (setq items (reverse items))
(setcdr (nthcdr (1- nlast) items) nil)
(nreverse items))))
- (numbers (delq nil (mapcar #'org-table--number-for-summing
- items1)))
- (res (apply '+ numbers))
+ (numbers (delq nil (mapcar 'org-table-cell-no-prop items1 )))
+ (res (string-to-number (calc-eval
+ (combine-and-quote-strings numbers "+"))))
Best regards
Jeremie Juste
next prev parent reply other threads:[~2020-10-24 15:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-24 19:38 org-table-sum Kein Test
2020-09-24 20:08 ` org-table-sum Mark Janes
2020-10-22 22:20 ` org-table-sum Jeremie Juste
2020-09-24 20:48 ` org-table-sum Kyle Meyer
2020-09-24 21:07 ` org-table-sum Kyle Meyer
2020-09-25 8:59 ` org-table-sum Robert Pluim
2020-09-26 23:07 ` org-table-sum Jeremie Juste
2020-09-28 12:27 ` org-table-sum Robert Pluim
2020-09-28 12:50 ` org-table-sum Jeremie Juste
2020-09-28 13:54 ` org-table-sum Robert Pluim
2020-10-24 15:15 ` Jeremie Juste [this message]
2020-09-25 7:51 ` org-table-sum Eric S Fraga
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=874kmju02t.fsf@gmail.com \
--to=jeremiejuste@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=rpluim@gmail.com \
--cc=soetwasaberauch@gmail.com \
/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).