Fix multiple TBLFM

Simplify commit release_8.2.4-14-geb28fe4 and commit
release_8.2.5c-8-ga2619b7.

* org-table.el (org-table-fix-formulas): Handle multiple #+TBLFM lines
with `forward-line'.
This commit is contained in:
Michael Brand 2014-01-09 20:10:19 +01:00
parent a2619b7145
commit 34af2fe7ff

View file

@ -2274,36 +2274,35 @@ KEY is \"@\" or \"$\". REPLACE is an alist of numbers to replace.
For all numbers larger than LIMIT, shift them by DELTA." For all numbers larger than LIMIT, shift them by DELTA."
(save-excursion (save-excursion
(goto-char (org-table-end)) (goto-char (org-table-end))
(let ((case-fold-search t) (while (let ((case-fold-search t)) (looking-at "[ \t]*#\\+tblfm:"))
(s-end (min (save-excursion (re-search-forward "^\\S-*$\\|\\'" nil t)) (let ((msg "The formulas in #+TBLFM have been updated")
(save-excursion (org-end-of-subtree t))))) (re (concat key "\\([0-9]+\\)"))
(while (re-search-forward "[ \t]*#\\+tblfm:" s-end t) (re2
(let ((msg "The formulas in #+TBLFM have been updated") (when remove
(re (concat key "\\([0-9]+\\)")) (if (or (equal key "$") (equal key "$LR"))
(re2 (format "\\(@[0-9]+\\)?%s%d=.*?\\(::\\|$\\)"
(when remove (regexp-quote key) remove)
(if (or (equal key "$") (equal key "$LR")) (format "@%d\\$[0-9]+=.*?\\(::\\|$\\)" remove))))
(format "\\(@[0-9]+\\)?%s%d=.*?\\(::\\|$\\)" s n a)
(regexp-quote key) remove) (when remove
(format "@%d\\$[0-9]+=.*?\\(::\\|$\\)" remove)))) (while (re-search-forward re2 (point-at-eol) t)
s n a)
(when remove
(while (re-search-forward re2 (point-at-eol) t)
(unless (save-match-data (org-in-regexp "remote([^)]+?)"))
(if (equal (char-before (match-beginning 0)) ?.)
(user-error "Change makes TBLFM term %s invalid, use undo to recover"
(match-string 0))
(replace-match "")))))
(while (re-search-forward re (point-at-eol) t)
(unless (save-match-data (org-in-regexp "remote([^)]+?)")) (unless (save-match-data (org-in-regexp "remote([^)]+?)"))
(setq s (match-string 1) n (string-to-number s)) (if (equal (char-before (match-beginning 0)) ?.)
(cond (user-error
((setq a (assoc s replace)) "Change makes TBLFM term %s invalid, use undo to recover"
(replace-match (concat key (cdr a)) t t) (match-string 0))
(message msg)) (replace-match "")))))
((and limit (> n limit)) (while (re-search-forward re (point-at-eol) t)
(replace-match (concat key (int-to-string (+ n delta))) t t) (unless (save-match-data (org-in-regexp "remote([^)]+?)"))
(message msg)))))))))) (setq s (match-string 1) n (string-to-number s))
(cond
((setq a (assoc s replace))
(replace-match (concat key (cdr a)) t t)
(message msg))
((and limit (> n limit))
(replace-match (concat key (int-to-string (+ n delta))) t t)
(message msg))))))
(forward-line))))
(defun org-table-get-specials () (defun org-table-get-specials ()
"Get the column names and local parameters for this table." "Get the column names and local parameters for this table."