diff src/editfns.c @ 161:28f395d8dc7a r20-3b7

Import from CVS: tag r20-3b7
author cvs
date Mon, 13 Aug 2007 09:42:26 +0200
parents 25f70ba0133c
children 0132846995bd
line wrap: on
line diff
--- a/src/editfns.c	Mon Aug 13 09:41:47 2007 +0200
+++ b/src/editfns.c	Mon Aug 13 09:42:26 2007 +0200
@@ -489,6 +489,30 @@
 			 
   return unbind_to (speccount, Fprogn (args));
 }
+
+Lisp_Object
+save_current_buffer_restore(Lisp_Object buffer)
+{
+  struct buffer *buf = XBUFFER (buffer);
+  if (!BUFFER_LIVE_P (buf))
+    return Qnil;
+  set_buffer_internal (buf);
+  return Qnil;
+}
+
+DEFUN ("save-current-buffer", Fsave_current_buffer, 0, UNEVALLED, 0, /*
+Save the current buffer; execute BODY; restore the current buffer.
+Executes BODY just like `progn'.
+*/
+  (args))
+{
+  /* This function can GC */
+  int speccount = specpdl_depth ();
+
+  record_unwind_protect (save_current_buffer_restore, Fcurrent_buffer ());
+
+  return unbind_to (speccount, Fprogn (args));
+}
 
 DEFUN ("buffer-size", Fbufsize, 0, 1, 0, /*
 Return the number of characters in BUFFER.
@@ -2100,6 +2124,7 @@
   DEFSUBR (Fregion_beginning);
   DEFSUBR (Fregion_end);
   DEFSUBR (Fsave_excursion);
+  DEFSUBR (Fsave_current_buffer);
 
   DEFSUBR (Fbufsize);
   DEFSUBR (Fpoint_max);