XEmacs 21.4.17 "Jumbo Shrimp".
[chise/xemacs-chise.git.1] / src / buffer.c
index d2245f7..23eb018 100644 (file)
@@ -356,7 +356,7 @@ get_buffer (Lisp_Object name, int error_if_deleted_or_does_not_exist)
 struct buffer *
 decode_buffer (Lisp_Object buffer, int allow_string)
 {
-  if (NILP (buffer))
+  if (NILP (buffer) || (!POINTER_TYPE_P( XTYPE(buffer))))
     return current_buffer;
 
   if (allow_string && STRINGP (buffer))
@@ -522,7 +522,7 @@ delete_from_buffer_alist (Lisp_Object buf)
   Lisp_Object cons = Frassq (buf, Vbuffer_alist);
   Lisp_Object frmcons, devcons, concons;
   if (NILP (cons))
-    return; /* abort() ? */
+    return; /* ABORT() ? */
   Vbuffer_alist = delq_no_quit (cons, Vbuffer_alist);
 
   FRAME_LOOP_NO_BREAK (frmcons, devcons, concons)
@@ -998,8 +998,8 @@ The ordering is for this frame; If second optional argument FRAME
 is provided, then the ordering is for that frame.  If the second arg
 is t, then the global ordering is returned.
 
-Note: In FSF Emacs, this function takes two arguments: BUFFER and
-VISIBLE-OK.
+Note: In FSF Emacs, this function takes the arguments in the order of
+BUFFER, VISIBLE-OK and FRAME.
 */
        (buffer, frame, visible_ok))
 {
@@ -1256,9 +1256,11 @@ with `delete-process'.
 
     delete_from_buffer_alist (buf);
 
-    /* #### This is a problem if this buffer is in a dedicated window.
-       Need to undedicate any windows of this buffer first (and delete them?)
-       */
+    /* Undedicate any windows of this buffer, and make sure no windows
+       show it.  */
+
+    undedicate_windows (buf, Qt);
+    
     GCPRO1 (buf);
     Freplace_buffer_in_windows (buf, Qnil, Qall);
     UNGCPRO;
@@ -1332,38 +1334,60 @@ buffer.  See `other-buffer' for more information.
 {
   REGISTER Lisp_Object lynk, prev;
   struct frame *f = selected_frame ();
+  int buffer_found = 0;
 
+  CHECK_BUFFER (buffer);
+  if (!BUFFER_LIVE_P (XBUFFER (buffer)))
+    return Qnil;
   prev = Qnil;
   for (lynk = Vbuffer_alist; CONSP (lynk); lynk = XCDR (lynk))
     {
       if (EQ (XCDR (XCAR (lynk)), buffer))
-       break;
+       {
+         buffer_found = 1;
+         break;
+       }
       prev = lynk;
     }
-  /* Effectively do Vbuffer_alist = delq_no_quit (lynk, Vbuffer_alist) */
-  if (NILP (prev))
-    Vbuffer_alist = XCDR (Vbuffer_alist);
+  if (buffer_found)
+    {
+      /* Effectively do Vbuffer_alist = delq_no_quit (lynk, Vbuffer_alist) */
+      if (NILP (prev))
+       Vbuffer_alist = XCDR (Vbuffer_alist);
+      else
+       XCDR (prev) = XCDR (XCDR (prev));
+      XCDR (lynk) = Vbuffer_alist;
+      Vbuffer_alist = lynk;
+    }
   else
-    XCDR (prev) = XCDR (XCDR (prev));
-  XCDR (lynk) = Vbuffer_alist;
-  Vbuffer_alist = lynk;
+    Vbuffer_alist = Fcons (Fcons (Fbuffer_name(buffer), buffer), Vbuffer_alist);
 
   /* That was the global one.  Now do the same thing for the
      per-frame buffer-alist. */
+  buffer_found = 0;
   prev = Qnil;
   for (lynk = f->buffer_alist; CONSP (lynk); lynk = XCDR (lynk))
     {
       if (EQ (XCDR (XCAR (lynk)), buffer))
-       break;
+       {
+         buffer_found = 1;
+         break;
+       }
       prev = lynk;
     }
-  /* Effectively do f->buffer_alist = delq_no_quit (lynk, f->buffer_alist) */
-  if (NILP (prev))
-    f->buffer_alist = XCDR (f->buffer_alist);
+  if (buffer_found)
+    {
+      /* Effectively do f->buffer_alist = delq_no_quit (lynk, f->buffer_alist) */
+      if (NILP (prev))
+       f->buffer_alist = XCDR (f->buffer_alist);
+      else
+       XCDR (prev) = XCDR (XCDR (prev));
+      XCDR (lynk) = f->buffer_alist;
+      f->buffer_alist = lynk;
+    }
   else
-    XCDR (prev) = XCDR (XCDR (prev));
-  XCDR (lynk) = f->buffer_alist;
-  f->buffer_alist = lynk;
+    f->buffer_alist = Fcons (Fcons (Fbuffer_name(buffer), buffer),
+                            f->buffer_alist);
 
   return Qnil;
 }
@@ -1624,7 +1648,6 @@ BUFFER defaults to the current buffer if omitted.
      implies that the future text is not really related to the past text.  */
   b->saved_size = Qzero;
 
-  zmacs_region_stays = 0;
   return Qnil;
 }
 
@@ -2505,7 +2528,9 @@ common_init_complex_vars_of_buffer (void)
 
     /* #### Warning: 1<<31 is the largest number currently allowable
        due to the XINT() handling of this value.  With some
-       rearrangement you can get 3 more bits. */
+       rearrangement you can get 3 more bits.
+
+       #### 3 more?  34 bits???? -ben */
   }
 }
 
@@ -2675,12 +2700,6 @@ Automatically becomes buffer-local when set in any fashion.
   DEFVAR_BUFFER_LOCAL ("case-fold-search", case_fold_search /*
 *Non-nil if searches should ignore case.
 Automatically becomes buffer-local when set in any fashion.
-
-BUG: Under XEmacs/Mule, translations to or from non-ASCII characters
- (this includes chars in the range 128 - 255) are ignored by
- the string/buffer-searching routines.  Thus, `case-fold-search'
- will not correctly conflate a-umlaut and A-umlaut even if the
- case tables call for this.
 */ );
 
   DEFVAR_BUFFER_LOCAL ("fill-column", fill_column /*
@@ -3032,7 +3051,7 @@ handled:
   if ((XINT (buffer_local_flags.slot) != -2 &&                 \
        XINT (buffer_local_flags.slot) != -3)                   \
       != !(NILP (XBUFFER (Vbuffer_local_symbols)->slot)))      \
-  abort ()
+  ABORT ()
 #include "bufslots.h"
 #undef MARKED_SLOT