Skip to content

Instantly share code, notes, and snippets.

@0branch
Created September 24, 2011 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0branch/1239515 to your computer and use it in GitHub Desktop.
Save 0branch/1239515 to your computer and use it in GitHub Desktop.
Emacs: string interpolation with property lists
(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