From mboxrd@z Thu Jan 1 00:00:00 1970 From: Johan Ekh Subject: Re: Iterate many tables Date: Mon, 3 May 2010 22:14:25 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0713906491==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O922C-0000cc-PQ for emacs-orgmode@gnu.org; Mon, 03 May 2010 16:14:32 -0400 Received: from [140.186.70.92] (port=58663 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O922A-0000cF-B0 for emacs-orgmode@gnu.org; Mon, 03 May 2010 16:14:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9228-0005a3-4A for emacs-orgmode@gnu.org; Mon, 03 May 2010 16:14:29 -0400 Received: from mail-fx0-f41.google.com ([209.85.161.41]:50750) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9227-0005Za-VW for emacs-orgmode@gnu.org; Mon, 03 May 2010 16:14:28 -0400 Received: by fxm1 with SMTP id 1so2542877fxm.0 for ; Mon, 03 May 2010 13:14:26 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --===============0713906491== Content-Type: multipart/alternative; boundary=001485f5ae024be4850485b63ddc --001485f5ae024be4850485b63ddc Content-Type: text/plain; charset=ISO-8859-1 Thanks, I will try it and report back. //Johan On Fri, Apr 30, 2010 at 5:03 PM, Carsten Dominik wrote: > > On Apr 30, 2010, at 4:07 PM, Johan Ekh wrote: > > Hi all, >> I have a series of tables in a single file. Each table have some fields >> that depends on fields >> in the previous table. Thus, if I change something in the first table, I >> must go down manually >> and recalculate (or iterate) each table. Is there a way to recalculate all >> tables in a file simultaneously? >> > > > Hi Johan, > > This should work if the dependence is only backwards. > > (defun org-recalculate-all-tables () > (interactive) > (org-table-map-tables (lambda () (org-table-recalculate t)) t)) > > If you have dependencies in both directions, this might work (untested): > > (defun org-iterate-all-tables () > (interactive) > (let* ((imax 10) > (checksum (md5 (buffer-string))) > c1 > (i imax)) > (catch 'exit > (while (> i 0) > (setq i (1- i)) > (org-table-map-tables (lambda () (org-table-recalculate t)) t) > (if (equal checksum (setq c1 (md5 (buffer-string)))) > (progn > (message "Convergence after %d iterations" (- imax i)) > (throw 'exit t)) > (setq checksum c1))) > (error "No convergence after %d iterations" imax)))) > > If it does, this could be added to org-hacks on Worg. > > HTH > > - Carsten > > --001485f5ae024be4850485b63ddc Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks,
I will try it and report back.
//Johan

On Fri, Apr 30, 2010 at 5:03 PM, Carsten Dominik <carsten.dominik@gmail.= com> wrote:
<= div class=3D"h5">
On Apr 30, 2010, at 4:07 PM, Johan Ekh wrote:

Hi all,
I have a series of tables in a single file. Each table have some fields tha= t depends on fields
in the previous table. Thus, if I change something in the first table, I mu= st go down manually
and recalculate (or iterate) each table. Is there a way to recalculate all = tables in a file simultaneously?


Hi Johan,

This should work if the dependence is only backwards.

(defun org-recalculate-all-tables ()
=A0 (interactive)
=A0 (org-table-map-tables (lambda () (org-table-recalculate t)) t))

If you have dependencies in both directions, this might work (untested):
(defun org-iterate-all-tables ()
=A0(interactive)
=A0(let* ((imax 10)
=A0 =A0 =A0 =A0 (checksum (md5 (buffer-string)))
=A0 =A0 =A0 =A0 c1
=A0 =A0 =A0 =A0 (i imax))
=A0 =A0(catch 'exit
=A0 =A0 =A0(while (> i 0)
=A0 =A0 =A0 =A0(setq i (1- i))
=A0 =A0 =A0 =A0(org-table-map-tables (lambda () (org-table-recalculate t))= t)
=A0 =A0 =A0 =A0(if (equal checksum (setq c1 (md5 (buffer-string))))
=A0 =A0 =A0 =A0 =A0 =A0(progn
=A0 =A0 =A0 =A0 =A0 =A0 =A0(message "Convergence after %d iterations&= quot; (- imax i))
=A0 =A0 =A0 =A0 =A0 =A0 =A0(throw 'exit t))
=A0 =A0 =A0 =A0 =A0(setq checksum c1)))
=A0 =A0 =A0(error "No convergence after %d iterations" imax))))<= br>
If it does, this could be added to org-hacks on Worg.

HTH

- Carsten


--001485f5ae024be4850485b63ddc-- --===============0713906491== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --===============0713906491==--