From c7434974897d932fe3acd182f06a98a61719e208 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Tue, 20 Oct 2020 11:03:14 +0200 Subject: [PATCH 1/4] org-table: Fix table formula mode string handling * lisp/org-table.el (org-table-eval-formula): Move mode lookup table from org-table--set-calc-mode to here. * lisp/org-table.el (org-table--set-calc-mode): Use plist-put instead of the buggy open coded version. --- lisp/org-table.el | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 112b1e171..0790dc3ca 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -721,17 +721,8 @@ Field is restored even in case of abnormal exit." (org-table-goto-column ,column) (set-marker ,line nil))))) -(defsubst org-table--set-calc-mode (var &optional value) - (if (stringp var) - (setq var (assoc var '(("D" calc-angle-mode deg) - ("R" calc-angle-mode rad) - ("F" calc-prefer-frac t) - ("S" calc-symbolic-mode t))) - value (nth 2 var) var (nth 1 var))) - (if (memq var org-tbl-calc-modes) - (setcar (cdr (memq var org-tbl-calc-modes)) value) - (cons var (cons value org-tbl-calc-modes))) - org-tbl-calc-modes) +(defsubst org-table--set-calc-mode (var value) + (plist-put org-tbl-calc-modes var value)) ;;; Predicates @@ -2476,9 +2467,14 @@ location of point." (setq keep-empty t fmt (replace-match "" t t fmt))) (while (string-match "[DRFS]" fmt) - (setq org-tbl-calc-modes - (org-table--set-calc-mode (match-string 0 fmt))) - (setq fmt (replace-match "" t t fmt))) + (let* ((c (string-to-char (match-string 0 fmt))) + (mode (cdr (assoc c '((?D calc-angle-mode deg) + (?R calc-angle-mode rad) + (?F calc-prefer-frac t) + (?S calc-symbolic-mode t)))))) + (setq org-tbl-calc-modes (org-table--set-calc-mode + (car mode) (cadr mode)) + fmt (replace-match "" t t fmt)))) (unless (string-match "\\S-" fmt) (setq fmt nil)))) (when (and (not suppress-const) org-table-formula-use-constants) -- 2.28.0