diff src/process.c @ 844:047d37eb70d7

[xemacs-hg @ 2002-05-16 13:30:23 by ben] ui fixes for things that were bothering me bytecode.c, editfns.c, lisp.h, lread.c: Fix save-restriction to use markers rather than pseudo-markers (integers representing the amount of text on either side of the region). That way, all inserts are handled correctly, not just those inside old restriction. Add buffer argument to save_restriction_save(). process.c: Clean up very dirty and kludgy code that outputs into a buffer -- use proper unwind protects, etc. font-lock.c: Do save-restriction/widen around the function -- otherwise, incorrect results will ensue when a buffer has been narrowed before a call to e.g. `buffer-syntactic-context' -- something that happens quite often. fileio.c: Look for a handler for make-temp-name. window.c, winslots.h: Try to solve this annoying problem: have two frames displaying the buffer, in different places; in one, temporarily switch away to another buffer and then back -- and you've lost your position; it's reset to the other one in the other frame. My current solution involves window-level caches of buffers and points (also a cache for window-start); when set-window-buffer is called, it looks to see if the buffer was previously visited in the window, and if so, uses the most recent point at that time. (It's a marker, so it handles changes.) #### Note: It could be argued that doing it on the frame level would be better -- e.g. if you visit a buffer temporarily through a grep, and then go back to that buffer, you presumably want the grep's position rather than some previous position provided everything was in the same frame, even though the grep was in another window in the frame. However, doing it on the frame level fails when you have two windows on the same frame. Perhaps we keep both a window and a frame cache, and use the frame cache if there are no other windows on the frame showing the buffer, else the window's cache? This is probably something to be configurable using a specifier. Suggestions please please please? window.c: Clean up a bit code that deals with the annoyance of window-point vs. point. dialog.el: Function to ask a multiple-choice question, automatically choosing a dialog box or minibuffer representation as necessary. Generalized version of yes-or-no-p, y-or-n-p. files.el: Use get-user-response to ask "yes/no/diff" question when recovering. "diff" means that a diff is displayed between the current file and the autosave. (Converts/deconverts escape-quoted as necessary. No more complaints from you, Mr. Turnbull!) One known problem: when a dialog is used, it's modal, so you can't scroll the diff. Will fix soon. lisp-mode.el: If we're filling a string, don't treat semicolon as a comment, which would give very unfriendly results. Uses `buffer-syntactic-context'. simple.el: all changes back to the beginning. (Useful if you've saved the file in the middle of the changes.) simple.el: Add option kill-word-into-kill-ring, which controls whether words deleted with kill-word, backward-kill-word, etc. are "cut" into the kill ring, or "cleared" into nothingness. (My preference is the latter, by far. I'd almost go so far as suggesting we make it the default, as you can always select a word and then cut it if you want it cut.) menubar-items.el: Add option corresponding to kill-word-into-kill-ring.
author ben
date Thu, 16 May 2002 13:30:58 +0000
parents 6728e641994e
children 2b6fa2618f76
line wrap: on
line diff
--- a/src/process.c	Wed May 15 15:27:58 2002 +0000
+++ b/src/process.c	Thu May 16 13:30:58 2002 +0000
@@ -868,6 +868,52 @@
 /*                              Process I/O                             */
 /************************************************************************/
 
+/* Set up PROCESS's buffer for insertion of process data at PROCESS's
+   mark.
+
+   Sets the current buffer to PROCESS's buffer, inhibits read only,
+   remembers current point, sets point to PROCESS'S mark, widens if
+   necessary.
+*/
+static int
+process_setup_for_insertion (Lisp_Object process)
+{
+  Lisp_Process *p = XPROCESS (process);
+  int spec = specpdl_depth ();
+  struct buffer *buf = XBUFFER (p->buffer);
+  Charbpos output_pt;
+
+  if (buf != current_buffer)
+    {
+      record_unwind_protect (save_current_buffer_restore,
+			     Fcurrent_buffer ());
+      set_buffer_internal (buf);
+    }
+
+  record_unwind_protect (save_excursion_restore, save_excursion_save ());
+  specbind (Qinhibit_read_only, Qt);
+      
+  /* Insert new output into buffer
+     at the current end-of-output marker,
+     thus preserving logical ordering of input and output.  */
+  if (XMARKER (p->mark)->buffer)
+    output_pt = marker_position (p->mark);
+  else
+    output_pt = BUF_ZV (buf);
+
+  /* If the output marker is outside of the visible region, save
+     the restriction and widen.  */
+  if (! (BUF_BEGV (buf) <= output_pt && output_pt <= BUF_ZV (buf)))
+    {
+      record_unwind_protect (save_restriction_restore,
+			     save_restriction_save (buf));
+      Fwiden (wrap_buffer (buf));
+    }
+
+  BUF_SET_PT (buf, output_pt);
+  return spec;
+}
+
 /* Read pending output from the process channel,
    starting with our buffered-ahead character if we have one.
    Yield number of characters read.
@@ -940,47 +986,11 @@
   /* If no filter, write into buffer if it isn't dead.  */
   if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
     {
-      Lisp_Object old_read_only = Qnil;
-      Charbpos old_point;
-      Charbpos old_begv;
-      Charbpos old_zv;
-      struct gcpro gcpro1, gcpro2;
+      struct gcpro gcpro1;
       struct buffer *buf = XBUFFER (p->buffer);
-
-      GCPRO2 (process, old_read_only);
-
-      old_point = BUF_PT (buf);
-      old_begv = BUF_BEGV (buf);
-      old_zv = BUF_ZV (buf);
-      old_read_only = buf->read_only;
-      buf->read_only = Qnil;
+      int spec = process_setup_for_insertion (process);
 
-      /* Insert new output into buffer
-	 at the current end-of-output marker,
-	 thus preserving logical ordering of input and output.  */
-      if (XMARKER (p->mark)->buffer)
-	BUF_SET_PT (buf,
-		    charbpos_clip_to_bounds (old_begv, marker_position (p->mark),
-					   old_zv));
-      else
-	BUF_SET_PT (buf, old_zv);
-
-      /* If the output marker is outside of the visible region, save
-	 the restriction and widen.  */
-      if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
-	     BUF_PT (buf) <= BUF_ZV (buf)))
-	Fwiden (p->buffer);
-
-      /* Make sure opoint floats ahead of any new text, just as point
-	 would.  */
-      if (BUF_PT (buf) <= old_point)
-	old_point += nchars;
-
-      /* Insert after old_begv, but before old_zv.  */
-      if (BUF_PT (buf) < old_begv)
-	old_begv += nchars;
-      if (BUF_PT (buf) <= old_zv)
-	old_zv += nchars;
+      GCPRO1 (process);
 
 #if 0
       /* This screws up initial display of the window.  jla */
@@ -994,29 +1004,8 @@
 #endif
 
       Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
-
       MARK_MODELINE_CHANGED;
-
-      /* If the restriction isn't what it should be, set it.  */
-      if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
-	{
-	  Fwiden(p->buffer);
-	  old_begv = charbpos_clip_to_bounds (BUF_BEG (buf),
-					    old_begv,
-					    BUF_Z (buf));
-	  old_zv = charbpos_clip_to_bounds (BUF_BEG (buf),
-					  old_zv,
-					  BUF_Z (buf));
-	  Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
-			     p->buffer);
-	}
-
-      buf->read_only = old_read_only;
-      old_point = charbpos_clip_to_bounds (BUF_BEGV (buf),
-					 old_point,
-					 BUF_ZV (buf));
-      BUF_SET_PT (buf, old_point);
-
+      unbind_to (spec);
       UNGCPRO;
     }
   return nchars;
@@ -1499,48 +1488,24 @@
 	    exec_sentinel (process, msg);
 	  /* Don't bother with a message in the buffer
 	     when a process becomes runnable.  */
-	  else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
+	  else if (!EQ (symbol, Qrun) && !NILP (p->buffer) &&
+		   /* Avoid error if buffer is deleted
+		      (probably that's why the process is dead, too) */
+		   BUFFER_LIVE_P (XBUFFER (p->buffer)))
 	    {
-	      Lisp_Object old_read_only = Qnil;
-	      Lisp_Object old = Fcurrent_buffer ();
-	      Charbpos 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;
+	      struct gcpro ngcpro1;
+	      struct buffer *buf = XBUFFER (p->buffer);
+	      int spec = process_setup_for_insertion (process);
 
-              NGCPRO2 (old, old_read_only);
-	      Fset_buffer (p->buffer);
-	      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.  */
-	      if (XMARKER (p->mark)->buffer)
-		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 (msg)
-                           + string_char_length (p->name)
-                           + 10);
-
-	      old_read_only = current_buffer->read_only;
-	      current_buffer->read_only = Qnil;
+	      NGCPRO1 (process);
 	      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);
 
-	      opoint = charbpos_clip_to_bounds(BUF_BEGV (XBUFFER (p->buffer)),
-					     opoint,
-					     BUF_ZV (XBUFFER (p->buffer)));
-	      BUF_SET_PT (current_buffer, opoint);
-	      Fset_buffer (old);
+	      unbind_to (spec);
               NUNGCPRO;
 	    }
 	}