瀏覽代碼

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 7 年之前
父節點
當前提交
6059c3a057
共有 2 個文件被更改,包括 25 次插入1 次删除
  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