Function: org-replace-escapes
org-replace-escapes is a byte-compiled function defined in
org-macs.el.
Signature
(org-replace-escapes STRING TABLE)
Documentation
Replace %-escapes in STRING with values in TABLE.
TABLE is an association list with keys like "%a" and string values. The sequences in STRING may contain normal field width and padding information, for example "%-5s". Replacements happen in the sequence given by TABLE, so values can contain further %-escapes if they are define later in TABLE.
Source Code
;; Defined in ~/.emacs.d/elpa/org-9.8.2/org-macs.el
(defun org-replace-escapes (string table)
"Replace %-escapes in STRING with values in TABLE.
TABLE is an association list with keys like \"%a\" and string values.
The sequences in STRING may contain normal field width and padding information,
for example \"%-5s\". Replacements happen in the sequence given by TABLE,
so values can contain further %-escapes if they are define later in TABLE."
(let ((tbl (copy-alist table))
(case-fold-search nil)
(pchg 0)
re rpl)
(dolist (e tbl)
(setq re (concat "%-?[0-9.]*" (substring (car e) 1)))
(when (and (cdr e) (string-match re (cdr e)))
(let ((sref (substring (cdr e) (match-beginning 0) (match-end 0)))
(safe (copy-sequence "SREF")))
(add-text-properties 0 3 (list 'sref sref) safe)
(setcdr e (replace-match safe t t (cdr e)))))
(while (string-match re string)
(setq rpl (format (concat (substring (match-string 0 string) 0 -1) "s")
(cdr e)))
(setq string (replace-match rpl t t string))))
(while (setq pchg (next-property-change pchg string))
(let ((sref (get-text-property pchg 'sref string)))
(when (and sref (string-match "SREF" string pchg))
(setq string (replace-match sref t t string)))))
string))