XEmacs 21.2.36 "Notos"
[chise/xemacs-chise.git.1] / src / buffer.c
index abad796..2a97d62 100644 (file)
@@ -84,6 +84,7 @@ Boston, MA 02111-1307, USA.  */
 #ifdef REGION_CACHE_NEEDS_WORK
 #include "region-cache.h"
 #endif
+#include "select.h"     /* for select_notify_buffer_kill */
 #include "specifier.h"
 #include "syntax.h"
 #include "sysdep.h"    /* for getwd */
@@ -438,7 +439,7 @@ the search will still be done on `buffer-file-name'.
 */
        (filename))
 {
-  /* This function can GC.  GC checked 1997.04.06. */
+  /* This function can GC.  GC checked and fixed 7-11-2000 ben. */
   REGISTER Lisp_Object buf;
   struct gcpro gcpro1;
 
@@ -473,15 +474,17 @@ the search will still be done on `buffer-file-name'.
          dn = Ffile_name_directory (filename);
          fn = Ffile_truename (dn, Qnil);
          if (! NILP (fn)) dn = fn;
-         fn = Fexpand_file_name (Ffile_name_nondirectory (filename),
-                                 dn);
+         /* Formerly the two calls below were combined, but that is
+            not GC-safe because the first call returns unprotected
+            data and the second call can GC. --ben */
+         fn = Ffile_name_nondirectory (filename);
+         fn = Fexpand_file_name (fn, dn);
        }
       filename = fn;
       NUNGCPRO;
     }
 
   {
-    Lisp_Object elt;
     LIST_LOOP_2 (elt, Vbuffer_alist)
       {
        buf = Fcdr (elt);
@@ -533,6 +536,7 @@ delete_from_buffer_alist (Lisp_Object buf)
 Lisp_Object
 get_truename_buffer (REGISTER Lisp_Object filename)
 {
+  /* This function can GC.  GC correct 7-11-00 ben */
   /* FSFmacs has its own code here and doesn't call get-file-buffer.
      That's because their equivalent of find-file-compare-truenames
      (find-file-existing-other-name) isn't looked at in get-file-buffer.
@@ -868,37 +872,6 @@ No argument or nil as argument means use current buffer as BUFFER.
   return result;
 }
 
-DEFUN ("buffer-dedicated-frame", Fbuffer_dedicated_frame, 0, 1, 0, /*
-Return the frame dedicated to this BUFFER, or nil if there is none.
-No argument or nil as argument means use current buffer as BUFFER.
-*/
-       (buffer))
-{
-  struct buffer *buf = decode_buffer (buffer, 0);
-
-  /* XEmacs addition: if the frame is dead, silently make it go away. */
-  if (!NILP (buf->dedicated_frame) &&
-      !FRAME_LIVE_P (XFRAME (buf->dedicated_frame)))
-    buf->dedicated_frame = Qnil;
-
-  return buf->dedicated_frame;
-}
-
-DEFUN ("set-buffer-dedicated-frame", Fset_buffer_dedicated_frame, 2, 2, 0, /*
-For this BUFFER, set the FRAME dedicated to it.
-FRAME must be a frame or nil.
-*/
-       (buffer, frame))
-{
-  struct buffer *buf = decode_buffer (buffer, 0);
-
-  if (!NILP (frame))
-    CHECK_LIVE_FRAME (frame); /* XEmacs change */
-
-  return buf->dedicated_frame = frame;
-}
-
-
 \f
 DEFUN ("buffer-modified-p", Fbuffer_modified_p, 0, 1, 0, /*
 Return t if BUFFER was modified since its file was last read or saved.
@@ -1220,15 +1193,13 @@ with `delete-process'.
 
       /* Then run the hooks.  */
       run_hook (Qkill_buffer_hook);
-#ifdef HAVE_X_WINDOWS
-      /* If an X selection was in this buffer, disown it.
-        We could have done this by simply adding this function to the
-        kill-buffer-hook, but the user might mess that up.
-        */
-      if (EQ (Vwindow_system, Qx))
-       call0 (intern ("xselect-kill-buffer-hook"));
-      /* #### generalize me! */
-#endif /* HAVE_X_WINDOWS */
+
+      /* Inform the selection code that a buffer just got killed.
+        We do this in C because (a) it's faster, and (b) it needs
+         to access data internal to select.c that can't be seen from
+         Lisp (so the Lisp code would just call into C anyway. */
+      select_notify_buffer_kill (buf);
+
       unbind_to (speccount, Qnil);
       UNGCPRO;
       b = XBUFFER (buf);        /* Hypothetical relocating GC. */
@@ -1481,20 +1452,6 @@ set_buffer_internal (struct buffer *b)
   current_buffer = b;
   invalidate_current_column ();   /* invalidate indentation cache */
 
-#ifdef HAVE_FEP
-  if (!noninteractive && initialized)
-    {
-      extern Lisp_Object Ffep_force_on (), Ffep_force_off (), Ffep_get_mode ();
-
-      old_buf->fep_mode = Ffep_get_mode ();
-
-      if (!NILP (current_buffer->fep_mode))
-       Ffep_force_on ();
-      else
-       Ffep_force_off ();
-  }
-#endif /* HAVE_FEP */
-
   if (old_buf)
     {
       /* Put the undo list back in the base buffer, so that it appears
@@ -2201,8 +2158,6 @@ syms_of_buffer (void)
   DEFSUBR (Fbuffer_base_buffer);
   DEFSUBR (Fbuffer_indirect_children);
   DEFSUBR (Fbuffer_local_variables);
-  DEFSUBR (Fbuffer_dedicated_frame);
-  DEFSUBR (Fset_buffer_dedicated_frame);
   DEFSUBR (Fbuffer_modified_p);
   DEFSUBR (Fset_buffer_modified_p);
   DEFSUBR (Fbuffer_modified_tick);
@@ -2223,8 +2178,8 @@ syms_of_buffer (void)
   DEFSUBR (Fbuffer_memory_usage);
 #endif
 
-  deferror (&Qprotected_field, "protected-field",
-           "Attempt to modify a protected field", Qerror);
+  DEFERROR (Qprotected_field, "Attempt to modify a protected field",
+           Qinvalid_change);
 }
 
 void
@@ -3114,6 +3069,7 @@ handled:
   }
 }
 
+#ifndef WIN32_NATIVE
 /* Is PWD another name for `.' ? */
 static int
 directory_is_current_directory (Extbyte *pwd)
@@ -3127,29 +3083,35 @@ directory_is_current_directory (Extbyte *pwd)
                      Qfile_name);
 
   return (IS_DIRECTORY_SEP (*pwd_internal)
-         && stat ((char *) pwd_internal, &pwdstat) == 0
-         && stat (".", &dotstat) == 0
+         && xemacs_stat ((char *) pwd_internal, &pwdstat) == 0
+         && xemacs_stat (".", &dotstat) == 0
          && dotstat.st_ino == pwdstat.st_ino
          && dotstat.st_dev == pwdstat.st_dev
          && pwd_internal_len < MAXPATHLEN);
 }
+#endif
 
 void
 init_initial_directory (void)
 {
   /* This function can GC */
 
+#ifndef WIN32_NATIVE
   Extbyte *pwd;
+#endif
 
   initial_directory[0] = 0;
 
   /* If PWD is accurate, use it instead of calling getcwd.  This is faster
      when PWD is right, and may avoid a fatal error.  */
+#ifndef WIN32_NATIVE
   if ((pwd = (Extbyte *) getenv ("PWD")) != NULL
       && directory_is_current_directory (pwd))
     strcpy (initial_directory, (char *) pwd);
-  else if (getcwd (initial_directory, MAXPATHLEN) == NULL)
-    fatal ("`getcwd' failed: %s\n", strerror (errno));
+  else
+#endif
+    if (getcwd (initial_directory, MAXPATHLEN) == NULL)
+      fatal ("`getcwd' failed: %s\n", strerror (errno));
 
   /* Make sure pwd is DIRECTORY_SEP-terminated.
      Maybe this should really use some standard subroutine
@@ -3164,16 +3126,8 @@ init_initial_directory (void)
       }
   }
 
-  /* XEmacs change: store buffer's default directory
-     using preferred (i.e. as defined at compile-time)
-     directory separator. --marcpa */
-#ifdef DOS_NT
-#define CORRECT_DIR_SEPS(s) \
-  do { if ('/' == DIRECTORY_SEP) dostounix_filename (s); \
-       else unixtodos_filename (s); \
-  } while (0)
-
-  CORRECT_DIR_SEPS(initial_directory);
+#ifdef CORRECT_DIR_SEPS
+  CORRECT_DIR_SEPS (initial_directory);
 #endif
 }