that_guu · 2022-09-09 18:20
Im trying to wtite a major mode for emacs. There are some words like(!str, !float...) that I want them highlighted. How do I do it?
For now, I am highlighting each part(! and the keyword) separatelly but that aint an elegant solution
Basically Im asking for the regexp or how to make regexp-opt to do it for me.
eleven_cupfuls · 2022-09-09 22:41
I sometimes find rx helpful for figuring out the syntax:
(require 'rx)
(rx (? ?!) ;; Optional ! character
(or "float" ;; One of "float" or "str"
"str"))
If you eval that you get `"!?\\(?:float\\|str\\)"`. You can also just use it directly when defining things:
(defvar my-keyword-regexp (rx (? ?!) (or "float" "str")))