Parcourir la source

Fix table align when recalculating buffer tables

* lisp/org-table.el (org-table-recalculate-buffer-tables): Align all
tables in a buffer.
(org-table-iterate-buffer-tables): Align a table only once, align all
tables in a buffer.
Michael Brand il y a 8 ans
Parent
commit
359afa6806
2 fichiers modifiés avec 13 ajouts et 5 suppressions
  1. 11 2
      lisp/org-table.el
  2. 2 3
      testing/lisp/test-org-table.el

+ 11 - 2
lisp/org-table.el

@@ -3321,7 +3321,14 @@ with the prefix ARG."
   "Recalculate all tables in the current buffer."
   (interactive)
   (org-with-wide-buffer
-   (org-table-map-tables (lambda () (org-table-recalculate t)) t)))
+   (org-table-map-tables
+    (lambda ()
+      ;; Reason for separate `org-table-align': When repeating
+      ;; (org-table-recalculate t) `org-table-may-need-update' gets in
+      ;; the way.
+      (org-table-recalculate t t)
+      (org-table-align))
+    t)))
 
 ;;;###autoload
 (defun org-table-iterate-buffer-tables ()
@@ -3335,12 +3342,14 @@ with the prefix ARG."
      (catch 'exit
        (while (> i 0)
 	 (setq i (1- i))
-	 (org-table-map-tables (lambda () (org-table-recalculate t)) t)
+	 (org-table-map-tables (lambda () (org-table-recalculate t t)) t)
 	 (if (equal checksum (setq c1 (md5 (buffer-string))))
 	     (progn
+	       (org-table-map-tables #'org-table-align t)
 	       (message "Convergence after %d iterations" (- imax i))
 	       (throw 'exit t))
 	   (setq checksum c1)))
+       (org-table-map-tables #'org-table-align t)
        (user-error "No convergence after %d iterations" imax)))))
 
 (defun org-table-calc-current-TBLFM (&optional arg)

+ 2 - 3
testing/lisp/test-org-table.el

@@ -174,11 +174,10 @@
 
 |  c  d  |
 ")
-	;; FIXME: Tables should be aligned.
 	(after "
-|  a  b  |
+| a  b |
 
-|  c  d  |
+| c  d |
 "))
     (should (equal (org-test-with-temp-text before
 		     (org-table-recalculate-buffer-tables)