I'm having to replace the configurations of keymaps in my use-package with define-key expressions and thought I'd use that to get more proficient with using regexp-replace. The situation is this:
(:map cdlatex-mode-map
("<kp-right>" . cdlatex-tab)
("\"" . cdlatex-math-modify)
("§" . cdlatex-math-modify)
("Ђ" . cdlatex-text)
("њ" . cdlatex-mathit)
("M-ℕ" . change-mathvar)
("C-M-ℕ" . change-mathvar-withinstring)
("M-]" . remove-environment)
("M-t" . cdlatex-item)
)
Here, I would like to rewrite each tuple like
("M-t" . cdlatex-item)
Into a string like
(define-key cdlatex-mode-map (kbd "M-t") #'cdlatex-item)
And do that not just for cdlatex-mode-map but for other mode-map configurations as well. I thought the first step would be to find a regexp that could match the :map code block above, and I did:
(:map[ ]+?\([^ ]*\).*
\( *("\(.*\)" *\. *\(.*\))
\)* *)
This matches the blocks. But I'm confused about how I can put the first regexp-subexpression, corresponding in the above block to cdlatex-mode-map, and the third and fourth, corresponding to the shortcut and command, into something like
(define-key \1 (kbd "\3") #'\4)
But this only works for the last item in the block. Is there a way I can make such a nested replacement work?
(:map...)sexp. Please clarify.