unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Stefan Monnier" <monnier+gnu/emacs@RUM.cs.yale.edu>
Cc: emacs-devel@gnu.org
Subject: Re: save-match-data woes
Date: Fri, 22 Feb 2002 11:43:03 -0500	[thread overview]
Message-ID: <200202221643.g1MGh3a30474@rum.cs.yale.edu> (raw)
In-Reply-To: 20020221115255.A397.LEKTU@terra.es

> I was trying something with ielm (which I use a lot), and found that:
> 
> ELISP> (setq var "12334")
> "12334"
> ELISP> (string-match "34+" var)
> 3
> ELISP> (match-data)
> (3 5)
> 
> ELISP> (match-data)
> (0 0)
> 
> After digging around I've found that ielm has non-protected calls to
> string-match and looking-for, and is also calling pp-to-string, which
> does not preserve the match data either.
> 
> From a recent change to bibtex.el by Eli I suppose the intent is to make
> functions preserve match data unless their interface specifically says
> they don't.

I think this is a wrong approach.  The match-data need only be saved
in a few particular circumstances and I'd rather handle those cases
in a special way.

For ielm, the problem is that the user might invoke any random command
between two inputs, so fixing M-p and M-n is not enough.  Also fixing
"any random command" is just not possible since that command might not
even be part of Emacs.

I.e. it seems better to fix ielm to save the match data before calling
the pretty printer and to restore it before executing the next command.
See patch below.  Any objection ?


	Stefan


--- ielm.el.~1.22.~	Wed Oct 11 17:26:53 2000
+++ ielm.el	Fri Feb 22 11:40:15 2002
@@ -103,6 +103,9 @@
 (defvar *** nil
   "Third-most-recent value evaluated in IELM.")
 
+(defvar ielm-match-data nil
+  "Match data saved at the end of last command.")
+
 ;;; System variables
 
 (defvar ielm-working-buffer nil
@@ -313,6 +316,7 @@
 		  (let ((*save *)
 			(**save **)
 			(***save ***))
+		    (set-match-data ielm-match-data)
 		    (save-excursion
 		      (set-buffer ielm-working-buffer)
 		      (condition-case err
@@ -330,7 +334,8 @@
 			(error (setq ielm-result (ielm-format-error err))
 			       (setq ielm-error-type "Eval error"))
 			(quit (setq ielm-result "Quit during evaluation")
-			      (setq ielm-error-type "Eval error")))))
+			      (setq ielm-error-type "Eval error"))))
+		    (setq ielm-match-data (match-data)))
 		(setq ielm-error-type "IELM error")
 		(setq ielm-result "More than one sexp in input"))))
 
@@ -451,6 +456,7 @@
   (make-local-variable '**)
   (setq *** nil)
   (make-local-variable '***)
+  (set (make-local-variable 'ielm-match-data) nil)
 
   ;; font-lock support
   (make-local-variable 'font-lock-defaults)


_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/emacs-devel


  parent reply	other threads:[~2002-02-22 16:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-21 11:36 save-match-data woes Juanma Barranquero
2002-02-21 11:54 ` Eli Zaretskii
2002-02-22 16:43 ` Stefan Monnier [this message]
2002-02-23  5:26   ` Richard Stallman
2002-02-25  8:10   ` Juanma Barranquero
2002-02-25  8:21     ` Stefan Monnier
2002-02-25 10:19       ` Juanma Barranquero
2002-02-26 20:15       ` Richard Stallman
2002-02-27 10:00         ` Eli Zaretskii
2002-02-28  4:08           ` Richard Stallman
2002-02-26 20:14     ` 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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=200202221643.g1MGh3a30474@rum.cs.yale.edu \
    --to=monnier+gnu/emacs@rum.cs.yale.edu \
    --cc=emacs-devel@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 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).