Skip to content

Instantly share code, notes, and snippets.

@0branch
Created September 25, 2011 10:48
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/1240468 to your computer and use it in GitHub Desktop.
Save 0branch/1240468 to your computer and use it in GitHub Desktop.
Emacs: string interpolation of bound variables
(defvar interpolate-capture "%{\\([^}]+\\)}")
(defun interpolate- (str pl)
(if (string-match interpolate-capture str 0)
(let* ((key (match-string 1 str))
(new-str (replace-match "%" t nil str))
(new-key (eval (intern key))))
(interpolate- new-str (cons new-key pl)))
(cons str (reverse pl))))
(defun interpolate (str)
(let* ((result (interpolate- str ())))
(apply 'format result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment