Merge from trunk.
[bpt/emacs.git] / src / buffer.c
index 2c7b426..afa7e91 100644 (file)
@@ -1526,7 +1526,13 @@ with SIGHUP.  */)
       UNGCPRO;
     }
 
-  /* Make this buffer not be current.
+  /* Run replace_buffer_in_windows before making another buffer current
+     since set-window-buffer-start-and-point will refuse to make another
+     buffer current if the selected window does not show the current
+     buffer.  (Bug#10114) */
+  replace_buffer_in_windows (buffer);
+
+     /* Make this buffer not be current.
      In the process, notice if this is the sole visible buffer
      and give up if so.  */
   if (b == current_buffer)
@@ -1566,7 +1572,6 @@ with SIGHUP.  */)
 
   /* These may run Lisp code and into infinite loops (if someone
      insisted on circular lists) so allow quitting here.  */
-  replace_buffer_in_windows (buffer);
   frames_discard_buffer (buffer);
 
   clear_charpos_cache (b);
@@ -1626,7 +1631,7 @@ with SIGHUP.  */)
 
   /* Reset the local variables, so that this buffer's local values
      won't be protected from GC.  They would be protected
-     if they happened to remain encached in their symbols.
+     if they happened to remain cached in their symbols.
      This gets rid of them for certain.  */
   swap_out_buffer_local_variables (b);
   reset_buffer_local_variables (b, 1);
@@ -2480,7 +2485,7 @@ swap_out_buffer_local_variables (struct buffer *b)
       Lisp_Object sym = XCAR (XCAR (alist));
       eassert (XSYMBOL (sym)->redirect == SYMBOL_LOCALIZED);
       /* Need not do anything if some other buffer's binding is
-        now encached.  */
+        now cached.  */
       if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer))
        {
          /* Symbol is set up for this buffer's old local value:
@@ -3672,6 +3677,7 @@ buffer.  */)
   struct buffer *b, *ob;
   Lisp_Object obuffer;
   ptrdiff_t count = SPECPDL_INDEX ();
+  ptrdiff_t n_beg, n_end;
 
   CHECK_OVERLAY (overlay);
   if (NILP (buffer))
@@ -3696,16 +3702,18 @@ buffer.  */)
       temp = beg; beg = end; end = temp;
     }
 
-  b = XBUFFER (buffer);
-  if (! (BUF_BEGV (b) <= XINT (beg) && XINT (end) <= BUF_ZV (b)))
-    args_out_of_range (beg, end);
+  Fset_marker (OVERLAY_START (overlay), beg, buffer);
+  Fset_marker (OVERLAY_END (overlay), end, buffer);
+  n_beg = marker_position (OVERLAY_START (overlay));
+  n_end = marker_position (OVERLAY_END (overlay));
 
-  if (XINT (beg) == XINT (end) && ! NILP (Foverlay_get (overlay, Qevaporate)))
+  if (n_beg == n_end && ! NILP (Foverlay_get (overlay, Qevaporate)))
     return Fdelete_overlay (overlay);
 
   specbind (Qinhibit_quit, Qt);
 
   obuffer = Fmarker_buffer (OVERLAY_START (overlay));
+  b = XBUFFER (buffer);
   ob = BUFFERP (obuffer) ? XBUFFER (obuffer) : (struct buffer *) 0;
 
   /* If the overlay has changed buffers, do a thorough redisplay.  */
@@ -3724,7 +3732,7 @@ buffer.  */)
        }
 
       /* Redisplay where the overlay is going to be.  */
-      modify_overlay (b, XINT (beg), XINT (end));
+      modify_overlay (b, n_beg, n_end);
     }
   else
     /* Redisplay the area the overlay has just left, or just enclosed.  */
@@ -3734,16 +3742,12 @@ buffer.  */)
       o_beg = OVERLAY_POSITION (OVERLAY_START (overlay));
       o_end = OVERLAY_POSITION (OVERLAY_END (overlay));
 
-      if (o_beg == XINT (beg))
-       modify_overlay (b, o_end, XINT (end));
-      else if (o_end == XINT (end))
-       modify_overlay (b, o_beg, XINT (beg));
+      if (o_beg == n_beg)
+       modify_overlay (b, o_end, n_end);
+      else if (o_end == n_end)
+       modify_overlay (b, o_beg, n_beg);
       else
-       {
-         if (XINT (beg) < o_beg) o_beg = XINT (beg);
-         if (XINT (end) > o_end) o_end = XINT (end);
-         modify_overlay (b, o_beg, o_end);
-       }
+       modify_overlay (b, min (o_beg, n_beg), max (o_end, n_end));
     }
 
   if (!NILP (obuffer))
@@ -3755,12 +3759,8 @@ buffer.  */)
       eassert (XOVERLAY (overlay)->next == NULL);
     }
 
-  Fset_marker (OVERLAY_START (overlay), beg, buffer);
-  Fset_marker (OVERLAY_END   (overlay), end, buffer);
-
   /* Put the overlay on the wrong list.  */
-  end = OVERLAY_END (overlay);
-  if (OVERLAY_POSITION (end) < b->overlay_center)
+  if (n_end < b->overlay_center)
     {
       XOVERLAY (overlay)->next = b->overlays_after;
       b->overlays_after = XOVERLAY (overlay);
@@ -4404,7 +4404,7 @@ static int mmap_fd_1;
 
 static int mmap_page_size;
 
-/* 1 means mmap has been intialized.  */
+/* 1 means mmap has been initialized.  */
 
 static int mmap_initialized_p;
 
@@ -4435,7 +4435,7 @@ static int mmap_initialized_p;
    is currently mapped.  Used to prevent overwriting an existing
    memory mapping.
 
-   Default is to conservativly assume the address range is occupied by
+   Default is to conservatively assume the address range is occupied by
    something else.  This can be overridden by system configuration
    files if system-specific means to determine this exists.  */
 
@@ -4443,7 +4443,7 @@ static int mmap_initialized_p;
 #define MMAP_ALLOCATED_P(start, end) 1
 #endif
 
-/* Perform necessary intializations for the use of mmap.  */
+/* Perform necessary initializations for the use of mmap.  */
 
 static void
 mmap_init (void)
@@ -5452,9 +5452,7 @@ file I/O and the behavior of various editing commands.
 
 This variable is buffer-local but you cannot set it directly;
 use the function `set-buffer-multibyte' to change a buffer's representation.
-Changing its default value with `setq-default' is supported.
-See also variable `default-enable-multibyte-characters' and Info node
-`(elisp)Text Representations'.  */);
+See also Info node `(elisp)Text Representations'.  */);
   XSYMBOL (intern_c_string ("enable-multibyte-characters"))->constant = 1;
 
   DEFVAR_PER_BUFFER ("buffer-file-coding-system",