From d8969931a90b238f4e4be5003257c842cf6bf4c3 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Tue, 19 Mar 2013 15:25:14 +0100 Subject: [PATCH] org-table.el: Fix setting of constants. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * org.el (org-set-regexps-and-options): Use `org-table-set-constants'. * org-table.el (org-table-set-constants): New function. (orgtbl-ctrl-c-ctrl-c): Use it. Thanks to Oliver Večerník for reporting problems here. --- lisp/org-table.el | 32 ++++++++++++++++++++------------ lisp/org.el | 9 +-------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lisp/org-table.el b/lisp/org-table.el index 8da57b2c5..969609916 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2959,6 +2959,24 @@ list, 'literal is for the format specifier L." ",") "]")))) ;;;###autoload +(defun org-table-set-constants () + "Set `org-table-formula-constants-local' in the current buffer." + (let (cst consts const-str) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^[ \t]*#\\+CONSTANTS: \\(.*\\)" nil t) + (setq const-str (substring-no-properties (match-string 1))) + (setq consts (append consts (org-split-string const-str "[ \t]+"))) + (when consts + (let (e) + (while (setq e (pop consts)) + (when (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e) + (if (assoc-string (match-string 1 e) cst) + (setq cst (delete (assoc-string (match-string 1 e) cst) cst))) + (push (cons (match-string 1 e) (match-string 2 e)) cst))) + (setq org-table-formula-constants-local cst))))))) + +;;;###autoload (defun org-table-recalculate (&optional all noalign) "Recalculate the current table line by applying all stored formulas. With prefix arg ALL, do this for all lines in the table. @@ -4243,7 +4261,7 @@ to execute outside of tables." If it is a table to be sent away to a receiver, do it. With prefix arg, also recompute table." (interactive "P") - (let ((case-fold-search t) (pos (point)) action consts-str consts cst const-str) + (let ((case-fold-search t) (pos (point)) action) (save-excursion (beginning-of-line 1) (setq action (cond @@ -4261,17 +4279,7 @@ With prefix arg, also recompute table." (when (orgtbl-send-table 'maybe) (run-hooks 'orgtbl-after-send-table-hook))) ((eq action 'recalc) - (save-excursion - (goto-char (point-min)) - (while (re-search-forward "^[ \t]*#\\+CONSTANTS: \\(.*\\)" nil t) - (setq const-str (substring-no-properties (match-string 1))) - (setq consts (append consts (org-split-string const-str "[ \t]+"))) - (when consts - (let (e) - (while (setq e (pop consts)) - (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e) - (push (cons (match-string 1 e) (match-string 2 e)) cst))) - (setq org-table-formula-constants-local cst))))) + (org-table-set-constants) (save-excursion (beginning-of-line 1) (skip-chars-backward " \r\n\t") diff --git a/lisp/org.el b/lisp/org.el index 322020733..11349f638 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4804,7 +4804,7 @@ but the stars and the body are.") ((equal key "DRAWERS") (setq drawers (delete-dups (append org-drawers (org-split-string value splitre))))) ((equal key "CONSTANTS") - (setq const (append const (org-split-string value splitre)))) + (org-table-set-constants)) ((equal key "STARTUP") (let ((opts (org-split-string value splitre)) l var val) @@ -4908,13 +4908,6 @@ but the stars and the body are.") org-todo-kwd-alist (nreverse org-todo-kwd-alist) org-todo-key-trigger (delq nil (mapcar 'cdr org-todo-key-alist)) org-todo-key-alist (org-assign-fast-keys org-todo-key-alist))) - ;; Process the constants - (when const - (let (e cst) - (while (setq e (pop const)) - (if (string-match "^\\([a-zA-Z0][_a-zA-Z0-9]*\\)=\\(.*\\)" e) - (push (cons (match-string 1 e) (match-string 2 e)) cst))) - (setq org-table-formula-constants-local cst))) ;; Process the tags. (when tags -- 2.11.4.GIT