From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#31586: 27.0.50; `frame-title-format' doesn't save match data Date: Sun, 27 May 2018 15:32:44 -0400 Message-ID: References: <838t8583yz.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1527449474 8108 195.159.176.226 (27 May 2018 19:31:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 27 May 2018 19:31:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: p.stephani2@gmail.com, 31586@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun May 27 21:31:10 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fN1Nl-0001yB-CJ for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 May 2018 21:31:09 +0200 Original-Received: from localhost ([::1]:53008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fN1Pq-0001re-Sp for geb-bug-gnu-emacs@m.gmane.org; Sun, 27 May 2018 15:33:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fN1Pe-0001rI-Ht for bug-gnu-emacs@gnu.org; Sun, 27 May 2018 15:33:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fN1Pa-0000kg-EW for bug-gnu-emacs@gnu.org; Sun, 27 May 2018 15:33:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43374) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fN1Pa-0000kU-AB for bug-gnu-emacs@gnu.org; Sun, 27 May 2018 15:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fN1Pa-0003Vc-0t for bug-gnu-emacs@gnu.org; Sun, 27 May 2018 15:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 27 May 2018 19:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 31586 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 31586-submit@debbugs.gnu.org id=B31586.152744956913469 (code B ref 31586); Sun, 27 May 2018 19:33:01 +0000 Original-Received: (at 31586) by debbugs.gnu.org; 27 May 2018 19:32:49 +0000 Original-Received: from localhost ([127.0.0.1]:51271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fN1PM-0003VB-QD for submit@debbugs.gnu.org; Sun, 27 May 2018 15:32:49 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:38151) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fN1PK-0003V3-Uf for 31586@debbugs.gnu.org; Sun, 27 May 2018 15:32:47 -0400 Original-Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w4RJX66w019816; Sun, 27 May 2018 15:33:07 -0400 Original-Received: by ceviche.home (Postfix, from userid 20848) id 0840A6612B; Sun, 27 May 2018 15:32:45 -0400 (EDT) In-Reply-To: <838t8583yz.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 27 May 2018 19:20:52 +0300") X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 2 Rules triggered EDT_SA_DN_PASS=0, RV6294=0 X-NAI-Spam-Version: 2.3.0.9418 : core <6294> : inlines <6661> : streams <1787976> : uri <2648210> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:146612 Archived-At: >> FWIW, I think this qualifies as a bug in query-replace: Elisp code >> should never presume that the match-data is preserved across something >> like sit-for, read-char, or any other function which can run process >> filters, redisplay, timers, or contains a yield-point. > Is this practical? We have any number of hooks, advices, and other > means to make arbitrary Lisp run almost off any function call. Given > that redisplay can be entered by such Lisp by calling 'redisplay' or > 'message' or one of the other functions you mentioned, your suggestion > would mean we need to save-match-data around any call to any > function. That would make our code very cluttered, indeed. That's how we've lived so far, except that the need for save-match-data is not around "any" call, but only around "any call except for <...>" where <...> is the set of "primitive enough" functions. The main problem so far is that this set is not formally defined (and also that the byte-compiler doesn't warn you if you use a function outside of this set without wrapping with save-match-data), but other than that it works well in practice, because in 99% there is *very* little code executed between a regexp match and the use of the match-data. [ Side question: while `message` does cause a form of redisplay, IIUC it doesn't cause a *real* redisplay in the sense that it won't recompute mode-lines, frame-titles, nor will it run jit-lock, IOW it won't run elisp code. ] > My POV is that using :eval is intrinsically tricky, and whoever does > that should take the necessary precautions. I think it would be preferable to save the match-data around the whole redisplay than have each :eval do it. More to the point: AFAICT in the problem at hand, between the regexp-match and the call to buffer-substring-no-properties, process filters can be executed, so it's not just the match data which could be changed, but the whole buffer's contents, so save-match-data around the :eval call will just patch over one particular instance of a more general problem, I think. This said, having looked at the code this time, the bug is not quite as clear as I thought: perform-replace does already save&restore the match data, as evidenced by: (setq key (read-event)) ;; Necessary in case something happens during ;; read-event that clobbers the match data. (set-match-data real-match-data) But it does it in a fairly complex way, so the exact problem is hard to pinpoint. If someone can understand what replace-match-data really does, maybe they can figure out the origin of the problem. Stefan