ソースを参照

Add commands to recalculate and iterate all tables in a buffer

This was a request by Johna Ekh.
Carsten Dominik 15 年 前
コミット
e27bc453de
4 ファイル変更43 行追加0 行削除
  1. 5 0
      doc/ChangeLog
  2. 5 0
      doc/org.texi
  3. 3 0
      lisp/ChangeLog
  4. 30 0
      lisp/org-table.el

+ 5 - 0
doc/ChangeLog

@@ -1,3 +1,8 @@
+2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.texi (Updating the table): Document new buffer-wide
+	table commands.
+
 2010-04-26  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.texi (Conflicts): Document new work-around for windmove.el.

+ 5 - 0
doc/org.texi

@@ -2466,6 +2466,11 @@ hline are left alone, assuming that these are part of the table header.
 Iterate the table by recomputing it until no further changes occur.
 This may be necessary if some computed fields use the value of other
 fields that are computed @i{later} in the calculation sequence.
+@item M-x org-table-recalculate-buffer-tables
+Recompute all tables in the current buffer.
+@item M-x org-table-iterate-buffer-tables
+Iterate all tables in the current buffer, in order to converge table-to-table
+dependencies.
 @end table
 
 @node Advanced features,  , Updating the table, The spreadsheet

+ 3 - 0
lisp/ChangeLog

@@ -1,5 +1,8 @@
 2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-table.el (org-table-recalculate-buffer-tables)
+	(org-table-iterate-buffer-tables): New commands.
+
 	* org.el (org-check-for-hidden): When there is a region, skip
 	the check.
 

+ 30 - 0
lisp/org-table.el

@@ -2685,6 +2685,36 @@ known that the table will be realigned a little later anyway."
 	  (throw 'exit t)))
       (error "No convergence after %d iterations" i))))
 
+(defun org-table-recalculate-buffer-tables ()
+  "Recalculate all tables in the current buffer."
+  (interactive)
+  (save-excursion
+    (save-restriction
+      (widen)
+      (org-table-map-tables (lambda () (org-table-recalculate t)) t))))
+
+(defun org-table-iterate-buffer-tables ()
+  "Iterate all tables in the buffer, to converge inter-table dependencies."
+ (interactive)
+ (let* ((imax 10)
+        (checksum (md5 (buffer-string)))
+
+        c1
+        (i imax))
+   (save-excursion
+     (save-restriction
+       (widen)
+       (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))))))
+
 (defun org-table-formula-substitute-names (f)
   "Replace $const with values in string F."
   (let ((start 0) a (f1 f) (pp (/= (string-to-char f) ?')))