diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2019-03-03 23:48:07 +0100 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2019-03-10 18:00:36 +0100 |
commit | 9cf2040313bbd5ef16af59768432f87df8d10585 (patch) | |
tree | 124855880e440f6987fc23bf4d2af906d15bbd00 | |
parent | ccfea3d8e58402d9c10197d7eb9b489dc139b561 (diff) | |
download | org-mode-9cf2040313bbd5ef16af59768432f87df8d10585.tar.gz |
Move `org-replace-escapes' into "org-macs.el"
* lisp/org.el (org-replace-escapes): Move function...
* lisp/org-macs.el: ...there.
-rw-r--r-- | lisp/org-macs.el | 27 | ||||
-rw-r--r-- | lisp/org.el | 27 |
2 files changed, 27 insertions, 27 deletions
diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 7978ca6..e23a0fe 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -1011,6 +1011,33 @@ as-is if removal failed." (or (cdr entry) "") template t t))) template)) +(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 "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)) + ;;; Text properties diff --git a/lisp/org.el b/lisp/org.el index 2365975..e1a7ea2 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19054,33 +19054,6 @@ Returns the number of empty lines passed." (goto-char (min (point) pos)) (count-lines (point) pos))) -(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 "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)) - ;;; TODO: Only called once, from ox-odt which should probably use ;;; org-export-inline-image-p or something. (defun org-file-image-p (file) |