Created
September 24, 2011 16:29
-
-
Save 0branch/1239515 to your computer and use it in GitHub Desktop.
Emacs: string interpolation with property lists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar interpolate-capture "%{\\([^}]+\\)}") | |
(defun interpolate-wrap-key (str sym) | |
(get sym (intern (concat ":" str)))) | |
(defun interpolate- (str pl sym) | |
(if (string-match interpolate-capture str 0) | |
(let* ((key (match-string 1 str)) | |
(new-str (replace-match "%" t nil str)) | |
(new-key (interpolate-wrap-key key sym))) | |
(interpolate- new-str (cons new-key pl) sym)) | |
(cons str (reverse pl)))) | |
(defun interpolate-plist (str sym) | |
(let* ((result (interpolate- str () sym))) | |
(apply 'format result))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment