unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* save-match-data woes
@ 2002-02-21 11:36 Juanma Barranquero
  2002-02-21 11:54 ` Eli Zaretskii
  2002-02-22 16:43 ` Stefan Monnier
  0 siblings, 2 replies; 11+ messages in thread
From: Juanma Barranquero @ 2002-02-21 11:36 UTC (permalink / raw


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.

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  <lektu@terra.es>

	* 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
===================================================================
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 @@
 
 (defun ielm-is-whitespace (string)
   "Return non-nil if STRING is all whitespace."
-  (or (string= string "") (string-match "\\`[ \t\n]+\\'" string)))
+  (or (string= string "")
+      (save-match-data (string-match "\\`[ \t\n]+\\'" string))))
 
 (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))))))
 
 ;;; User command
 
Index: emacs-lisp/pp.el
===================================================================
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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-02-28  4:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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).