Browse Source

org-table: Clean left-over `:org-untouchable' property

* lisp/org-table.el (org-table-recalculate): Clean `:org-untouchable'
  property once we no longer need it.

* testing/lisp/test-org-table.el (test-org-table/formula-priority):
  New test.

Reported-by: Ruy Exel <ruyexel@gmail.com>
<http://lists.gnu.org/archive/html/emacs-orgmode/2017-11/msg00159.html>
Nicolas Goaziou 8 months ago
parent
commit
6059c3a057
2 changed files with 25 additions and 1 deletions
  1. 4 1
      lisp/org-table.el
  2. 21 0
      testing/lisp/test-org-table.el

+ 4 - 1
lisp/org-table.el

@@ -3270,7 +3270,9 @@ existing formula for column %s"
 		 (org-table-goto-field name)
 		 (org-table-put-field-property :org-untouchable t)))))
 	 ;; Evaluate the column formulas, but skip fields covered by
-	 ;; field formulas.
+	 ;; field formulas.  This is done by setting
+	 ;; `:org-untouchable' property on such fields.  The property
+	 ;; is them removed once column formulas have been applied.
 	 (goto-char beg)
 	 (while (re-search-forward line-re end t)
 	   (unless (string-match "\\` *[_^!$/] *\\'" (org-table-get-field 1))
@@ -3292,6 +3294,7 @@ existing formula for column %s"
 	       (unless (get-text-property (point) :org-untouchable)
 		 (org-table-eval-formula
 		  nil (cdr entry) 'noalign 'nocst 'nostore 'noanalysis)))))
+	 (remove-text-properties beg end '(:org-untouchable))
 	 ;; Evaluate the field formulas.
 	 (dolist (eq eqlfield)
 	   (let ((reference (car eq))

+ 21 - 0
testing/lisp/test-org-table.el

@@ -1906,6 +1906,27 @@ is t, then new columns should be added as needed"
       (org-table-calc-current-TBLFM)
       (buffer-string)))))
 
+(ert-deftest test-org-table/formula-priority ()
+  "Test field formula priority over column formula."
+  ;; Field formulas bind stronger than column formulas.
+  (should
+   (equal
+    "| 1 |  3 |\n| 2 | 99 |\n"
+    (org-test-with-temp-text
+	"| 1 |   |\n| 2 |   |\n<point>#+tblfm: $2=3*$1::@2$2=99"
+      (org-table-calc-current-TBLFM)
+      (buffer-substring-no-properties (point-min) (point)))))
+  ;; When field formula is removed, table formulas is applied again.
+  (should
+   (equal
+    "| 1 | 3 |\n| 2 | 6 |\n"
+    (org-test-with-temp-text
+	"| 1 |   |\n| 2 |   |\n#+tblfm: $2=3*$1<point>::@2$2=99"
+      (org-table-calc-current-TBLFM)
+      (delete-region (point) (line-end-position))
+      (org-table-calc-current-TBLFM)
+      (buffer-substring-no-properties (point-min) (line-beginning-position))))))
+
 (ert-deftest test-org-table/tab-indent ()
   "Test named fields with tab indentation."
   (should