Add helper function to replace variables in strings
Only a thin but hopefully helpful wrapper around `replace-regexp-in-string`.
This commit is contained in:
parent
1ac4e44f86
commit
e2181fa87a
3
init.el
3
init.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…
Reference in New Issue