joddie/pcre2el

Add a function for quoting PCRE expressions

Closed this issue · 7 comments

Since pcre2el is my go-to library for handling PCREs in Emacs, it'd be nice to include a mechanism for quoting PCREs. Would you be interested in a PR for such functionality? We have code for this already in ag.el.

Sorry for the delayed response. This sounds useful, but I'm not sure I completely understand what you mean by a mechanism for quoting PCREs -- could you give me a bit more detail? Quoting RE metacharacters, or something else?

Yep, just quoting RE metacharacters. For example, from ".*[]foo+" to "\\.\\*\\[\\]foo\\+".

So, this is basically a one-line function, since it's just a special case of converting to pcre syntax:

(defun rxt-quote-pcre (text)
  (rxt-adt->pcre (rxt-string text)))

(string=
 (rxt-quote-pcre ".*[]foo+")
 "\\.\\*\\[\\]foo\\+") ;; => t

I guess it should probably have an interactive spec & add the result to the kill-ring, too. WDYT?

I'm impressed it's just one line! :) I'm interested in using it for calling external tools that expect PCRE patterns, so adding the result to the kill-ring isn't useful for me. Otherwise, looks great.

Would you like me to send a PR for this?

Would you mind? I'm sorry to have let it drop, just swamped with other work right now.

Should now be fixed in master. Sorry for the long delay!