* Should save-match-data bind inhibit-changing-match-data to nil?
@ 2007-11-29 10:49 David Kastrup
2007-11-29 22:31 ` Richard Stallman
0 siblings, 1 reply; 4+ messages in thread
From: David Kastrup @ 2007-11-29 10:49 UTC (permalink / raw)
To: emacs-devel
Hi, I was thinking about using inhibit-changing-match-data in replace.el
for a number of things. Now the tricky part is what to do with
operations that can lead to the user switching windows and similar? It
is an obvious fix to wrap them in save-match-data. But one would need
to set inhibit-changing-match-data to t at the same time.
Is this something that save-match-data could/should do in general?
After all, there is not much of a point to save the match data (except
that it gets moved into markers instead of integers, which _is_ a
difference when the user is editing) when it can't change, anyway?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Should save-match-data bind inhibit-changing-match-data to nil?
2007-11-29 10:49 Should save-match-data bind inhibit-changing-match-data to nil? David Kastrup
@ 2007-11-29 22:31 ` Richard Stallman
2007-11-29 23:21 ` David Kastrup
0 siblings, 1 reply; 4+ messages in thread
From: Richard Stallman @ 2007-11-29 22:31 UTC (permalink / raw)
To: David Kastrup; +Cc: emacs-devel
Hi, I was thinking about using inhibit-changing-match-data in replace.el
for a number of things. Now the tricky part is what to do with
operations that can lead to the user switching windows and similar? It
is an obvious fix to wrap them in save-match-data. But one would need
to set inhibit-changing-match-data to t at the same time.
Could you give an example of the sort of scenario are you concerned with here?
Which operations are these?
Is this something that save-match-data could/should do in general?
Sorry, I don't follow. What is your proposal?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Should save-match-data bind inhibit-changing-match-data to nil?
2007-11-29 22:31 ` Richard Stallman
@ 2007-11-29 23:21 ` David Kastrup
2007-11-30 23:36 ` Richard Stallman
0 siblings, 1 reply; 4+ messages in thread
From: David Kastrup @ 2007-11-29 23:21 UTC (permalink / raw)
To: rms; +Cc: emacs-devel
Richard Stallman <rms@gnu.org> writes:
> Hi, I was thinking about using inhibit-changing-match-data in replace.el
> for a number of things. Now the tricky part is what to do with
> operations that can lead to the user switching windows and similar? It
> is an obvious fix to wrap them in save-match-data. But one would need
> to set inhibit-changing-match-data to t at the same time.
Uh, to nil I mean.
> Could you give an example of the sort of scenario are you concerned with here?
> Which operations are these?
(read-string "something")
> Is this something that save-match-data could/should do in general?
>
> Sorry, I don't follow. What is your proposal?
Something like the following sketch (the only change to the original
version is let-binding inhibit-changing-match-data to nil around the
body):
(defmacro save-match-data (&rest body)
"Execute the BODY forms, restoring the global value of the match data.
The value returned is the value of the last form in BODY."
;; It is better not to use backquote here,
;; because that makes a bootstrapping problem
;; if you need to recompile all the Lisp files using interpreted code.
(declare (indent 0) (debug t))
(list 'let
'((save-match-data-internal (match-data)) inhibit-changing-match-data)
(list 'unwind-protect
(cons 'progn body)
;; It is safe to free (evaporate) markers immediately here,
;; as Lisp programs should not copy from save-match-data-internal.
'(set-match-data save-match-data-internal 'evaporate))))
The idea is that if some code does
(let (inhibit-changing-match-data)
(while ...
(save-match-data (call something else))
...
))
that the (call something else) not only is free to change the match data
(and it will get restored afterwards), but actually has a chance of
changing the match data in the first place.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Should save-match-data bind inhibit-changing-match-data to nil?
2007-11-29 23:21 ` David Kastrup
@ 2007-11-30 23:36 ` Richard Stallman
0 siblings, 0 replies; 4+ messages in thread
From: Richard Stallman @ 2007-11-30 23:36 UTC (permalink / raw)
To: David Kastrup; +Cc: emacs-devel
The idea of `inhibit-changing-match-data' is that you use it around
small pieces of code. (We should make the documentation say that
clearly.) So there is no need for anything to bind it helpfully to
nil for you.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-30 23:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-29 10:49 Should save-match-data bind inhibit-changing-match-data to nil? David Kastrup
2007-11-29 22:31 ` Richard Stallman
2007-11-29 23:21 ` David Kastrup
2007-11-30 23:36 ` Richard Stallman
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).