From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: find-file-noselect needs save-match-data Date: Thu, 14 Jun 2007 08:57:40 +0200 Message-ID: <4670E6E4.3010906@gmx.at> References: <46665AD7.7040706@gmx.at> <87k5ueq23m.fsf@kfs-lx.testafd.dk> <87myz8c10t.fsf@jurta.org> <18030.3441.204697.244518@rgrjr.dyndns.org> <87zm3515r4.fsf@jurta.org> <85k5u8x2gm.fsf@lola.goethe.zz> <87r6og6czf.fsf@catnip.gol.com> <85bqfkx0i5.fsf@lola.goethe.zz> <85tztbvh4d.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1181804562 8771 80.91.229.12 (14 Jun 2007 07:02:42 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 14 Jun 2007 07:02:42 +0000 (UTC) Cc: rms@gnu.org, schwab@suse.de, emacs-devel@gnu.org, juri@jurta.org, miles@gnu.org, miles.bader@necel.com To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 14 09:02:39 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 1HyjLr-0002l3-1n for ged-emacs-devel@m.gmane.org; Thu, 14 Jun 2007 09:02:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HyjLq-0000Xp-IX for ged-emacs-devel@m.gmane.org; Thu, 14 Jun 2007 03:02:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HyjL0-0000F5-3w for emacs-devel@gnu.org; Thu, 14 Jun 2007 03:01:46 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HyjKy-0000Ee-VU for emacs-devel@gnu.org; Thu, 14 Jun 2007 03:01:45 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HyjKy-0000EJ-R0 for emacs-devel@gnu.org; Thu, 14 Jun 2007 03:01:44 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1HyjKx-0002JO-2L for emacs-devel@gnu.org; Thu, 14 Jun 2007 03:01:43 -0400 Original-Received: (qmail invoked by alias); 14 Jun 2007 07:01:42 -0000 Original-Received: from N870P005.adsl.highway.telekom.at (EHLO [62.47.52.165]) [62.47.52.165] by mail.gmx.net (mp031) with SMTP; 14 Jun 2007 09:01:42 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1+XNqQjLTqXkkATrHvRgsi6QEslD8k3mZqHm3YKj9 dvqkIQ81lCSnGo User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: de-DE, de, en-us, en In-Reply-To: X-Y-GMX-Trusted: 0 X-detected-kernel: 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:72833 Archived-At: > AFAIK save-match-data is only needed in 2 circumstances: > > 1 - when implementing a function that needs to leave the > match-data unaffected. This is typically only the case for functions > that are placed on hooks. In most cases such save-match-data are > necessary because the function you define does touch the match-data > (otherwise you wouldn't have used save-match-data) and the function that > runs the hook will sooner or later need the match-data to > stay unaffected. Exact. > 2 - around code that needs to be run after string-match but before match-end I fail to understand this. > and of which we do not know that it leaves the match-data unaffected. > This may be unnecessary because the code may in fact preserve the > match-data even though you don't know it. > > So although number 1 may be an unnecessary use of save-match-data, I find > it's usually useful/necessary. Number 2 OTOH can often turn out to be > unnecessary. Luckily number 2 is very rarely needed because in most cases > it's easier to restructure your code such that save-match-data is not needed > any more. Saving match-data is needed if the index for accessing match-data is known only after performing a second match operation like in (let (index) (when (re-search-forward ...) (save-match-data (if (string-match ...) (setq index ...))) (match-beginning index))) I think we agree that this is rarely used. > So I don't see current usage as problematic w.r.t efficiency. The info.el examples in my earlier mail seem to contradict this. > The only real problem with it is that people tend to not know/understand it > and are thus tempted to complain that most functions need to be wrapped in > save-match-data, which then leads to long discussions such as this one. > Maybe we should make the convention more prominent by adding it to the > docstring of save-match-data? We probably should remove bad uses of `save-match-data' from Emacs code in the first place.