update.
[chise/xemacs-chise.git.1] / src / buffer.c
index 5790dc9..e7f8a4c 100644 (file)
@@ -524,7 +524,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)
@@ -1000,8 +1000,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))
 {
@@ -1336,38 +1336,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;
 }
@@ -2819,6 +2841,8 @@ It may not be a list of functions.
   DEFVAR_BUFFER_LOCAL ("buffer-file-name", filename /*
 Name of file visited in current buffer, or nil if not visiting a file.
 Each buffer has its own value of this variable.
+Code that changes this variable must maintain the invariant
+`(equal buffer-file-truename (file-truename buffer-file-name))'.
 */ );
 
 #if 0 /* FSFmacs */
@@ -2831,12 +2855,11 @@ Each buffer has its own value of this variable.
 #endif /* FSFmacs */
 
   DEFVAR_BUFFER_LOCAL ("buffer-file-truename", file_truename /*
-The real name of the file visited in the current buffer,
-or nil if not visiting a file.  This is the result of passing
-buffer-file-name to the `file-truename' function.  Every buffer has
-its own value of this variable.  This variable is automatically
-maintained by the functions that change the file name associated
-with a buffer.
+The real name of the file visited in the current buffer, or nil if not
+visiting a file.  This is the result of passing `buffer-file-name' to the
+`file-truename' function.  Every buffer has its own value of this variable.
+Code that changes the file name associated with a buffer maintains the
+invariant `(equal buffer-file-truename (file-truename buffer-file-name))'.
 */ );
 
   DEFVAR_BUFFER_LOCAL ("buffer-auto-save-file-name", auto_save_file_name /*
@@ -3049,7 +3072,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