From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Miles Bader Newsgroups: gmane.emacs.devel Subject: Re: find-file-noselect needs save-match-data Date: Thu, 14 Jun 2007 08:39:08 +0900 Message-ID: <87odjjzaoz.fsf@catnip.gol.com> References: <46643852.6070709@gmx.at> <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> Reply-To: Miles Bader NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1181777971 13204 80.91.229.12 (13 Jun 2007 23:39:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 13 Jun 2007 23:39:31 +0000 (UTC) Cc: juri@jurta.org, schwab@suse.de, miles.bader@necel.com, emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 14 01:39:28 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 1HycQu-0000r1-ND for ged-emacs-devel@m.gmane.org; Thu, 14 Jun 2007 01:39:24 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HycQt-0003d6-UO for ged-emacs-devel@m.gmane.org; Wed, 13 Jun 2007 19:39:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HycQq-0003cd-Px for emacs-devel@gnu.org; Wed, 13 Jun 2007 19:39:20 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HycQn-0003c8-79 for emacs-devel@gnu.org; Wed, 13 Jun 2007 19:39:20 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HycQm-0003bz-Uq for emacs-devel@gnu.org; Wed, 13 Jun 2007 19:39:17 -0400 Original-Received: from smtp02.dentaku.gol.com ([203.216.5.72]) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HycQj-0005ea-PY; Wed, 13 Jun 2007 19:39:14 -0400 Original-Received: from 203-216-102-031.dsl.gol.ne.jp ([203.216.102.31] helo=catnip.gol.com) by smtp02.dentaku.gol.com with esmtpa (Dentaku) id 1HycQf-0003c9-La; Thu, 14 Jun 2007 08:39:09 +0900 Original-Received: by catnip.gol.com (Postfix, from userid 1000) id 94D142F41; Thu, 14 Jun 2007 08:39:09 +0900 (JST) System-Type: i686-pc-linux-gnu In-Reply-To: (Richard Stallman's message of "Wed\, 13 Jun 2007 12\:22\:45 -0400") Original-Lines: 46 X-Abuse-Complaints: abuse@gol.com 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:72822 Archived-At: Richard Stallman writes: > Anyway, such a function should likely _return_ the corresponding > match-data (rather than setting a global variable to it), and things > like match-beginning should optionally take an argument for this > particular match-data. > > That is a good idea. If there is no match, it returns nil; if there > is a match, it returns the match data. One alternative to _returning_ the match data would be accepting an argument -- a vector or list -- in which to _place_ the match data (presumably this would be optional, and after the "normal" args). This would have the advantage that it avoids consing the match-data unless the user actually wants it, and yet remains convenient if the user _does_ want it. E.g: (string-match-reentrant REGEXP STRING &optional START MATCH-DATA-VEC) with usage like: (let ((mdata (vector 10))) (if (string-match-reentrant regexp string nil mdata) (message "blargh [%s] [%s]" (aref mdata 1) (aref mdata 2)))) [I'm not sure exactly the format of mdata; there'd have to be some sort of accessor functions] The disadvantage of this is that it would mean allocating the return-vector every time the caller wants match-data, even if there ends up being no match -- though often I guess this overhead could be reduced when a piece of code can use the same vector for many different calls to string-match-reentrant. Which alternative better depends on the expected frequency of various cases, but I think being able to easily avoid the allocation in the extremely common "just match no data" case is valuable, so I'd tend to think my above solution is preferable. -Miles -- `Suppose Korea goes to the World Cup final against Japan and wins,' Moon said. `All the past could be forgiven.' [NYT]