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

Import from CVS: tag r20-3b7
author cvs
date Mon, 13 Aug 2007 09:42:26 +0200
parents 3bb7ccffb0c0
children 85ec50267440
line wrap: on
line diff
--- a/src/process.c	Mon Aug 13 09:41:47 2007 +0200
+++ b/src/process.c	Mon Aug 13 09:42:26 2007 +0200
@@ -1771,12 +1771,24 @@
 
       /* If the restriction isn't what it should be, set it.  */
       if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
-	Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
-			   p->buffer);
+	{
+	  Fwiden(p->buffer);
+	  old_begv = bufpos_clip_to_bounds (BUF_BEG (buf),
+					    old_begv,
+					    BUF_Z (buf));
+	  old_zv = bufpos_clip_to_bounds (BUF_BEG (buf),
+					  old_zv,
+					  BUF_Z (buf));
+	  Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
+			     p->buffer);
+	}
 
       /* Handling the process output should not deactivate the mark.  */
       zmacs_region_stays = old_zmacs_region_stays;
       buf->read_only = old_read_only;
+      old_point = bufpos_clip_to_bounds (BUF_BEGV (buf),
+					 old_point,
+					 BUF_ZV (buf));
       BUF_SET_PT (buf, old_point);
 
       UNGCPRO;
@@ -2600,19 +2612,19 @@
 	     when a process becomes runnable.  */
 	  else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
 	    {
-	      int speccount = specpdl_depth ();
+	      Lisp_Object old_read_only = Qnil;
+	      Lisp_Object old = Fcurrent_buffer ();
+	      Bufpos opoint;
+              struct gcpro ngcpro1, ngcpro2;
 
 	      /* Avoid error if buffer is deleted
 		 (probably that's why the process is dead, too) */
 	      if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
 		continue;
 
-	      record_unwind_protect (save_excursion_restore,
-				     save_excursion_save ());
+              NGCPRO2 (old, old_read_only);
 	      Fset_buffer (p->buffer);
-	      record_unwind_protect (save_excursion_restore,
-				     save_excursion_save ());
-	      specbind(Qbuffer_read_only, Qnil);
+	      opoint = BUF_PT (current_buffer);
 	      /* Insert new output into buffer
 		 at the current end-of-output marker,
 		 thus preserving logical ordering of input and output.  */
@@ -2620,13 +2632,27 @@
 		BUF_SET_PT (current_buffer, marker_position (p->mark));
 	      else
 		BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
+	      if (BUF_PT (current_buffer) <= opoint)
+		opoint += (string_char_length (XSTRING (msg))
+                           + string_char_length (XSTRING (p->name))
+                           + 10);
+
+	      old_read_only = current_buffer->read_only;
+	      current_buffer->read_only = Qnil;
 	      buffer_insert_c_string (current_buffer, "\nProcess ");
 	      Finsert (1, &p->name);
 	      buffer_insert_c_string (current_buffer, " ");
 	      Finsert (1, &msg);
+	      current_buffer->read_only = old_read_only;
 	      Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
 			   p->buffer);
-	      unbind_to(speccount, Qnil);
+
+	      opoint = bufpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
+					     opoint,
+					     BUF_ZV (XBUFFER (p->buffer)));
+	      BUF_SET_PT (current_buffer, opoint);
+	      Fset_buffer (old);
+              NUNGCPRO;
 	    }
 	}
     } /* end for */