Skip to content

Comment on Evolution of Emacs Lisp [pdf]parent

Comments

Emacs has dedicated functions that let you handle such cases more conveniently. For example, in your case, the function regexp-quote may be useful:

    (regexp-quote "\\") ⇒ "\\\\"
In addition, structured data are often better represented as trees. In Emacs, you can use the function "rx" to translate Lisp forms from a dedicated tree-based mini language into regexp strings. The primary advantage is that you can more readily reflect the logic of the intended regular expression in this way.

For example:

    (rx (or "a" "b")) ⇒ "[ab]"
and:
    (rx (and (or "a" "b" "test") "c")) ⇒ "\\(?:test\\|[ab]\\)c"

It never ceases to amaze me how much there is to emacs and emacs-lisp. After 15 years of daily use I still discover gems like this

Thankyou

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.