summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-11-26 22:41:14 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-11-26 22:56:06 +0100
commitd85ddfba0d07ceb303d915cd3240f26921204b57 (patch)
tree7968b1b2abc376767f6b707d6250cc908270547d
parentb0a436cb8e316b266c4d5f3691cc94625a3238b5 (diff)
downloadorg-mode-d85ddfba0d07ceb303d915cd3240f26921204b57.tar.gz
org-table: Fix c651e150cc8fb230fca99dfff27caedfddced8ff
* lisp/org-table.el (org-table-get-stored-formulas): Correctly detect named fields in formulas' LHS. * testing/lisp/test-org-table.el (test-org-table/named-field): (test-org-table/named-column): New tests. Reported-by: "Stefan-W. Hahn" <stefan.hahn@s-hahn.de> <http://permalink.gmane.org/gmane.emacs.orgmode/103119>
-rw-r--r--lisp/org-table.el17
-rw-r--r--testing/lisp/test-org-table.el32
2 files changed, 45 insertions, 4 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 638a284..09f4473 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -2297,10 +2297,19 @@ column formula? " ))
" *:: *"))
eq-alist seen)
(dolist (string strings (nreverse eq-alist))
- (when (string-match "\\`\\(@[-+I<>0-9.$@]+\\|@?[0-9]+\\|\
-\\$\\([a-zA-Z0-9]+\\|[<>]+\\)\\) *= *\\(.*[^ \t]\\)" string)
- (let* ((lhs (match-string 1 string))
- (rhs (match-string 3 string)))
+ (when (string-match "\\`\\(@[-+I<>0-9.$@]+\\|\\$\\([_a-zA-Z0-9]+\\|\
+[<>]+\\)\\) *= *\\(.*[^ \t]\\)"
+ string)
+ (let ((lhs
+ (let ((m (match-string 1 string)))
+ (cond
+ ((not (match-end 2)) m)
+ ;; Is it a column reference?
+ ((org-string-match-p "\\`$\\([0-9]+\\|[<>]+\\)\\'" m) m)
+ ;; Since named columns are not possible in
+ ;; LHS, assume this is a named field.
+ (t (match-string 2 string)))))
+ (rhs (match-string 3 string)))
(push (cons lhs rhs) eq-alist)
(cond
((not (member lhs seen)) (push lhs seen))
diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el
index 95ac7f4..ff8978d 100644
--- a/testing/lisp/test-org-table.el
+++ b/testing/lisp/test-org-table.el
@@ -1787,6 +1787,38 @@ is t, then new columns should be added as needed"
|---+---+---|
#+TBLFM: @3$2..@3$>=vsum(@1..@2)")))
+(ert-deftest test-org-table/named-field ()
+ "Test formula with a named field."
+ (should
+ (org-string-match-p
+ "| +| +1 +|"
+ (org-test-with-temp-text "
+| | |
+| ^ | name |
+<point>#+TBLFM: $name=1"
+ (org-table-calc-current-TBLFM)
+ (buffer-string))))
+ (should
+ (org-string-match-p
+ "| +| +1 +|"
+ (org-test-with-temp-text "
+| _ | name |
+| | |
+<point>#+TBLFM: $name=1"
+ (org-table-calc-current-TBLFM)
+ (buffer-string)))))
+
+(ert-deftest test-org-table/named-column ()
+ "Test formula with a named field."
+ (should
+ (org-string-match-p
+ "| +| +1 +| +1 +|"
+ (org-test-with-temp-text "
+| ! | name | |
+| | 1 | |
+<point>#+TBLFM: @2$3=$name"
+ (org-table-calc-current-TBLFM)
+ (buffer-string)))))
(provide 'test-org-table)