diff src/editfns.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 e7ee5f8bde58
line wrap: on
line diff
--- a/src/editfns.c	Wed May 15 15:27:58 2002 +0000
+++ b/src/editfns.c	Thu May 16 13:30:58 2002 +0000
@@ -2042,77 +2042,71 @@
 }
 
 Lisp_Object
-save_restriction_save (void)
+save_restriction_save (struct buffer *buf)
 {
-  Lisp_Object bottom, top;
-  /* Note: I tried using markers here, but it does not win
+  Lisp_Object bottom = noseeum_make_marker ();
+  Lisp_Object top = noseeum_make_marker ();
+
+  /* Formerly, this function remembered the amount of text on either side
+     of the restricted area, in a halfway attempt to account for insertion --
+     it handles insertion inside the old restricted area, but not outside.
+     The comment read:
+
+     [[ Note: I tried using markers here, but it does not win
      because insertion at the end of the saved region
-     does not advance mh and is considered "outside" the saved region. */
-  bottom = make_int (BUF_BEGV (current_buffer) - BUF_BEG (current_buffer));
-  top = make_int (BUF_Z (current_buffer) - BUF_ZV (current_buffer));
+     does not advance mh and is considered "outside" the saved region. ]]
+
+     But that was clearly before the advent of marker-insertion-type. --ben */
 
-  return noseeum_cons (Fcurrent_buffer (), noseeum_cons (bottom, top));
+  Fset_marker (bottom, make_int (BUF_BEGV (buf)), wrap_buffer (buf));
+  Fset_marker (top, make_int (BUF_ZV (buf)), wrap_buffer (buf));
+  Fset_marker_insertion_type (top, Qt);
+
+  return noseeum_cons (wrap_buffer (buf), noseeum_cons (bottom, top));
 }
 
 Lisp_Object
 save_restriction_restore (Lisp_Object data)
 {
   struct buffer *buf;
-  Charcount newhead, newtail;
-  Lisp_Object tem;
+  Lisp_Object markers = XCDR (data);
   int local_clip_changed = 0;
 
   buf = XBUFFER (XCAR (data));
-  if (!BUFFER_LIVE_P (buf))
+  /* someone could have killed the buffer in the meantime ... */
+  if (BUFFER_LIVE_P (buf))
     {
-      /* someone could have killed the buffer in the meantime ... */
-      free_cons (XCONS (XCDR (data)));
-      free_cons (XCONS (data));
-      return Qnil;
-    }
-  tem = XCDR (data);
-  newhead = XINT (XCAR (tem));
-  newtail = XINT (XCDR (tem));
+      Charbpos start = marker_position (XCAR (markers));
+      Charbpos end = marker_position (XCDR (markers));
+      Bytebpos byte_start = charbpos_to_bytebpos (buf, start);
+      Bytebpos byte_end = charbpos_to_bytebpos (buf, end);
 
-  free_cons (XCONS (XCDR (data)));
-  free_cons (XCONS (data));
+      if (BUF_BEGV (buf) != start)
+	{
+	  local_clip_changed = 1;
+	  SET_BOTH_BUF_BEGV (buf, start, byte_start);
+	  narrow_line_number_cache (buf);
+	}
+      if (BUF_ZV (buf) != end)
+	{
+	  local_clip_changed = 1;
+	  SET_BOTH_BUF_ZV (buf, end, byte_end);
+	}
 
-  if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))
-    {
-      newhead = 0;
-      newtail = 0;
+      if (local_clip_changed)
+	MARK_CLIP_CHANGED;
+
+      /* If point is outside the new visible range, move it inside. */
+      BUF_SET_PT (buf, charbpos_clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf),
+						BUF_ZV (buf)));
     }
 
-  {
-    Charbpos start, end;
-    Bytebpos byte_start, byte_end;
-
-    start = BUF_BEG (buf) + newhead;
-    end = BUF_Z (buf) - newtail;
-
-    byte_start = charbpos_to_bytebpos (buf, start);
-    byte_end = charbpos_to_bytebpos (buf, end);
-
-    if (BUF_BEGV (buf) != start)
-      {
-	local_clip_changed = 1;
-	SET_BOTH_BUF_BEGV (buf, start, byte_start);
-	narrow_line_number_cache (buf);
-      }
-    if (BUF_ZV (buf) != end)
-      {
-	local_clip_changed = 1;
-	SET_BOTH_BUF_ZV (buf, end, byte_end);
-      }
-  }
-  if (local_clip_changed)
-    MARK_CLIP_CHANGED;
-
-  /* If point is outside the new visible range, move it inside. */
-  BUF_SET_PT (buf,
-              charbpos_clip_to_bounds (BUF_BEGV (buf),
-				     BUF_PT (buf),
-				     BUF_ZV (buf)));
+  /* Free all the junk we allocated, so that a `save-restriction' comes
+     for free in terms of GC junk. */
+  free_marker (XMARKER (XCAR (markers)));
+  free_marker (XMARKER (XCDR (markers)));
+  free_cons (XCONS (markers));
+  free_cons (XCONS (data));
 
   return Qnil;
 }
@@ -2129,8 +2123,9 @@
 
 The value returned is the value of the last form in BODY.
 
-`save-restriction' can get confused if, within the BODY, you widen
-and then make changes outside the area within the saved restrictions.
+As of XEmacs 22.0, `save-restriction' correctly handles all modifications
+made within BODY. (Formerly, it got confused if, within the BODY, you
+widened and then made changes outside the old restricted area.)
 
 Note: if you are using both `save-excursion' and `save-restriction',
 use `save-excursion' outermost:
@@ -2139,9 +2134,9 @@
        (body))
 {
   /* This function can GC */
-  int speccount = specpdl_depth ();
-
-  record_unwind_protect (save_restriction_restore, save_restriction_save ());
+  int speccount =
+    record_unwind_protect (save_restriction_restore,
+			   save_restriction_save (current_buffer));
 
   return unbind_to_1 (speccount, Fprogn (body));
 }