From mboxrd@z Thu Jan 1 00:00:00 1970 Path: quimby.gnus.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: save-match-data woes Date: Thu, 21 Feb 2002 12:36:58 +0100 Message-ID: <20020221115255.A397.LEKTU@terra.es> NNTP-Posting-Host: quimby2.netfonds.no Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-Trace: quimby2.netfonds.no 1014291622 4325 195.204.10.66 (21 Feb 2002 11:40:22 GMT) X-Complaints-To: usenet@quimby2.netfonds.no NNTP-Posting-Date: 21 Feb 2002 11:40:22 GMT Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby2.netfonds.no with esmtp (Exim 3.12 #1 (Debian)) id 16draH-00017f-00 for ; Thu, 21 Feb 2002 12:40:21 +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 16drZC-0007vY-00; Thu, 21 Feb 2002 06:39:14 -0500 Original-Received: from [62.22.27.141] (helo=mail.peoplecall.com) by fencepost.gnu.org with esmtp (Exim 3.33 #1 (Debian)) id 16drX3-0007p5-00 for ; Thu, 21 Feb 2002 06:37:02 -0500 Original-Received: from jbarranquero (jbarranquero.ofi.peoplecall.com [62.22.27.143]) by mail.peoplecall.com (8.11.6/8.11.6) with ESMTP id g1LBaw817073 for ; Thu, 21 Feb 2002 12:36:58 +0100 Original-To: emacs-devel@gnu.org X-BkRandomSig-Folder: 3ade7ea7.mb\Emacs\Emacs-Devel\ X-Mailer: Becky! ver. 2.00.07 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:1389 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:1389 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. =46rom 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. So I'm including patches to ielm.el and pp.el protecting the offending code with save-match-data (the changes seem bigger because of indentation, but in all cases is just a matter of adding a call to save-match-data or equivalent). Incidentally, the above example with ielm still does not work for me (on a patched Emacs) if I get the second call to match-data via M-p, because that invokes an offending comint function. AFAICS comint.el does only a half-hearted attempt to preserve match data. It should be modified also, but I won't try that unless someone says that it is OK to do so. Only somewhat related: several tiny patches I've sent on the past week or so haven't received any comment. Should I assume silence is equivalent to rejection, or lack of interest? (Not a complain, just curiosity) /L/e/k/t/u 2002-02-21 Juanma Barranquero * ielm.el (ielm-return): Protect match data. (ielm-is-whitespace): Ditto. (ielm-get-old-input): Ditto. * emacs-lisp/pp.el (pp-to-string): Ditto. (pp-eval-last-sexp): Ditto. Index: ielm.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/ielm.el,v retrieving revision 1.22 diff -u -r1.22 ielm.el --- ielm.el 10 Oct 2000 17:27:38 -0000 1.22 +++ ielm.el 21 Feb 2002 11:03:35 -0000 @@ -225,7 +225,7 @@ (if (and ielm-dynamic-multiline-inputs (save-excursion (beginning-of-line) - (looking-at comint-prompt-regexp))) + (save-match-data (looking-at comint-prompt-regexp)))) (save-excursion (goto-char (ielm-pm)) (newline 1))) @@ -251,7 +251,8 @@ =20 (defun ielm-is-whitespace (string) "Return non-nil if STRING is all whitespace." - (or (string=3D string "") (string-match "\\`[ \t\n]+\\'" string))) + (or (string=3D string "") + (save-match-data (string-match "\\`[ \t\n]+\\'" string)))) =20 (defun ielm-format-errors (errlist) (let ((result "")) @@ -473,11 +474,12 @@ (defun ielm-get-old-input nil ;; Return the previous input surrounding point (save-excursion - (beginning-of-line) - (if (looking-at comint-prompt-regexp) nil - (re-search-backward comint-prompt-regexp)) - (comint-skip-prompt) - (buffer-substring (point) (progn (forward-sexp 1) (point))))) + (save-match-data + (beginning-of-line) + (if (looking-at comint-prompt-regexp) nil + (re-search-backward comint-prompt-regexp)) + (comint-skip-prompt) + (buffer-substring (point) (progn (forward-sexp 1) (point)))))) =20 ;;; User command =20 Index: emacs-lisp/pp.el =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/pp.el,v retrieving revision 1.18 diff -u -r1.18 pp.el --- emacs-lisp/pp.el 14 Feb 2002 16:47:11 -0000 1.18 +++ emacs-lisp/pp.el 21 Feb 2002 11:03:35 -0000 @@ -44,7 +44,7 @@ (save-excursion (set-buffer (generate-new-buffer " pp-to-string")) (unwind-protect - (progn + (save-match-data (lisp-mode-variables nil) (set-syntax-table emacs-lisp-mode-syntax-table) (let ((print-escape-newlines pp-escape-newlines) @@ -136,17 +136,18 @@ (let ((stab (syntax-table)) (pt (point)) start exp) (set-syntax-table emacs-lisp-mode-syntax-table) (save-excursion - (forward-sexp -1) - ;; If first line is commented, ignore all leading comments: - (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;")) - (progn - (setq exp (buffer-substring (point) pt)) - (while (string-match "\n[ \t]*;+" exp start) - (setq start (1+ (match-beginning 0)) - exp (concat (substring exp 0 start) - (substring exp (match-end 0))))) - (setq exp (read exp))) - (setq exp (read (current-buffer))))) + (save-match-data + (forward-sexp -1) + ;; If first line is commented, ignore all leading comments: + (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;")) + (progn + (setq exp (buffer-substring (point) pt)) + (while (string-match "\n[ \t]*;+" exp start) + (setq start (1+ (match-beginning 0)) + exp (concat (substring exp 0 start) + (substring exp (match-end 0))))) + (setq exp (read exp))) + (setq exp (read (current-buffer)))))) (set-syntax-table stab) (if arg (insert (pp-to-string (eval exp))) _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel