From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: table formula help... Date: Sun, 07 Dec 2014 11:25:34 +0800 Message-ID: <8761do6t01.fsf@ericabrahamsen.net> References: <87ppbxfi5f.fsf@ericabrahamsen.net> <54838805.8090705@free.fr> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxSOJ-00033N-Su for emacs-orgmode@gnu.org; Sat, 06 Dec 2014 22:20:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XxSOE-0006II-AN for emacs-orgmode@gnu.org; Sat, 06 Dec 2014 22:20:11 -0500 Received: from plane.gmane.org ([80.91.229.3]:33114) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxSOE-0006G8-3f for emacs-orgmode@gnu.org; Sat, 06 Dec 2014 22:20:06 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XxSOD-0005Yd-3z for emacs-orgmode@gnu.org; Sun, 07 Dec 2014 04:20:05 +0100 Received: from 61.149.185.27 ([61.149.185.27]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 07 Dec 2014 04:20:05 +0100 Received: from eric by 61.149.185.27 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 07 Dec 2014 04:20:05 +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 Thierry Banel writes: > To elaborate on Michael's first suggestion, > we will first give a name ("work") to the table: > > #+TBLNAME: work > | Chars | Lines | Translator | > > |-------+-------+-----------------| > | | 84 | Austin Woerner | > | 6633 | | Eric Abrahamsen | > | 16984 | | Canaan Morse | > | | 24 | Lucas Klein | > | | 10 | Lucas Klein | > > Then typing C-c C-x i and answering the wizard questions, > we get a new table as follow: > > #+BEGIN: aggregate :table "work" :cols "Translator sum(Chars) sum(Lines)" > | Translator | sum(Chars) | sum(Lines) | > > |-----------------+------------+------------| > | Austin Woerner | NA | 84 | > | Eric Abrahamsen | 6633 | NA | > | Canaan Morse | 16984 | NA | > | Lucas Klein | 2 NA | 34 | > #+END: > > Whenever you change the "work" table, > you can easily refresh the aggregated table by typing C-c C-c > > To install the orgtbl-aggregate module, > add those lines to your .emacs: > > (require 'package) > (add-to-list 'package-archives '("melpa" . > "http://melpa.milkbox.net/packages/") t) > (package-initialize) > > Then type M-x package-list-packages > and install orgtbl-aggregate > > Have fun > Thierry Okay, having fun! This seems like exactly what I was after. A couple of things: I've attached a patch replacing some [a-z] regexps with [:word:], so that column names can be written in scripts other than ascii (my tables above are actually all in Chinese). I hope that's acceptable. I've changed blank fields to "0" so that I don't get the "NA" strings. Now I'd like to do more calculations based on the rows in the sum(Chars) and sum(Lines) columns. Ideally I could add a fourth column to the aggregate table, calculated from rows in the previous two. Is there any way to make a column specification that refers to columns in the same table? The fourth column would be defined as: (sum(prod($2 0.7) prod($3 10)) Where $2 and $3 refer to cells in the aggregated table. I made that up -- I don't even know if it's valid calc syntax. But that's the idea. Or perhaps I should be making a third table based on this second one? Thanks again! Eric --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Modify-regexps-to-find-word-instead-of-a-zA-Z.patch >From a5e50914e431420a39e544b3a05b72169828e269 Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen Date: Sun, 7 Dec 2014 10:56:04 +0800 Subject: [PATCH] Modify regexps to find [:word:] instead of a-zA-Z * orgtbl-aggregate.el (orgtbl-to-aggregated-table-parse-spec): Allow column names in scripts other than ASCII. --- orgtbl-aggregate.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/orgtbl-aggregate.el b/orgtbl-aggregate.el index b228545..af8fc12 100644 --- a/orgtbl-aggregate.el +++ b/orgtbl-aggregate.el @@ -273,7 +273,7 @@ or 0 for the special 'hline column." (cond ((string-match "^count()$" column) 'count) - ((string-match "^\\([a-z]+\\)(\\([a-zA-Z0-9_$]+\\))$" column) + ((string-match "^\\([[:word:]]+\\)(\\([[:word:]0-9_$]+\\))$" column) (setq id (intern (match-string 1 column))) (unless (memq id validid1) (error @@ -285,7 +285,7 @@ or 0 for the special 'hline column." table t))) ((string-match - "^\\([a-z]+\\)(\\([a-zA-Z0-9_$]+\\)[*,]\\([a-zA-Z0-9_$]+\\))$" + "^\\([[:word:]]+\\)(\\([[:word:]0-9_$]+\\)[*,]\\([[:word:]0-9_$]+\\))$" column) (setq id (intern (match-string 1 column))) (unless (memq id validid2) @@ -297,7 +297,7 @@ or 0 for the special 'hline column." (list id (orgtbl-to-aggregated-table-colname-to-int a table t) (orgtbl-to-aggregated-table-colname-to-int b table t)))) - ((string-match "^\\([a-zA-Z0-9_$]+\\)$" column) + ((string-match "^\\([[:word:]0-9_$]+\\)$" column) (orgtbl-to-aggregated-table-colname-to-int (match-string 1 column) table -- 2.1.3 --=-=-=--