all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Kastrup <dak@gnu.org>
To: rms@gnu.org
Cc: emacs-devel@gnu.org
Subject: Re: Should save-match-data bind inhibit-changing-match-data to nil?
Date: Fri, 30 Nov 2007 00:21:52 +0100	[thread overview]
Message-ID: <85fxyo3aen.fsf@lola.goethe.zz> (raw)
In-Reply-To: <E1IxrvD-0002Vx-N2@fencepost.gnu.org> (Richard Stallman's message of "Thu, 29 Nov 2007 17:31:51 -0500")

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

  reply	other threads:[~2007-11-29 23:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2007-11-30 23:36     ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85fxyo3aen.fsf@lola.goethe.zz \
    --to=dak@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.