Dear Bug Team!
Maybe I should have sent this to xemacs-design but I think it's more
of a bug.
The macro `with-string-as-buffer-contents' does in code
like the following not work as expected unless (current-buffer) is
explicitly passed in:
(with-string-as-buffer-contents (buffer-substring from to))
(with-string-as-buffer-contents (buffer-file-name))
I think that STR should be evaluated prior to switching buffers. This
should not break existing code since the newly created temp-buffer
will be empty and therefore nobody would really want to take STR from
it. Only really flaky code relying on buffer local variables in the
temporary buffer might be affected. I don't think such code can be
found in the distribution. (Checked all of the dumped code and there
are no problems I could see. It does not appear in any of the packages
I have installed, well except for my own or I wouldn't have noticed.)
Here the proposed fix:
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/subr.el,v
retrieving revision 1.22
diff -u -r1.22 subr.el
--- subr.el 2002/04/14 12:42:05 1.22
+++ subr.el 2002/05/07 11:25:29
@@ -495,10 +495,12 @@
"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 ((string (gensym)))
+ `(let ((,string ,str))
+ (with-temp-buffer
+ (insert ,string)
+ ,@body
+ (buffer-string)))))
(defun insert-face (string face)
"Insert STRING and highlight with FACE. Return the extent created."
===================================================================
And a ChangeLog entry, if you agree:
===================================================================
2002-05-07 Carsten Boriss <caboriss(a)eircom.net>
* subr.el (with-string-as-buffer-contents): evaluate argument STR
prior to switching to the temporary buffer, so that buffer
contents and local variables of the caller are still in scope.
===================================================================
Carsten