summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Guerry <bzg@altern.org>2013-03-19 15:25:14 +0100
committerBastien Guerry <bzg@altern.org>2013-03-19 19:39:34 +0100
commitd8969931a90b238f4e4be5003257c842cf6bf4c3 (patch)
tree23b981c56f243faf506dc6fe6783c909fc5ec371
parentf4b38bcdbbec1faa6f5d5916d6cd58d04cf2f9a1 (diff)
downloadorg-mode-d8969931a90b238f4e4be5003257c842cf6bf4c3.tar.gz
org-table.el: Fix setting of constants.
* 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.
-rw-r--r--lisp/org-table.el32
-rw-r--r--lisp/org.el9
2 files changed, 21 insertions, 20 deletions
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 8da57b2..9696099 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 3220207..11349f6 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