From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Mattias_Engdeg=C3=A5rd?= Newsgroups: gmane.emacs.devel Subject: Re: modern regexes in emacs Date: Mon, 18 Feb 2019 09:55:39 +0100 Message-ID: <125F20FA-9824-49D7-AC37-BEDC121B6850@acm.org> References: <20180616123704.7123f6d7@jabberwock.cb.piermont.com> <87po0qs6re.fsf@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="71214"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 18 10:03:25 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gvepg-000IQ7-Vj for ged-emacs-devel@m.gmane.org; Mon, 18 Feb 2019 10:03:25 +0100 Original-Received: from localhost ([127.0.0.1]:54808 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvepf-00035D-TY for ged-emacs-devel@m.gmane.org; Mon, 18 Feb 2019 04:03:23 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:53827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gvenz-0002cj-8F for emacs-devel@gnu.org; Mon, 18 Feb 2019 04:01:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gveiT-0003eb-SI for emacs-devel@gnu.org; Mon, 18 Feb 2019 03:55:58 -0500 Original-Received: from mail171c50.megamailservers.eu ([91.136.10.181]:57282 helo=mail92c50.megamailservers.eu) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gveiT-0003Ya-8q for emacs-devel@gnu.org; Mon, 18 Feb 2019 03:55:57 -0500 X-Authenticated-User: mattiase@bredband.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=megamailservers.eu; s=maildub; t=1550480142; bh=EUuwgIamYyVr267h4IsNLSww+D9qYaj541kdRABoAWE=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=QU/tIu9E/Vu8IPTWGaUOLNX6jZmmanCwQfMA6A7p21WEt8mZ06lYcuj/djKpJZ8p0 g8wq+tb/CnWTbDmgLC1vV8Mhh4aLTjWzjm6qLv7hCdRJsYx/s10R4QtX5TxePVO6YV gkw863KJn+e17QUXKJN0gmqMmsYejxE2AtiFsJyY= Feedback-ID: mattiase@acm.or Original-Received: from [192.168.0.4] (c83-251-8-17.bredband.comhem.se [83.251.8.17]) (authenticated bits=0) by mail92c50.megamailservers.eu (8.14.9/8.13.1) with ESMTP id x1I8tdXa001891; Mon, 18 Feb 2019 08:55:42 +0000 In-Reply-To: X-Mailer: Apple Mail (2.3445.102.3) X-CTCH-RefID: str=0001.0A0B0210.5C6A730E.0043, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0 X-CTCH-VOD: Unknown X-CTCH-Spam: Unknown X-CTCH-Score: 0.000 X-CTCH-Flags: 0 X-CTCH-ScoreCust: 0.000 X-CSC: 0 X-CHA: v=2.3 cv=EN4oLWRC c=1 sm=1 tr=0 a=NAHmi3I8mP0S/Y8gRKeQyA==:117 a=NAHmi3I8mP0S/Y8gRKeQyA==:17 a=kj9zAlcOel0A:10 a=iRZporoAAAAA:8 a=i7cvIS8xKZBvX_rt0goA:9 a=CjuIK1q_8ugA:10 a=NOBgFS-JBQ2l-kSd6-zu:22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 91.136.10.181 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:233441 Archived-At: 17 feb. 2019 kl. 21.47 skrev Stefan Monnier : >=20 > 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.