|
@@ -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")
|