From mboxrd@z Thu Jan 1 00:00:00 1970 Path: quimby.gnus.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: save-match-data woes Date: Fri, 22 Feb 2002 11:43:03 -0500 Message-ID: <200202221643.g1MGh3a30474@rum.cs.yale.edu> References: <20020221115255.A397.LEKTU@terra.es> NNTP-Posting-Host: quimby2.netfonds.no Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: quimby2.netfonds.no 1014396424 5952 195.204.10.66 (22 Feb 2002 16:47:04 GMT) X-Complaints-To: usenet@quimby2.netfonds.no NNTP-Posting-Date: 22 Feb 2002 16:47:04 GMT Cc: emacs-devel@gnu.org Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby2.netfonds.no with esmtp (Exim 3.12 #1 (Debian)) id 16eIqd-0001Xu-00 for ; Fri, 22 Feb 2002 17:47:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16eIp3-000204-00; Fri, 22 Feb 2002 11:45:25 -0500 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16eImp-0001rp-00 for ; Fri, 22 Feb 2002 11:43:07 -0500 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.11.6/8.11.6) id g1MGh3a30474; Fri, 22 Feb 2002 11:43:03 -0500 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Juanma Barranquero Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.5 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: quimby.gnus.org gmane.emacs.devel:1430 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:1430 > 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