0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-29 20:07:46 +00:00

org-table: Fix `org-table-eval-formula'

* lisp/org-table.el (org-table-get-formula):
(org-table-store-formulas): Column formulas references are stored along
with their dollar-sign since "Fix `org-table-get-range' with column
formulas". Update functions accordingly.

Reported-by: John Hendy <jw.hendy@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/103056>
This commit is contained in:
Nicolas Goaziou 2015-11-23 23:19:14 +01:00
parent 773e0e9c72
commit 16c7594a0f

View file

@ -2192,17 +2192,19 @@ When NAMED is non-nil, look for a named equation."
(line-beginning-position))
(org-table-current-column))
org-table-named-field-locations)))
(ref (format "@%d$%d" (org-table-current-dline)
(ref (format "@%d$%d"
(org-table-current-dline)
(org-table-current-column)))
(refass (assoc ref stored-list))
(nameass (assoc name stored-list))
(scol (if named
(if (and name (not (string-match "^LR[0-9]+$" name)))
name
ref)
(int-to-string (org-table-current-column))))
(dummy (and (or nameass refass) (not named)
(not (y-or-n-p "Replace existing field formula with column formula? " ))
(scol (cond
((not named) (format "$%d" (org-table-current-column)))
((and name (not (string-match "\\`LR[0-9]+\\'" name))) name)
(t ref)))
(dummy (and (or nameass refass)
(not named)
(not (y-or-n-p "Replace existing field formula with \
column formula? " ))
(message "Formula not replaced")))
(name (or name ref))
(org-table-may-need-update nil)
@ -2215,9 +2217,8 @@ When NAMED is non-nil, look for a named equation."
(t (org-table-formula-from-user
(read-string
(org-table-formula-to-user
(format "%s formula %s%s="
(format "%s formula %s="
(if named "Field" "Column")
(if (member (string-to-char scol) '(?$ ?@)) "" "$")
scol))
(if stored (org-table-formula-to-user stored) "")
'org-table-formula-history
@ -2243,23 +2244,21 @@ When NAMED is non-nil, look for a named equation."
(defun org-table-store-formulas (alist)
"Store the list of formulas below the current table."
(setq alist (sort alist 'org-table-formula-less-p))
(let ((case-fold-search t))
(save-excursion
(goto-char (org-table-end))
(let ((case-fold-search t))
(if (looking-at "\\([ \t]*\n\\)*[ \t]*\\(#\\+tblfm:\\)\\(.*\n?\\)")
(progn
;; don't overwrite TBLFM, we might use text properties to store stuff
;; Don't overwrite TBLFM, we might use text properties to
;; store stuff.
(goto-char (match-beginning 3))
(delete-region (match-beginning 3) (match-end 0)))
(org-indent-line)
(insert (or (match-string 2) "#+TBLFM:")))
(insert " "
(mapconcat (lambda (x)
(concat
(if (equal (string-to-char (car x)) ?@) "" "$")
(car x) "=" (cdr x)))
alist "::")
(mapconcat (lambda (x) (concat (car x) "=" (cdr x)))
(sort alist #'org-table-formula-less-p)
"::")
"\n"))))
(defsubst org-table-formula-make-cmp-string (a)