diff lisp/subr.el @ 371:cc15677e0335 r21-2b1

Import from CVS: tag r21-2b1
author cvs
date Mon, 13 Aug 2007 11:03:08 +0200
parents a4f53d9b3154
children d883f39b8495
line wrap: on
line diff
--- a/lisp/subr.el	Mon Aug 13 11:01:58 2007 +0200
+++ b/lisp/subr.el	Mon Aug 13 11:03:08 2007 +0200
@@ -297,14 +297,10 @@
 If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
   (or pattern
       (setq pattern "[ \f\t\n\r\v]+"))
-  (let (parts (start 0) (len (length string)))
-    (if (string-match pattern string)
-       (setq parts (cons (substring string 0 (match-beginning 0)) parts)
-             start (match-end 0)))
-    (while (and (< start len)
-               (string-match pattern string (if (> start (match-beginning 0))
-                                                start
-                                              (1+ start))))
+  ;; The FSF version of this function takes care not to cons in case
+  ;; of infloop.  Maybe we should synch?
+  (let (parts (start 0))
+    (while (string-match pattern string start)
       (setq parts (cons (substring string start (match-beginning 0)) parts)
 	    start (match-end 0)))
     (nreverse (cons (substring string start) parts))))
@@ -326,8 +322,7 @@
   "Collect output to `standard-output' while evaluating FORMS and return
 it as a string."
   ;; by "William G. Dubuque" <wgd@zurich.ai.mit.edu> w/ mods from Stig
-  `(with-current-buffer (get-buffer-create
-			 (generate-new-buffer-name " *string-output*"))
+  `(with-current-buffer (get-buffer-create " *string-output*")
      (setq buffer-read-only nil)
      (buffer-disable-undo (current-buffer))
      (erase-buffer)
@@ -338,7 +333,7 @@
        (erase-buffer))))
 
 (defmacro with-current-buffer (buffer &rest body)
-  "Temporarily make BUFFER the current buffer and execute the forms in BODY.
+  "Execute the forms in BODY with BUFFER as the current buffer.
 The value returned is the value of the last form in BODY.
 See also `with-temp-buffer'."
   `(save-current-buffer
@@ -376,14 +371,21 @@
 	 (and (buffer-name ,temp-buffer)
 	      (kill-buffer ,temp-buffer))))))
 
+;; Moved from mule-coding.el.
 (defmacro with-string-as-buffer-contents (str &rest body)
   "With the contents of the current buffer being STR, run BODY.
 Returns the new contents of the buffer, as modified by BODY.
 The original current buffer is restored afterwards."
-  `(with-temp-buffer
-     (insert ,str)
-     ,@body
-     (buffer-string)))
+  `(let ((tempbuf (get-buffer-create " *string-as-buffer-contents*")))
+     (with-current-buffer tempbuf
+       (unwind-protect
+	   (progn
+	     (buffer-disable-undo (current-buffer))
+	     (erase-buffer)
+	     (insert ,str)
+	     ,@body
+	     (buffer-string))
+	 (erase-buffer tempbuf)))))
 
 (defun insert-face (string face)
   "Insert STRING and highlight with FACE.  Return the extent created."