[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Document that failed search/match preserves match data

From: Stephen J. Turnbull
Subject: Document that failed search/match preserves match data
Date: Fri, 09 May 2003 23:14:05 +0900
User-agent: Gnus/5.090016 (Oort Gnus v0.16) XEmacs/21.5 (cabbage)

Currently in both XEmacs and Emacs a failed search will preserve the
match data from the last successful search (this is true for XEmacs
from regression testing and verifying the code, and if I interpreted a
communication with Stefan Monnier correctly, it is true for Emacs).

However, until now the documentation for both Emacsen strongly implied
(to my mind) that any call to a search or match function would clobber
the match data.  As an experiment, in XEmacs I changed it to clear the
match data even on failure, and (as you would expect) got a bunch of
bug reports.  This led me to some elegant examples (the function
`w3-configuration-data' in "w3-cfg" is a good one, I think) which
depend on match failure preserving previous match data in an essential
way.  (Of course you could work around it but it would be real ugly.)

I propose that the docstrings and Info documentation for both Emacsen
be amended to reflect the (common) behavior of the implementations,
since it seems to be useful.  That is, we state that

"On success, a search or match sets the match data for the whole
expression and any matched subexpressions.  If the search or match
fails, the match data from the most recent successful search will be
preserved.  (You should not depend on the match data being preserved
in case of an error in the search function.)"[1]

[1]  In the case of XEmacs, I'm pretty sure that even on errors the
previous match data is preserved, but of course that's a little harder
to be sure of than with normal termination.

Institute of Policy and Planning Sciences     http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]