From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexis Newsgroups: gmane.emacs.devel Subject: Re: Possible bug in `match-string` in 24.4.50.18? Date: Mon, 26 May 2014 10:22:58 +1000 Message-ID: <87y4xpfkwt.fsf@gmail.com> References: <87bnumh3zh.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1401063813 23846 80.91.229.3 (26 May 2014 00:23:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 26 May 2014 00:23:33 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 26 02:23:20 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WoihD-0005sT-IU for ged-emacs-devel@m.gmane.org; Mon, 26 May 2014 02:23:19 +0200 Original-Received: from localhost ([::1]:53865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoihD-0000rq-5F for ged-emacs-devel@m.gmane.org; Sun, 25 May 2014 20:23:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53816) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Woih5-0000qj-5O for emacs-devel@gnu.org; Sun, 25 May 2014 20:23:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Woigy-0004YI-IK for emacs-devel@gnu.org; Sun, 25 May 2014 20:23:11 -0400 Original-Received: from mail-pa0-x232.google.com ([2607:f8b0:400e:c03::232]:58722) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Woigy-0004Xv-Bn for emacs-devel@gnu.org; Sun, 25 May 2014 20:23:04 -0400 Original-Received: by mail-pa0-f50.google.com with SMTP id fb1so6734710pad.37 for ; Sun, 25 May 2014 17:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:user-agent:from:to:subject:in-reply-to:date:message-id :mime-version:content-type; bh=HIlq3mOhrXQh5ITLDsz4TaS3H+QO4QTmRyHmZp5nCgw=; b=i3T6dEaVpKrwofThOoo6pd1Y1fZOmMQBboZ1gl2k+ipMu/etzaNWHsZmM8qR4eVaZ0 oGW99oH5Gja49C5RnIwMUTyDLE4ikYXGUH+Q2rq6rKMEtSJBagkP+3tv4rNZqyq8Hzsz rqLwOD8lO27T1Yt+MplwFN39xu7/azCGZyFK22ItDfj6si+inL2FgczIIGjgvGr5WFsi QU0c6+0JogxGpweSacUTTbZhSapnPvgElLj71vhd+ZvRDonqdI1XlSXXHlHuPrs/ot5J OsfEXc3CR2KdbuQDR96QB8ihWms3R62CfHWub7hN1LKw5NUUkHEIEj0xMUaLuxeBlIlC Q/IQ== X-Received: by 10.68.143.65 with SMTP id sc1mr23833750pbb.93.1401063783157; Sun, 25 May 2014 17:23:03 -0700 (PDT) Original-Received: from localhost (ppp118-209-145-187.lns20.mel6.internode.on.net. [118.209.145.187]) by mx.google.com with ESMTPSA id bc4sm15218701pbb.2.2014.05.25.17.23.01 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 25 May 2014 17:23:02 -0700 (PDT) User-agent: mu4e 0.9.9.6pre3; emacs 24.4.50.18 In-reply-to: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:172090 Archived-At: Stefan Monnier writes: >> Take the following code: > >> (setq address "mailto:alexis@example.com") >> (setq re "mailto") >> (string-match re address) >> (match-string 0 address) > > These are 4 separate expressions. How do you run them? i was playing around in *scratch*, to test out various regular expressions on my data, and did a C-x C-e after each line. The above was the result of whittling down the problem to the simplest case i could find that exhibited the problem. There was nothing else in the buffer, and as i noted to Eli, i was indeed running with the -Q option. > My crystal ball says that the problem is the code you unknowingly run > between each one of those expressions. If you run them as a single > expression such as > > (let ((address "mailto:alexis@example.com") > (re "mailto")) > (if (string-match re address) > (match-string 0 address))) > > I'm pretty sure you'll get what you want. It seems you're right. :-) Thank you! i now note that this situation is indeed described in the GNU Emacs Lisp Reference Manual: "Notice that all functions are allowed to overwrite the match data unless they're explicitly documented not to do so. A consequence is that functions that are run implicitly in the background (see Timers, and Idle Timers) should likely save and restore the match data explicitly." .... which i hadn't read because i'd only been reading section "34.6.2 Simple Match Data Access": "Every successful search sets the match data. Therefore, you should query the match data immediately after searching, before calling any other function that might perform another search." .... which is what i thought my code was doing. Since the latter text is from a reference manual which, i suspect, other people will often use by simply reading specific function documentation, could i suggest adding to the latter text something along the lines of: "Note that all functions are allowed to overwrite the match data unless they're explicitly documented not to do so. A consequence is that functions that are run implicitly in the background might overwrite your match data unless you wrap your matching function (e.g. string-match) and match-string together in a let." Thanks again! Alexis.