[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: modern regexes in emacs
From: |
Mattias Engdegård |
Subject: |
Re: modern regexes in emacs |
Date: |
Mon, 18 Feb 2019 09:55:39 +0100 |
17 feb. 2019 kl. 21.47 skrev Stefan Monnier <address@hidden>:
>
> Other than isearch, most other commands should (ideally) read their
> regexps interactively with `read-regexp`, so it should be easy for
> a third party package to advise `read-regexp` so it accepts the PCRE
> syntax (or the RX syntax, ...) and then converts it to Emacs's
> own syntax. Shouldn't break any package at all.
Like this?
(defun backslash-mod-regexp (re)
"Invert the backslash requirements for |(){} in RE."
(with-temp-buffer
(insert re)
(goto-char (point-min))
(while (re-search-forward
(rx (or (seq "["
(opt "^")
(opt "]")
(* (not (any "]")))
"]")
(seq "\\" (or (group (any "|(){}"))
(seq (any "sScC") anything)
anything))
(group (any "|(){}"))))
nil t)
(cond
((match-beginning 1) (replace-match "\\1"))
((match-beginning 2) (replace-match "\\\\\\&"))))
(buffer-string)))
(defadvice read-regexp (after read-regexp-backslash-mod last activate)
(when (stringp ad-return-value)
(setq ad-return-value (backslash-mod-regexp ad-return-value))))
Of course it won't help with commands that display previously entered regexps,
which users naturally want to see in the form entered, not converted. However,
that should not matter functionally.
- Re: modern regexes in emacs, (continued)
- Re: modern regexes in emacs, Perry E. Metzger, 2019/02/15
- Re: modern regexes in emacs, Clément Pit-Claudel, 2019/02/15
- Re: modern regexes in emacs, Stefan Monnier, 2019/02/15
- Re: modern regexes in emacs, Van L, 2019/02/19
- Re: modern regexes in emacs, Stefan Monnier, 2019/02/17
- Re: modern regexes in emacs, Philippe Vaucher, 2019/02/18
- Re: modern regexes in emacs,
Mattias Engdegård <=