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