From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Should save-match-data bind inhibit-changing-match-data to nil? Date: Fri, 30 Nov 2007 00:21:52 +0100 Message-ID: <85fxyo3aen.fsf@lola.goethe.zz> References: <85ir3l5nso.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1196378527 32209 80.91.229.12 (29 Nov 2007 23:22:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2007 23:22:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Nov 30 00:22:15 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ixshj-0005Jr-GY for ged-emacs-devel@m.gmane.org; Fri, 30 Nov 2007 00:21:59 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxshT-0001Iz-KG for ged-emacs-devel@m.gmane.org; Thu, 29 Nov 2007 18:21:43 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IxshQ-0001Iq-CV for emacs-devel@gnu.org; Thu, 29 Nov 2007 18:21:40 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IxshP-0001Hw-1U for emacs-devel@gnu.org; Thu, 29 Nov 2007 18:21:40 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IxshO-0001Hn-QD for emacs-devel@gnu.org; Thu, 29 Nov 2007 18:21:38 -0500 Original-Received: from fencepost.gnu.org ([140.186.70.10]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IxshO-0004Ux-Nd for emacs-devel@gnu.org; Thu, 29 Nov 2007 18:21:38 -0500 Original-Received: from localhost ([127.0.0.1] helo=lola.goethe.zz) by fencepost.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IxshI-0005Yk-Js; Thu, 29 Nov 2007 18:21:32 -0500 Original-Received: by lola.goethe.zz (Postfix, from userid 1002) id A8A0C1C4D3AA; Fri, 30 Nov 2007 00:21:52 +0100 (CET) In-Reply-To: (Richard Stallman's message of "Thu, 29 Nov 2007 17:31:51 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:84325 Archived-At: Richard Stallman writes: > Hi, I was thinking about using inhibit-changing-match-data in replace.el > for a number of things. Now the tricky part is what to do with > operations that can lead to the user switching windows and similar? It > is an obvious fix to wrap them in save-match-data. But one would need > to set inhibit-changing-match-data to t at the same time. Uh, to nil I mean. > Could you give an example of the sort of scenario are you concerned with here? > Which operations are these? (read-string "something") > Is this something that save-match-data could/should do in general? > > Sorry, I don't follow. What is your proposal? Something like the following sketch (the only change to the original version is let-binding inhibit-changing-match-data to nil around the body): (defmacro save-match-data (&rest body) "Execute the BODY forms, restoring the global value of the match data. The value returned is the value of the last form in BODY." ;; It is better not to use backquote here, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. (declare (indent 0) (debug t)) (list 'let '((save-match-data-internal (match-data)) inhibit-changing-match-data) (list 'unwind-protect (cons 'progn body) ;; It is safe to free (evaporate) markers immediately here, ;; as Lisp programs should not copy from save-match-data-internal. '(set-match-data save-match-data-internal 'evaporate)))) The idea is that if some code does (let (inhibit-changing-match-data) (while ... (save-match-data (call something else)) ... )) that the (call something else) not only is free to change the match data (and it will get restored afterwards), but actually has a chance of changing the match data in the first place. -- David Kastrup, Kriemhildstr. 15, 44793 Bochum