forked from mirrors/org-mode
org-table: Fix c651e150cc
* 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>
This commit is contained in:
parent
b0a436cb8e
commit
d85ddfba0d
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue