From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Re: Make regexp handling more regular Date: Wed, 02 Dec 2020 22:16:45 -0600 Message-ID: <87y2ifsevm.fsf@alphapapa.net> References: <87lfeg60iy.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26670"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 03 05:17:28 2020 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kkg3c-0006qC-Se for ged-emacs-devel@m.gmane-mx.org; Thu, 03 Dec 2020 05:17:28 +0100 Original-Received: from localhost ([::1]:49558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kkg3b-0003pG-TR for ged-emacs-devel@m.gmane-mx.org; Wed, 02 Dec 2020 23:17:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkg38-0003MP-2z for emacs-devel@gnu.org; Wed, 02 Dec 2020 23:16:58 -0500 Original-Received: from static.214.254.202.116.clients.your-server.de ([116.202.254.214]:40676 helo=ciao.gmane.io) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kkg36-000058-Hp for emacs-devel@gnu.org; Wed, 02 Dec 2020 23:16:57 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1kkg31-00063b-QN for emacs-devel@gnu.org; Thu, 03 Dec 2020 05:16:51 +0100 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:260197 Archived-At: Lars Ingebrigtsen writes: > I constant source of confusion and subtle bugs is the way Emacs does > regexp match handling: The way `string-match' (and the rest) sets a > global state, and you sort of have to catch them "early" is often a > challenge for new users. > > Experienced Emacs Lisp programmers know to be safe and will say: > > (when (string-match "[a-z]" string) > (let ((match (match-string 0 string))) > (foo) > (bar match))) > > while people new to Emacs Lisp will expect this to work: > > (when (string-match "[a-z]" string) > (foo) > (bar (match-string - string))) > > And sometimes it does, and sometimes it doesn't, depending on whether > `foo' also messes with the match data. > > So my idle shower thought for the day is: Is there any reasonable path > forward that the Emacs Lisp language could take here? It's funny that you should post this today, Lars, because I just encountered this very problem while using code from your format-spec function in combination with code from your shr-insert-document function (the latter of which changed the match data, making the former fail inexplicably...until I figured it out). Not that I'm blaming you, of course--it's me who's using your code in unintended ways. :) Anyway, I'd be very happy if Emacs had "safer" matching functions like this. And I like the idea of prefixing them with "rx-", as was suggested. Thanks for your work on Emacs!