]> code.delx.au - gnu-emacs/blobdiff - src/emacs.c
(Fmake_indirect_buffer, Fset_buffer_major_mode, Fpop_to_buffer,
[gnu-emacs] / src / emacs.c
index 226a8e1cd76fbcc2e91a0a34c0b77f1ecd92298f..8c669a0fd61ca3ed1255d7cd0dd6aba8c62c0d93 100644 (file)
@@ -1,5 +1,5 @@
 /* Fully extensible Emacs, running on Unix, intended for GNU.
-   Copyright (C) 1985, 1986, 1987, 1993, 1994 Free Software Foundation, Inc.
+   Copyright (C) 1985, 86, 87, 93, 94, 95 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -35,12 +35,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <sys/ioctl.h>
 #endif
 
-#ifdef APOLLO
-#ifndef APOLLO_SR10
-#include <default_acl.h>
-#endif
-#endif
-
 #include "lisp.h"
 #include "commands.h"
 #include "intervals.h"
@@ -116,9 +110,11 @@ int display_arg;
    Tells GC how to save a copy of the stack.  */
 char *stack_bottom;
 
-#ifdef HAVE_X_WINDOWS
+#ifdef HAVE_WINDOW_SYSTEM
 extern Lisp_Object Vwindow_system;
-#endif /* HAVE_X_WINDOWS */
+#endif /* HAVE_WINDOW_SYSTEM */
+
+extern Lisp_Object Vauto_save_list_file_name;
 
 #ifdef USG_SHARED_LIBRARIES
 /* If nonzero, this is the place to put the end of the writable segment
@@ -222,6 +218,11 @@ init_cmdargs (argc, argv, skip_args)
        Vinvocation_directory = Ffile_name_directory (found);
     }
 
+  if (!NILP (Vinvocation_directory)
+      && NILP (Ffile_name_absolute_p (Vinvocation_directory)))
+    /* Emacs was started with relative path, like ./emacs  */
+    Vinvocation_directory = Fexpand_file_name (Vinvocation_directory, Qnil);
+
   Vinstallation_directory = Qnil;
 
   if (!NILP (Vinvocation_directory))
@@ -308,9 +309,9 @@ DEFUN ("invocation-directory", Finvocation_directory, Sinvocation_directory,
 \f
 #ifdef VMS
 #ifdef LINK_CRTL_SHARE
-#ifdef SHAREABLE_LIB_BUG
+#ifdef SHARABLE_LIB_BUG
 extern noshare char **environ;
-#endif /* SHAREABLE_LIB_BUG */
+#endif /* SHARABLE_LIB_BUG */
 #endif /* LINK_CRTL_SHARE */
 #endif /* VMS */
 
@@ -418,6 +419,10 @@ main (argc, argv, envp)
   extern int errno;
   extern sys_nerr;
 
+#ifdef LINUX_SBRK_BUG
+  __sbrk (1);
+#endif
+
   sort_args (argc, argv);
 
   if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
@@ -453,12 +458,13 @@ main (argc, argv, envp)
 #endif
 
 #ifdef NeXT
-  extern int malloc_cookie;
-
-  /* This helps out unexnext.c.  */
-  if (initialized)
-    if (malloc_jumpstart (malloc_cookie) != 0)
-      printf ("malloc jumpstart failed!\n");
+  {
+    extern int malloc_cookie;
+    /* This helps out unexnext.c.  */
+    if (initialized)
+      if (malloc_jumpstart (malloc_cookie) != 0)
+       printf ("malloc jumpstart failed!\n");
+  }
 #endif /* NeXT */
 
 #ifdef VMS
@@ -470,7 +476,7 @@ main (argc, argv, envp)
   }
 
 #ifdef LINK_CRTL_SHARE
-#ifdef SHAREABLE_LIB_BUG
+#ifdef SHARABLE_LIB_BUG
   /* Bletcherous shared libraries! */
   if (!stdin)
     stdin = fdopen (0, "r");
@@ -480,7 +486,7 @@ main (argc, argv, envp)
     stderr = fdopen (2, "w");
   if (!environ)
     environ = envp;
-#endif /* SHAREABLE_LIB_BUG */
+#endif /* SHARABLE_LIB_BUG */
 #endif /* LINK_CRTL_SHARE */
 #endif /* VMS */
 
@@ -494,20 +500,11 @@ main (argc, argv, envp)
 
 #ifdef USG_SHARED_LIBRARIES
   if (bss_end)
-    brk (bss_end);
+    brk ((void *)bss_end);
 #endif
 
   clearerr (stdin);
 
-#ifdef APOLLO
-#ifndef APOLLO_SR10
-  /* If USE_DOMAIN_ACLS environment variable exists,
-     use ACLs rather than UNIX modes. */
-  if (egetenv ("USE_DOMAIN_ACLS"))
-    default_acl (USE_DEFACL);
-#endif
-#endif /* APOLLO */
-
 #ifndef SYSTEM_MALLOC
   if (! initialized)
     {
@@ -563,7 +560,7 @@ main (argc, argv, envp)
            exit (1);
          }
        fprintf (stderr, "Using %s\n", term);
-#ifdef HAVE_X_WINDOWS
+#ifdef HAVE_WINDOW_SYSTEM
        inhibit_window_system = 1; /* -t => -nw */
 #endif
       }
@@ -582,9 +579,9 @@ main (argc, argv, envp)
       printf ("\
 Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
       [-q] [--no-init-file]  [-u user] [--user user]  [--debug-init]\n\
-\(Arguments above this line must be first; those below may be in any order)\n\
+      [--version] [--no-site-file]\n\
       [-f func] [--funcall func]  [-l file] [--load file]  [--insert file]\n\
-      file-to-visit  [--kill]\n", argv[0]);
+      [+linenum] file-to-visit  [--kill]\n", argv[0]);
       exit (0);
     }
 
@@ -623,7 +620,7 @@ Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
     /* Change --display to -d, when its arg is separate.  */
     else if (displayname != 0 && skip_args > count_before
             && argv[count_before + 1][1] == '-')
-      argv[count_before] = "-d";
+      argv[count_before + 1] = "-d";
 
     /* Don't actually discard this arg.  */
     skip_args = count_before;
@@ -754,6 +751,12 @@ Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
   init_dosfns ();
   /* Set defaults for several environment variables.  */
   if (initialized) init_environment (argc, argv, skip_args);
+  else init_gettimeofday ();
+#endif
+
+#ifdef WINDOWSNT
+  /* Initialize environment from registry settings.  */
+  init_environment ();
 #endif
 
   /* egetenv is a pretty low-level facility, which may get called in
@@ -862,16 +865,24 @@ Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
 #ifdef HAVE_X11
       syms_of_xselect ();
 #endif
-#ifdef HAVE_X_MENU
-      syms_of_xmenu ();
-#endif /* HAVE_X_MENU */
 #endif /* HAVE_X_WINDOWS */
 
 #if defined (MSDOS) && !defined (HAVE_X_WINDOWS)
       syms_of_xfaces ();
-      syms_of_xmenu ();
 #endif
 
+#ifdef HAVE_MENUS
+      syms_of_xmenu ();
+#endif /* HAVE_MENUS */
+
+#ifdef HAVE_NTGUI
+      syms_of_win32term ();
+      syms_of_win32fns ();
+      syms_of_win32faces ();
+      syms_of_win32select ();
+      syms_of_win32menu ();
+#endif /* HAVE_NTGUI */
+
 #ifdef SYMS_SYSTEM
       SYMS_SYSTEM;
 #endif
@@ -906,26 +917,26 @@ Usage: %s [-t term] [--terminal term]  [-nw] [--no-windows]  [--batch]\n\
 #endif /* CANNOT_DUMP */
     }
 
+  if (initialized)
+    {
+      /* Erase any pre-dump messages in the message log, to avoid confusion */
+      Lisp_Object old_log_max;
+      old_log_max = Vmessage_log_max;
+      XSETFASTINT (Vmessage_log_max, 0);
+      message_dolog ("", 0, 1);
+      Vmessage_log_max = old_log_max;
+    }
+
   initialized = 1;
 
-#if defined (sun) || defined (LOCALTIME_CACHE)
-  /* sun's localtime has a bug.  it caches the value of the time
+#ifdef LOCALTIME_CACHE
+  /* Some versions of localtime have a bug.  They cache the value of the time
      zone rather than looking it up every time.  Since localtime() is
      called to bolt the undumping time into the undumped emacs, this
      results in localtime ignoring the TZ environment variable.
      This flushes the new TZ value into localtime. */
   tzset ();
-#endif /* defined (sun) || defined (LOCALTIME_CACHE) */
-
-  /* Handle the GNU standard option --version.  */
-  if (argmatch (argv, argc, "-version", "--version", 3, NULL, &skip_args))
-    {
-      Lisp_Object ver;
-      ver = call0 (intern ("emacs-version"));
-      if (STRINGP (ver))
-       printf ("%s\n", XSTRING (ver)->data);
-      exit (0);
-    }
+#endif /* defined (LOCALTIME_CACHE) */
 
   /* Enter editor command loop.  This never returns.  */
   Frecursive_edit ();
@@ -947,8 +958,12 @@ struct standard_args
 
 struct standard_args standard_args[] =
 {
+  { "-version", "--version", 110, 0 },
+  { "-help", "--help", 110, 0 },
   { "-nl", "--no-shared-memory", 100, 0 },
+#ifdef VMS
   { "-map", "--map-data", 100, 0 },
+#endif
   { "-t", "--terminal", 90, 1 },
   { "-d", "--display", 80, 1 },
   { "-display", 0, 80, 1 },
@@ -960,11 +975,9 @@ struct standard_args standard_args[] =
   { "-u", "--user", 30, 1 },
   { "-user", 0, 30, 1 },
   { "-debug-init", "--debug-init", 20, 0 },
-  { "-l", "--load", 10, 1 },
-  { "-load", 0, 10, 1 },
-  { "-f", "--funcall", 10, 1 },
-  { "-funcall", 0, 10, 1 },
-  { "-insert", "--insert", 10, 1 },
+  { "-i", "--icon-type", 15, 0 },
+  { "-itype", 0, 15, 0 },
+  { "-iconic", "--iconic", 15, 0 },
   { "-bg", "--background-color", 10, 1 },
   { "-background", 0, 10, 1 },
   { "-fg", "--foreground-color", 10, 1 },
@@ -979,16 +992,24 @@ struct standard_args standard_args[] =
   { "-g", "--geometry", 10, 1 },
   { "-geometry", 0, 10, 1 },
   { "-T", "--title", 10, 1 },
-  { "-i", "--icon-type", 10, 1 },
-  { "-itype", 0, 10, 1 },
   { "-name", "--name", 10, 1 },
   { "-xrm", "--xrm", 10, 1 },
-  { "-r", "--reverse-video", 0, 0 },
-  { "-rv", 0, 0, 0 },
-  { "-reverse", 0, 0, 0 },
-  { "-vb", "--vertical-scroll-bars", 0, 0 },
-  { "-iconic", "--iconic", 0, 0 },
-  { "-kill", "--kill", 0, 0 },
+  { "-r", "--reverse-video", 5, 0 },
+  { "-rv", 0, 5, 0 },
+  { "-reverse", 0, 5, 0 },
+  { "-vb", "--vertical-scroll-bars", 5, 0 },
+  /* These have the same priority as ordinary file name args,
+     so they are not reordered with respect to those.  */
+  { "-L", "--directory", 0, 1 },
+  { "-directory", 0, 0, 1 },
+  { "-l", "--load", 0, 1 },
+  { "-load", 0, 0, 1 },
+  { "-f", "--funcall", 0, 1 },
+  { "-funcall", 0, 0, 1 },
+  { "-eval", "--eval", 0, 1 },
+  { "-insert", "--insert", 0, 1 },
+  /* This should be processed after ordinary file name args and the like.  */
+  { "-kill", "--kill", -10, 0 },
 };
 
 /* Reorder the elements of ARGV (assumed to have ARGC elements)
@@ -1018,7 +1039,7 @@ sort_args (argc, argv)
   for (from = 1; from < argc; from++)
     {
       options[from] = -1;
-      priority[from] = -1;
+      priority[from] = 0;
       if (argv[from][0] == '-')
        {
          int match, thislen;
@@ -1045,8 +1066,11 @@ sort_args (argc, argv)
              if (equals != 0)
                thislen = equals - argv[from];
 
-             for (i = 0; i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
-               if (!strncmp (argv[from], standard_args[i].longname, thislen))
+             for (i = 0;
+                  i < sizeof (standard_args) / sizeof (standard_args[0]); i++)
+               if (standard_args[i].longname
+                   && !strncmp (argv[from], standard_args[i].longname,
+                                thislen))
                  {
                    if (match == -1)
                      match = i;
@@ -1075,7 +1099,7 @@ sort_args (argc, argv)
   while (to < argc)
     {
       int best = -1;
-      int best_priority = -2;
+      int best_priority = -9999;
 
       /* Find the highest priority remaining option.
         If several have equal priority, take the first of them.  */
@@ -1140,6 +1164,12 @@ all of which are called before Emacs is actually killed.")
 
   shut_down_emacs (0, 0, STRINGP (arg) ? arg : Qnil);
 
+  /* If we have an auto-save list file,
+     kill it because we are exiting Emacs deliberately (not crashing).
+     Do it after shut_down_emacs, which does an auto-save.  */
+  if (STRINGP (Vauto_save_list_file_name))
+    unlink (XSTRING (Vauto_save_list_file_name)->data);
+
   exit (INTEGERP (arg) ? XINT (arg)
 #ifdef VMS
        : 1
@@ -1225,8 +1255,6 @@ shut_down_emacs (sig, no_x, stuff)
 
 \f
 #ifndef CANNOT_DUMP
-/* Nothing like this can be implemented on an Apollo.
-   What a loss!  */
 
 #ifdef HAVE_SHM
 
@@ -1236,7 +1264,7 @@ This function exists on systems that use HAVE_SHM.")
   (intoname)
      Lisp_Object intoname;
 {
-  extern int my_edata;
+  extern char my_edata[];
   Lisp_Object tem;
 
   CHECK_STRING (intoname, 0);
@@ -1249,7 +1277,7 @@ This function exists on systems that use HAVE_SHM.")
   /* Tell malloc where start of impure now is */
   /* Also arrange for warnings when nearly out of space.  */
 #ifndef SYSTEM_MALLOC
-  memory_warnings (&my_edata, malloc_warning);
+  memory_warnings (my_edata, malloc_warning);
 #endif
   map_out_data (XSTRING (intoname)->data);
 
@@ -1271,7 +1299,7 @@ and announce itself normally when it is run.")
   (intoname, symname)
      Lisp_Object intoname, symname;
 {
-  extern int my_edata;
+  extern char my_edata[];
   Lisp_Object tem;
 
   CHECK_STRING (intoname, 0);
@@ -1296,11 +1324,11 @@ and announce itself normally when it is run.")
 #ifndef WINDOWSNT
   /* On Windows, this was done before dumping, and that once suffices.
      Meanwhile, my_edata is not valid on Windows.  */
-  memory_warnings (&my_edata, malloc_warning);
+  memory_warnings (my_edata, malloc_warning);
 #endif /* not WINDOWSNT */
 #endif
   unexec (XSTRING (intoname)->data,
-         !NILP (symname) ? XSTRING (symname)->data : 0, &my_edata, 0, 0);
+         !NILP (symname) ? XSTRING (symname)->data : 0, my_edata, 0, 0);
 #endif /* not VMS */
 
   Vpurify_flag = tem;
@@ -1338,7 +1366,8 @@ decode_env_path (evarname, defalt)
     {
       p = index (path, SEPCHAR);
       if (!p) p = path + strlen (path);
-      lpath = Fcons (p - path ? make_string (path, p - path) : Qnil,
+      lpath = Fcons (p - path ? make_string (path, p - path)
+                    : build_string ("."),
                     lpath);
       if (*p)
        path = p + 1;
@@ -1385,7 +1414,8 @@ syms_of_emacs ()
     "Hook to be run whenever kill-emacs is called.\n\
 Since kill-emacs may be invoked when the terminal is disconnected (or\n\
 in other similar situations), functions placed on this hook should not\n\
-expect to be able to interact with the user.");
+expect to be able to interact with the user.  To ask for confirmation,\n\
+see `kill-emacs-query-functions' instead.");
   Vkill_emacs_hook = Qnil;
 
   DEFVAR_INT ("emacs-priority", &emacs_priority,