* bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data
@ 2009-02-27 15:42 tcr
2009-02-28 4:50 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: tcr @ 2009-02-27 15:42 UTC (permalink / raw)
To: emacs-pretest-bug
`beginning-of-defun' (and `syntax-ppss' as it invokes the former by
the variable `syntax-begin-function') does not save match data.
The issue also applies to 23.0.60.1, and 22.1.1.
Test case:
(let ((buffer-sexpr "(defun *HERE*"))
(with-temp-buffer
(lisp-mode)
(insert buffer-sexpr)
(search-backward "*HERE*")
(let ((old (match-data)))
(progn (beginning-of-defun))
(equal old (match-data)))))
==> nil
There are several possible options now:
(i) `beginning-of-defun' is allowed to not save match data. If so,
please document it.
(ii) If (i) is true, still consider whether `syntax-ppss' is allowed
to not save match data, too. Perhaps it should rather funcall
`syntax-begin-function' wrapped in a `save-match-data'.
Whatever the decision, please document it.
Thank you!
In GNU Emacs 23.0.91.1 (i686-pc-linux-gnu, GTK+ Version 2.12.9)
of 2009-02-27 on thaleron
Windowing system distributor `The X.Org Foundation', version 11.0.10400090
configured using `configure '--prefix=/home/tcr/software/emacs-cvs' '--with-x-toolkit=gtk' '--without-gpm' '--with-x' '--without-xpm' '--enable-asserts' 'CFLAGS=-g''
Important settings:
value of $LC_ALL: nil
value of $LC_COLLATE: nil
value of $LC_CTYPE: nil
value of $LC_MESSAGES: nil
value of $LC_MONETARY: nil
value of $LC_NUMERIC: nil
value of $LC_TIME: nil
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: nil
locale-coding-system: utf-8-unix
default-enable-multibyte-characters: t
Major mode: Lisp Interaction
Minor modes in effect:
eldoc-mode: t
tooltip-mode: t
mouse-wheel-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
global-auto-composition-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
column-number-mode: t
line-number-mode: t
transient-mark-mode: t
Recent input:
<down> <return> C-x b * <backspace> <return> C-y C-M-x
C-j <up> <up> <up> <right> <right> <right> <right>
<right> <right> <right> M-d s a v e - m a t c h - d
a t a C-e <down> C-j <up> <up> <right> <right> <right>
<right> <right> <right> <right> <up> C-M-k r <backspace>
p r o g n M-x r e p o r t - e m a c s - b u g <ret
urn>
Recent messages:
Loading /home/tcr/.emacs.d/config/lisp-config.el (source)...done
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set
nil
--
Diese Nachricht wurde auf Viren und andere gefaerliche Inhalte untersucht
und ist - aktuelle Virenscanner vorausgesetzt - sauber.
Freebits E-Mail Virus Scanner
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data
2009-02-27 15:42 bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data tcr
@ 2009-02-28 4:50 ` Stefan Monnier
2009-02-28 16:56 ` Tobias C. Rittweiler
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2009-02-28 4:50 UTC (permalink / raw)
To: tcr; +Cc: 2499
> (i) `beginning-of-defun' is allowed to not save match data. If so,
> please document it.
99.9% of the functions are allowed to not save match data. We do not
bother to document it. We should document the functions that are not
allowed to do it, OTOH.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data
2009-02-28 4:50 ` Stefan Monnier
@ 2009-02-28 16:56 ` Tobias C. Rittweiler
2009-02-28 22:09 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Tobias C. Rittweiler @ 2009-02-28 16:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: 2499
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > (i) `beginning-of-defun' is allowed to not save match data. If so,
> > please document it.
>
> 99.9% of the functions are allowed to not save match data.
Oh, I didn't know that! I thought the policy was the other way
around. (Perhaps 34.6, The Match Data, should make this policy more
explicit. If so, and you say so, I'll prepare a patch.)
> We do not bother to document it. We should document the functions
> that are not allowed to do it, OTOH.
I think it's still worth to think about making `syntax-ppss' saving the
match data as this function may easily be implicitly invoked by
something deep down.
Thank you for your prompt reply!,
-T.
--
Diese Nachricht wurde auf Viren und andere gefaerliche Inhalte untersucht
und ist - aktuelle Virenscanner vorausgesetzt - sauber.
Freebits E-Mail Virus Scanner
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data
2009-02-28 16:56 ` Tobias C. Rittweiler
@ 2009-02-28 22:09 ` Stefan Monnier
2009-03-03 20:50 ` Tobias C. Rittweiler
0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2009-02-28 22:09 UTC (permalink / raw)
To: Tobias C. Rittweiler; +Cc: 2499
>> > (i) `beginning-of-defun' is allowed to not save match data. If so,
>> > please document it.
>> 99.9% of the functions are allowed to not save match data.
> Oh, I didn't know that! I thought the policy was the other way
> around. (Perhaps 34.6, The Match Data, should make this policy more
> explicit. If so, and you say so, I'll prepare a patch.)
Patch welcome.
>> We do not bother to document it. We should document the functions
>> that are not allowed to do it, OTOH.
> I think it's still worth to think about making `syntax-ppss' saving the
> match data as this function may easily be implicitly invoked by
> something deep down.
Basically any function that does a non-trivial amount of work should be
expected to affect the match-data. I.e. it's the responsability of the
match-data user to make sure she reads the match-data soon after the
regexp match took place, rather than responsability of all other
functions to preserve the match-data.
Stefan
^ permalink raw reply [flat|nested] 6+ messages in thread
* bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data
2009-02-28 22:09 ` Stefan Monnier
@ 2009-03-03 20:50 ` Tobias C. Rittweiler
2011-07-03 18:45 ` Lars Magne Ingebrigtsen
0 siblings, 1 reply; 6+ messages in thread
From: Tobias C. Rittweiler @ 2009-03-03 20:50 UTC (permalink / raw)
To: bug-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 476 bytes --]
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> > > > (i) `beginning-of-defun' is allowed to not save match data. If so,
> > > > please document it.
> > >
> > > 99.9% of the functions are allowed to not save match data.
> >
> > Oh, I didn't know that! I thought the policy was the other way
> > around. (Perhaps 34.6, The Match Data, should make this policy more
> > explicit. If so, and you say so, I'll prepare a patch.)
>
> Patch welcome.
Attached.
-T.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: match-data-lispref.diff --]
[-- Type: text/x-diff, Size: 925 bytes --]
Index: doc/lispref/searching.texi
===================================================================
RCS file: /sources/emacs/emacs/doc/lispref/searching.texi,v
retrieving revision 1.11
diff -u -r1.11 searching.texi
--- doc/lispref/searching.texi 8 Jan 2009 05:29:01 -0000 1.11
+++ doc/lispref/searching.texi 3 Mar 2009 20:48:30 -0000
@@ -1204,6 +1204,12 @@
can't avoid another intervening search, you must save and restore the
match data around it, to prevent it from being overwritten.
+ 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 implictly in the background (@pxref{Timers}, and
+@ref{Idle Timers}) should likely save and restore the match data
+explicitly.
+
@menu
* Replacing Match:: Replacing a substring that was matched.
* Simple Match Data:: Accessing single items of match data,
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-07-03 18:45 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-27 15:42 bug#2499: 23.0.91; syntax-ppss / beginning-of-defun not saving match data tcr
2009-02-28 4:50 ` Stefan Monnier
2009-02-28 16:56 ` Tobias C. Rittweiler
2009-02-28 22:09 ` Stefan Monnier
2009-03-03 20:50 ` Tobias C. Rittweiler
2011-07-03 18:45 ` Lars Magne Ingebrigtsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).