From mboxrd@z Thu Jan 1 00:00:00 1970 From: T Helms Subject: Re: Iterate many tables Date: Thu, 06 May 2010 07:34:44 -0400 Message-ID: <4BE2A954.7010401@gmail.com> References: Reply-To: maxco.tr@gmail.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1627499890==" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O9zMB-0001sm-16 for emacs-orgmode@gnu.org; Thu, 06 May 2010 07:35:07 -0400 Received: from [140.186.70.92] (port=46470 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9zM2-0001l6-Me for emacs-orgmode@gnu.org; Thu, 06 May 2010 07:35:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O9zM0-0006Iw-HQ for emacs-orgmode@gnu.org; Thu, 06 May 2010 07:34:58 -0400 Received: from mail-gw0-f41.google.com ([74.125.83.41]:42523) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O9zM0-0006HD-Ca for emacs-orgmode@gnu.org; Thu, 06 May 2010 07:34:56 -0400 Received: by gwj16 with SMTP id 16so1656332gwj.0 for ; Thu, 06 May 2010 04:34:50 -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 This is a multi-part message in MIME format. --===============1627499890== Content-Type: multipart/alternative; boundary="------------050200090407060504080607" This is a multi-part message in MIME format. --------------050200090407060504080607 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Thanks for bringing this up, it would be a useful tool. I get an error using the functions as well org-recalculate-all-tables: org-recalculate-all-tables: Wrong number of arguments: (lambda (function) "Apply FUNCTION to the start of all tables in the buffer." (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward org-table-any-line-regexp nil t) (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))) (beginning-of-line 1) (when (looking-at org-table-line-regexp) (save-excursion (funcall function)) (or (looking-at org-table-line-regexp) (forward-char 1))) (re-search-forward org-table-any-border-regexp nil 1)))) (message "Mapping tables: done")), 2 org-iterate-all-tables: while: Wrong number of arguments: (lambda (function) "Apply FUNCTION to the start of all tables in the buffer." (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward org-table-any-line-regexp nil t) (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))) (beginning-of-line 1) (when (looking-at org-table-line-regexp) (save-excursion (funcall function)) (or (looking-at org-table-line-regexp) (forward-char 1))) (re-search-forward org-table-any-border-regexp nil 1)))) (message "Mapping tables: done")), 2 On 05/05/2010 03:37 PM, Johan Ekh wrote: > > > Any idea what could be wrong? > > > > Error meassage: > > org-recalculate-all-tables: Wrong number of arguments: #[(function) > "S(OE~^eb^ÄÅÆ#f: > > > Best regards, > 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 > > > > _______________________________________________ > 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 > --------------050200090407060504080607 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Thanks for bringing this up, it would be a useful tool.

I get an error using the functions as well

org-recalculate-all-tables:
org-recalculate-all-tables: Wrong number of arguments: (lambda (function) "Apply FUNCTION to the start of all tables in the buffer." (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward org-table-any-line-regexp nil t) (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))) (beginning-of-line 1) (when (looking-at org-table-line-regexp) (save-excursion (funcall function)) (or (looking-at org-table-line-regexp) (forward-char 1))) (re-search-forward org-table-any-border-regexp nil 1)))) (message "Mapping tables: done")), 2

org-iterate-all-tables:
while: Wrong number of arguments: (lambda (function) "Apply FUNCTION to the start of all tables in the buffer." (save-excursion (save-restriction (widen) (goto-char (point-min)) (while (re-search-forward org-table-any-line-regexp nil t) (message "Mapping tables: %d%%" (/ (* 100.0 (point)) (buffer-size))) (beginning-of-line 1) (when (looking-at org-table-line-regexp) (save-excursion (funcall function)) (or (looking-at org-table-line-regexp) (forward-char 1))) (re-search-forward org-table-any-border-regexp nil 1)))) (message "Mapping tables: done")), 2


On 05/05/2010 03:37 PM, Johan Ekh wrote:


Any idea what could be wrong?



Error meassage:

org-recalculate-all-tables: Wrong number of arguments: #[(function) "ŠŒ~ˆebˆÄÅÆ#ƒ:


Best regards,
Johan






On Fri, Apr 30, 2010 at 5:03 PM, Carsten Dominik <carsten.dominik@gmail.com> 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


_______________________________________________ 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
--------------050200090407060504080607-- --===============1627499890== 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 --===============1627499890==--