[emacs-berlin] A riddle to be solved with Emacs

Christian Tietze me at christiantietze.de
Wed Jun 9 07:51:09 UTC 2021

I didn't know that you could call elisp functions in interactive
replace-regex! That's cool, but for whatever reason, the downcase
function didn't actually downcase anything in my experiments. It didn't
fail either, just kept the upcase.

I had some luck writing non-interactive regexp replacements, though,
after reading other have experienced similar trouble[1]. Formatted into
multiple functions for readability in mail:

(defun sanitize-label (label)
  (replace-regexp-in-string "[ ,.:]+" "-" (downcase label)))

(defun assemble-json (label)
  (concat "{ value: \""
          (sanitize-label label))
          "\", label: \""

(while (re-search-forward "^[ ]*\"\\([^\"]+\\)\",?[ ]*" nil t)
  (replace-match (assemble-json (match-string 1)) t nil)) 

[1]: https://stackoverflow.com/a/9858515/1460929

Sent from Bielefeld, Germany <3

More information about the emacs-berlin mailing list