Add helper function to replace variables in strings

Only a thin but hopefully helpful wrapper around `replace-regexp-in-string`.
master
Daniel Borchmann 4 months ago
parent 1ac4e44f86
commit e2181fa87a
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625
  1. 3
      init.el
  2. 13
      site-lisp/db-utils.el

@ -628,7 +628,8 @@
keyboard-quit-context+
db/convert-lf-to-crlf-in-buffer
db/convert-crlf-to-lf-in-buffer
db/sync-magit-repos-from-projectile))
db/sync-magit-repos-from-projectile
db/replace-variables-in-string))
(use-package db-hydras
:commands (hydra-toggle/body

@ -464,6 +464,19 @@ Does not replace CRLF with CRCRLF, and so on."
(shr-render-buffer (find-file-noselect file))
(delete-trailing-whitespace))
(defun db/replace-variables-in-string (string var-map)
"Replace variables in STRING as per VAR-MAP.
VAR-MAP is an alist mapping variable names (strings or symbols)
to values. Variables are strings of alphabetic characters (no
numbers allowed)."
(replace-regexp-in-string "[[:alpha:]]+"
#'(lambda (var)
(format "%s" (alist-get var var-map
var ; default value
nil ; not relevant REMOVE parameter
#'string=)))
string))
;;; Base45 Decoding

Loading…
Cancel
Save