Function: org-table-formula-substitute-names

org-table-formula-substitute-names is a byte-compiled function defined in org-table.el.gz.

Signature

(org-table-formula-substitute-names F)

Documentation

Replace $const with values in string F.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
(defun org-table-formula-substitute-names (f)
  "Replace $const with values in string F."
  (let ((start 0)
	(pp (/= (string-to-char f) ?'))
	(duration (string-match-p ";.*[Tt].*\\'" f))
	(new (replace-regexp-in-string	; Check for column names.
	      org-table-column-name-regexp
	      (lambda (m)
		(concat "$" (cdr (assoc (match-string 1 m)
					org-table-column-names))))
	      f t t)))
    ;; Parameters and constants.
    (while (setq start
		 (string-match
		  "\\$\\([a-zA-Z][_a-zA-Z0-9]*\\)\\|\\(\\<remote([^)]*)\\)"
		  new start))
      (if (match-end 2) (setq start (match-end 2))
	(cl-incf start)
	;; When a duration is expected, convert value on the fly.
	(let ((value
	       (save-match-data
		 (let ((v (org-table-get-constant (match-string 1 new))))
		   (if (and (org-string-nw-p v) duration)
		       (org-table-time-string-to-seconds v)
		     v)))))
	  (when value
	    (setq new (replace-match
		       (concat (and pp "(") value (and pp ")")) t t new))))))
    (if org-table-formula-debug (propertize new :orig-formula f) new)))