forked from mirrors/org-mode
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.
This commit is contained in:
parent
f4b38bcdbb
commit
d8969931a9
|
@ -2958,6 +2958,24 @@ list, 'literal is for the format specifier L."
|
|||
elements
|
||||
",") "]"))))
|
||||
|
||||
;;;###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.
|
||||
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue