(dired-get-filename)<declare-function>:
[bpt/emacs.git] / lisp / startup.el
index a4f5c6b..1efab62 100644 (file)
@@ -1,7 +1,7 @@
 ;;; startup.el --- process Emacs shell arguments
 
 ;; Copyright (C) 1985, 1986, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+;;   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -49,7 +47,7 @@ directory using `find-file'.  If t, open the `*scratch*' buffer."
   :type '(choice
          (const     :tag "Startup screen" nil)
          (directory :tag "Directory" :value "~/")
-         (file      :tag "File" :value "~/file.txt")
+         (file      :tag "File" :value "~/.emacs")
          (const     :tag "Lisp scratch buffer" t))
   :version "23.1"
   :group 'initialization)
@@ -57,8 +55,8 @@ directory using `find-file'.  If t, open the `*scratch*' buffer."
 (defcustom inhibit-startup-screen nil
   "Non-nil inhibits the startup screen.
 
-This is for use in your personal init file (but NOT site-start.el), once
-you are familiar with the contents of the startup screen."
+This is for use in your personal init file (but NOT site-start.el),
+once you are familiar with the contents of the startup screen."
   :type 'boolean
   :group 'initialization)
 
@@ -68,7 +66,7 @@ you are familiar with the contents of the startup screen."
 (defvar startup-screen-inhibit-startup-screen nil)
 
 (defcustom inhibit-startup-echo-area-message nil
-  "*Non-nil inhibits the initial startup echo area message.
+  "Non-nil inhibits the initial startup echo area message.
 Setting this variable takes effect
 only if you do it with the customization buffer
 or if your `.emacs' file contains a line of this form:
@@ -82,12 +80,12 @@ the startup message unless he personally acts to inhibit it."
   :group 'initialization)
 
 (defcustom inhibit-default-init nil
-  "*Non-nil inhibits loading the `default' library."
+  "Non-nil inhibits loading the `default' library."
   :type 'boolean
   :group 'initialization)
 
 (defcustom inhibit-startup-buffer-menu nil
-  "*Non-nil inhibits display of buffer list when more than 2 files are loaded."
+  "Non-nil inhibits display of buffer list when more than 2 files are loaded."
   :type 'boolean
   :group 'initialization)
 
@@ -136,6 +134,7 @@ This is normally copied from `default-directory' when Emacs starts.")
     ("-fs" 0 x-handle-initial-switch fullscreen fullboth)
     ("-fw" 0 x-handle-initial-switch fullscreen fullwidth)
     ("-fh" 0 x-handle-initial-switch fullscreen fullheight)
+    ("-mm" 0 x-handle-initial-switch fullscreen maximized)
     ("-ib" 1 x-handle-numeric-switch internal-border-width)
     ("-g" 1 x-handle-geometry)
     ("-lsp" 1 x-handle-numeric-switch line-spacing)
@@ -161,6 +160,7 @@ This is normally copied from `default-directory' when Emacs starts.")
     ("--fullscreen" 0 x-handle-initial-switch fullscreen fullboth)
     ("--fullwidth" 0 x-handle-initial-switch fullscreen fullwidth)
     ("--fullheight" 0 x-handle-initial-switch fullscreen fullheight)
+    ("--maximized" 0 x-handle-initial-switch fullscreen maximized)
     ("--internal-border" 1 x-handle-numeric-switch internal-border-width)
     ("--geometry" 1 x-handle-geometry)
     ("--foreground-color" 1 x-handle-switch foreground-color)
@@ -184,6 +184,72 @@ FRAME-PARAM (optional) is the frame parameter this option specifies,
 and VALUE is the value which is given to that frame parameter
 \(most options use the argument for this, so VALUE is not present).")
 
+(defconst command-line-ns-option-alist
+  '(("-NSAutoLaunch" 1 ns-ignore-1-arg)
+    ("-NXAutoLaunch" 1 ns-ignore-1-arg)
+    ("-macosx" 0 ignore)
+    ("-NSHost" 1 ns-ignore-1-arg)
+    ("-_NSMachLaunch" 1 ns-ignore-1-arg)
+    ("-MachLaunch" 1 ns-ignore-1-arg)
+    ("-NXOpen" 1 ns-ignore-1-arg)
+    ("-NSOpen" 1 ns-handle-nxopen)
+    ("-NXOpenTemp" 1 ns-ignore-1-arg)
+    ("-NSOpenTemp" 1 ns-handle-nxopentemp)
+    ("-GSFilePath" 1 ns-handle-nxopen)
+    ;;("-bw" .              x-handle-numeric-switch)
+    ;;("-d" .               x-handle-display)
+    ;;("-display" .         x-handle-display)
+    ("-name" 1 ns-handle-name-switch)
+    ("-title" 1 ns-handle-switch title)
+    ("-T" 1 ns-handle-switch title)
+    ("-r" 0 ns-handle-switch reverse t)
+    ("-rv" 0 ns-handle-switch reverse t)
+    ("-reverse" 0 ns-handle-switch reverse t)
+    ("-fn" 1 ns-handle-switch font)
+    ("-font" 1 ns-handle-switch font)
+    ("-ib" 1 ns-handle-numeric-switch internal-border-width)
+    ;;("-g" .               x-handle-geometry)
+    ;;("-geometry" .        x-handle-geometry)
+    ("-fg" 1 ns-handle-switch foreground-color)
+    ("-foreground" 1 ns-handle-switch foreground-color)
+    ("-bg" 1 ns-handle-switch background-color)
+    ("-background" 1 ns-handle-switch background-color)
+;    ("-ms" 1 ns-handle-switch mouse-color)
+    ("-itype" 0 ns-handle-switch icon-type t)
+    ("-i" 0 ns-handle-switch icon-type t)
+    ("-iconic" 0 ns-handle-iconic icon-type t)
+    ;;("-xrm" .             x-handle-xrm-switch)
+    ("-cr" 1 ns-handle-switch cursor-color)
+    ("-vb" 0 ns-handle-switch vertical-scroll-bars t)
+    ("-hb" 0 ns-handle-switch horizontal-scroll-bars t)
+    ("-bd" 1 ns-handle-switch)
+    ;; ("--border-width" 1 ns-handle-numeric-switch border-width)
+    ;; ("--display" 1 ns-handle-display)
+    ("--name" 1 ns-handle-name-switch)
+    ("--title" 1 ns-handle-switch title)
+    ("--reverse-video" 0 ns-handle-switch reverse t)
+    ("--font" 1 ns-handle-switch font)
+    ("--internal-border" 1 ns-handle-numeric-switch internal-border-width)
+    ;; ("--geometry" 1 ns-handle-geometry)
+    ("--foreground-color" 1 ns-handle-switch foreground-color)
+    ("--background-color" 1 ns-handle-switch background-color)
+    ("--mouse-color" 1 ns-handle-switch mouse-color)
+    ("--icon-type" 0 ns-handle-switch icon-type t)
+    ("--iconic" 0 ns-handle-iconic)
+    ;; ("--xrm" 1 ns-handle-xrm-switch)
+    ("--cursor-color" 1 ns-handle-switch cursor-color)
+    ("--vertical-scroll-bars" 0 ns-handle-switch vertical-scroll-bars t)
+    ("--border-color" 1 ns-handle-switch border-width))
+  "Alist of NS options.
+Each element has the form
+  (NAME NUMARGS HANDLER FRAME-PARAM VALUE)
+where NAME is the option name string, NUMARGS is the number of arguments
+that the option accepts, HANDLER is a function to call to handle the option.
+FRAME-PARAM (optional) is the frame parameter this option specifies,
+and VALUE is the value which is given to that frame parameter
+\(most options use the argument for this, so VALUE is not present).")
+
+
 (defvar before-init-hook nil
   "Normal hook run after handling urgent options but before loading init files.")
 
@@ -193,12 +259,6 @@ There is no `condition-case' around the running of these functions;
 therefore, if you set `debug-on-error' non-nil in `.emacs',
 an error in one of these functions will invoke the debugger.")
 
-(defvar before-init-time nil
-  "Value of `current-time' before Emacs begins initialization.")
-
-(defvar after-init-time nil
-  "Value of `current-time' after loading the init files.")
-
 (defvar emacs-startup-hook nil
   "Normal hook run after loading init files and handling the command line.")
 
@@ -245,7 +305,7 @@ looked for.
 Setting `init-file-user' does not prevent Emacs from loading
 `site-start.el'.  The only way to do that is to use `--no-site-file'.")
 
-(defcustom site-run-file "site-start"
+(defcustom site-run-file (purecopy "site-start")
   "File containing site-wide run-time initializations.
 This file is loaded at run-time before `~/.emacs'.  It contains inits
 that need to be in place for the entire site, but which, due to their
@@ -267,11 +327,11 @@ this variable usefully is to set it while building and dumping Emacs."
   :type '(choice (const :tag "none" nil) string)
   :group 'initialization
   :initialize 'custom-initialize-default
-  :set '(lambda (variable value)
+  :set (lambda (variable value)
          (error "Customizing `site-run-file' does not work")))
 
 (defcustom mail-host-address nil
-  "*Name of this machine, for purposes of naming users."
+  "Name of this machine, for purposes of naming users."
   :type '(choice (const nil) string)
   :group 'mail)
 
@@ -282,9 +342,9 @@ this variable usefully is to set it while building and dumping Emacs."
                                                 (system-name))))
                               ;; Empty string means "not set yet".
                               "")
-  "*Full mailing address of this user.
+  "Full mailing address of this user.
 This is initialized with environment variable `EMAIL' or, as a
-fallback, using `mail-host-address'. This is done after your
+fallback, using `mail-host-address'.  This is done after your
 init file is read, in case it sets `mail-host-address'."
   :type 'string
   :group 'mail)
@@ -306,8 +366,6 @@ from being initialized."
                 string)
   :group 'auto-save)
 
-(defvar emacs-quick-startup nil)
-
 (defvar emacs-basic-display nil)
 
 (defvar init-file-debug nil)
@@ -324,17 +382,16 @@ from being initialized."
 (defvar pure-space-overflow nil
   "Non-nil if building Emacs overflowed pure space.")
 
-(defvar pure-space-overflow-message "\
+(defvar pure-space-overflow-message (purecopy "\
 Warning Warning!!!  Pure space overflow    !!!Warning Warning
-\(See the node Pure Storage in the Lisp manual for details.)\n")
-
-(defvar tutorial-directory nil
-  "Directory containing the Emacs TUTORIAL files.")
+\(See the node Pure Storage in the Lisp manual for details.)\n"))
 
-;; Get correct value in a dumped, installed Emacs.
-(eval-at-startup
- (setq tutorial-directory (file-name-as-directory
-                           (expand-file-name "tutorials" data-directory))))
+(defcustom tutorial-directory
+  (file-name-as-directory (expand-file-name "tutorials" data-directory))
+  "Directory containing the Emacs TUTORIAL files."
+  :group 'installation
+  :type 'directory
+  :initialize 'custom-initialize-delay)
 
 (defun normal-top-level-add-subdirs-to-load-path ()
   "Add all subdirectories of current directory to `load-path'.
@@ -398,10 +455,12 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
   (if command-line-processed
       (message "Back to top level.")
     (setq command-line-processed t)
-    ;; Give *Messages* the same default-directory as *scratch*,
-    ;; just to keep things predictable.
     (let ((dir default-directory))
       (with-current-buffer "*Messages*"
+        ;; Make it easy to do like "tail -f".
+        (set (make-local-variable 'window-point-insertion-type) t)
+        ;; Give *Messages* the same default-directory as *scratch*,
+        ;; just to keep things predictable.
        (setq default-directory dir)))
     ;; `user-full-name' is now known; reset its standard-value here.
     (put 'user-full-name 'standard-value
@@ -425,22 +484,21 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
         ;; the end, because the subdirs.el files may add elements to the end
         ;; of load-path and we want to take it into account.
         (setq tail (cdr tail))))
-    (unless (eq system-type 'vax-vms)
-      ;; If the PWD environment variable isn't accurate, delete it.
-      (let ((pwd (getenv "PWD")))
-       (and (stringp pwd)
-            ;; Use FOO/., so that if FOO is a symlink, file-attributes
-            ;; describes the directory linked to, not FOO itself.
-            (or (equal (file-attributes
-                        (concat (file-name-as-directory pwd) "."))
-                       (file-attributes
-                        (concat (file-name-as-directory default-directory)
-                                ".")))
-                (setq process-environment
-                      (delete (concat "PWD=" pwd)
-                              process-environment))))))
+    ;; If the PWD environment variable isn't accurate, delete it.
+    (let ((pwd (getenv "PWD")))
+      (and (stringp pwd)
+          ;; Use FOO/., so that if FOO is a symlink, file-attributes
+          ;; describes the directory linked to, not FOO itself.
+          (or (equal (file-attributes
+                      (concat (file-name-as-directory pwd) "."))
+                     (file-attributes
+                      (concat (file-name-as-directory default-directory)
+                              ".")))
+              (setq process-environment
+                    (delete (concat "PWD=" pwd)
+                            process-environment)))))
     (setq default-directory (abbreviate-file-name default-directory))
-    (let ((menubar-bindings-done nil))
+    (let ((old-face-font-rescale-alist face-font-rescale-alist))
       (unwind-protect
          (command-line)
        ;; Do this again, in case .emacs defined more abbreviations.
@@ -481,6 +539,19 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
                  (not (and initial-window-system
                            (not noninteractive)
                            (not (eq initial-window-system 'pc)))))
+
+         ;; FIXME: The user's init file may change
+         ;; face-font-rescale-alist.  However, the default face
+         ;; already has an assigned font object, which does not take
+         ;; face-font-rescale-alist into account.  For such
+         ;; situations, we ought to have a way to find all font
+         ;; objects and regenerate them; currently we do not.  As a
+         ;; workaround, we specifically reset te default face's :font
+         ;; attribute here.  See bug#1785.
+         (unless (eq face-font-rescale-alist
+                     old-face-font-rescale-alist)
+           (set-face-attribute 'default nil :font (font-spec)))
+
          ;; Modify the initial frame based on what .emacs puts into
          ;; ...-frame-alist.
          (if (fboundp 'frame-notice-user-settings)
@@ -496,10 +567,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
        (if (fboundp 'font-menu-add-default)
            (font-menu-add-default))
        (and window-setup-hook
-            (run-hooks 'window-setup-hook))
-       (or menubar-bindings-done
-           (if (display-popup-menus-p)
-               (precompute-menubar-bindings)))))
+            (run-hooks 'window-setup-hook))))
     ;; Subprocesses of Emacs do not have direct access to the terminal, so
     ;; unless told otherwise they should only assume a dumb terminal.
     ;; We are careful to do it late (after term-setup-hook), although the
@@ -520,20 +588,6 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
         (delete display process-environment)))))
 
 ;; Precompute the keyboard equivalents in the menu bar items.
-(defun precompute-menubar-bindings ()
-  (let ((submap (lookup-key global-map [menu-bar])))
-    (while submap
-      (and (consp (car submap))
-          (symbolp (car (car submap)))
-          (stringp (car-safe (cdr (car submap))))
-          (keymapp (cdr (cdr (car submap))))
-          (progn
-            (x-popup-menu nil (cdr (cdr (car submap))))
-            (if purify-flag
-                (garbage-collect))))
-      (setq submap (cdr submap))))
-    (setq define-key-rebound-commands t))
-
 ;; Command-line options supported by tty's:
 (defconst tty-long-option-alist
   '(("--name"            . "-name")
@@ -544,7 +598,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
     ("--color"           . "-color")))
 
 (defconst tool-bar-images-pixel-height 24
-  "Height in pixels of images in the tool bar.")
+  "Height in pixels of images in the tool-bar.")
 
 (defvar tool-bar-originally-present nil
   "Non-nil if tool-bars are present before user and site init files are read.")
@@ -629,14 +683,21 @@ opening the first frame (e.g. open a connection to an X server).")
                (push argi rest)))))
     (nreverse rest)))
 
+(declare-function x-get-resource "frame.c"
+                 (attribute class &optional component subclass))
+(declare-function tool-bar-mode "tool-bar" (&optional arg))
+(declare-function tool-bar-setup "tool-bar")
+
+(defvar server-name)
+(defvar server-process)
+
 (defun command-line ()
   (setq before-init-time (current-time)
+       after-init-time nil
         command-line-default-directory default-directory)
 
-  ;; Choose a reasonable location for temporary files.
-  (custom-reevaluate-setting 'temporary-file-directory)
-  (custom-reevaluate-setting 'small-temporary-file-directory)
-  (custom-reevaluate-setting 'auto-save-file-name-transforms)
+  ;; Force recomputation, in case it was computed during the dump.
+  (setq abbreviated-home-dir nil)
 
   ;; See if we should import version-control from the environment variable.
   (let ((vc (getenv "VERSION_CONTROL")))
@@ -657,51 +718,13 @@ opening the first frame (e.g. open a connection to an X server).")
   ;; Set the default strings to display in mode line for
   ;; end-of-line formats that aren't native to this platform.
   (cond
-   ((memq system-type '(ms-dos windows-nt emx))
+   ((memq system-type '(ms-dos windows-nt))
     (setq eol-mnemonic-unix "(Unix)"
           eol-mnemonic-mac  "(Mac)"))
-   ;; Both Mac and Unix EOLs are now "native" on Mac OS so keep the
-   ;; abbreviated strings `/' and `:' set in coding.c for them.
-   ((eq system-type 'macos)
-    (setq eol-mnemonic-dos  "(DOS)"))
    (t                                   ; this is for Unix/GNU/Linux systems
     (setq eol-mnemonic-dos  "(DOS)"
           eol-mnemonic-mac  "(Mac)")))
 
-  ;; Make sure window system's init file was loaded in loadup.el if using a window system.
-  (condition-case error
-    (unless noninteractive
-      (if (and initial-window-system
-              (not (featurep
-                    (intern (concat (symbol-name initial-window-system) "-win")))))
-         (error "Unsupported window system `%s'" initial-window-system))
-      ;; Process window-system specific command line parameters.
-      (setq command-line-args
-           (funcall (or (cdr (assq initial-window-system handle-args-function-alist))
-                        (error "Unsupported window system `%s'" initial-window-system))
-                    command-line-args))
-      ;; Initialize the window system. (Open connection, etc.)
-      (funcall (or (cdr (assq initial-window-system window-system-initialization-alist))
-                  (error "Unsupported window system `%s'" initial-window-system))))
-    ;; If there was an error, print the error message and exit.
-    (error
-     (princ
-      (if (eq (car error) 'error)
-         (apply 'concat (cdr error))
-       (if (memq 'file-error (get (car error) 'error-conditions))
-           (format "%s: %s"
-                    (nth 1 error)
-                    (mapconcat (lambda (obj) (prin1-to-string obj t))
-                               (cdr (cdr error)) ", "))
-         (format "%s: %s"
-                  (get (car error) 'error-message)
-                  (mapconcat (lambda (obj) (prin1-to-string obj t))
-                             (cdr error) ", "))))
-      'external-debugging-output)
-     (terpri 'external-debugging-output)
-     (setq initial-window-system nil)
-     (kill-emacs)))
-
   (set-locale-environment nil)
 
   ;; Convert preloaded file names in load-history to absolute.
@@ -756,10 +779,10 @@ opening the first frame (e.g. open a connection to an X server).")
              (orig-argi argi)
              argval)
        ;; Handle --OPTION=VALUE format.
-       (when (string-match "^\\(--[^=]*\\)=" argi)
+       (when (string-match "\\`\\(--[^=]*\\)=" argi)
          (setq argval (substring argi (match-end 0))
                 argi (match-string 1 argi)))
-       (unless (equal argi "--")
+       (when (string-match "\\`--." orig-argi)
          (let ((completion (try-completion argi longopts)))
            (if (eq completion t)
                (setq argi (substring argi 1))
@@ -774,7 +797,7 @@ opening the first frame (e.g. open a connection to an X server).")
         ((member argi '("-Q" "-quick"))
          (setq init-file-user nil
                site-run-file nil
-               emacs-quick-startup t))
+               inhibit-x-resources t))
         ((member argi '("-D" "-basic-display"))
          (setq no-blinking-cursor t
                emacs-basic-display t)
@@ -806,17 +829,57 @@ opening the first frame (e.g. open a connection to an X server).")
     (and command-line-args
          (setcdr command-line-args args)))
 
+  ;; Make sure window system's init file was loaded in loadup.el if
+  ;; using a window system.
+  ;; Initialize the window-system only after processing the command-line
+  ;; args so that -Q can influence this initialization.
+  (condition-case error
+    (unless noninteractive
+      (if (and initial-window-system
+              (not (featurep
+                    (intern
+                     (concat (symbol-name initial-window-system) "-win")))))
+         (error "Unsupported window system `%s'" initial-window-system))
+      ;; Process window-system specific command line parameters.
+      (setq command-line-args
+           (funcall
+            (or (cdr (assq initial-window-system handle-args-function-alist))
+                (error "Unsupported window system `%s'" initial-window-system))
+            command-line-args))
+      ;; Initialize the window system. (Open connection, etc.)
+      (funcall
+       (or (cdr (assq initial-window-system window-system-initialization-alist))
+          (error "Unsupported window system `%s'" initial-window-system))))
+    ;; If there was an error, print the error message and exit.
+    (error
+     (princ
+      (if (eq (car error) 'error)
+         (apply 'concat (cdr error))
+       (if (memq 'file-error (get (car error) 'error-conditions))
+           (format "%s: %s"
+                    (nth 1 error)
+                    (mapconcat (lambda (obj) (prin1-to-string obj t))
+                               (cdr (cdr error)) ", "))
+         (format "%s: %s"
+                  (get (car error) 'error-message)
+                  (mapconcat (lambda (obj) (prin1-to-string obj t))
+                             (cdr error) ", "))))
+      'external-debugging-output)
+     (terpri 'external-debugging-output)
+     (setq initial-window-system nil)
+     (kill-emacs)))
+
   (run-hooks 'before-init-hook)
 
   ;; Under X Window, this creates the X frame and deletes the terminal frame.
-  (when (fboundp 'frame-initialize)
+  (unless (daemonp)
     (frame-initialize))
 
   ;; Turn off blinking cursor if so specified in X resources.  This is here
   ;; only because all other settings of no-blinking-cursor are here.
   (unless (or noninteractive
              emacs-basic-display
-             (and (memq window-system '(x w32 mac))
+             (and (memq window-system '(x w32 ns))
                   (not (member (x-get-resource "cursorBlink" "CursorBlink")
                                '("off" "false")))))
     (setq no-blinking-cursor t))
@@ -828,26 +891,25 @@ opening the first frame (e.g. open a connection to an X server).")
                    (<= (frame-parameter nil 'menu-bar-lines) 0)))
     (menu-bar-mode 1))
 
-  ;; If frame was created with a tool bar, switch tool-bar-mode on.
-  (unless (or noninteractive
-             emacs-basic-display
-              (not (display-graphic-p))
-              (<= (frame-parameter nil 'tool-bar-lines) 0))
-    (tool-bar-mode 1))
-
-  ;; Can't do this init in defcustom because the relevant variables
-  ;; are not set.
-  (custom-reevaluate-setting 'blink-cursor-mode)
-  (custom-reevaluate-setting 'tooltip-mode)
-  (custom-reevaluate-setting 'global-font-lock-mode)
-  (custom-reevaluate-setting 'mouse-wheel-down-event)
-  (custom-reevaluate-setting 'mouse-wheel-up-event)
-  (custom-reevaluate-setting 'file-name-shadow-mode)
-  (custom-reevaluate-setting 'send-mail-function)
-  (custom-reevaluate-setting 'focus-follows-mouse)
-  (custom-reevaluate-setting 'global-auto-composition-mode)
-  (custom-reevaluate-setting 'transient-mark-mode)
-  (custom-reevaluate-setting 'auto-encryption-mode)
+  (unless (or noninteractive (not (fboundp 'tool-bar-mode)))
+    ;; Set up the tool-bar.  Do this even in tty frames, so that there
+    ;; is a tool-bar if Emacs later opens a graphical frame.
+    (if (or emacs-basic-display
+           (and (numberp (frame-parameter nil 'tool-bar-lines))
+                (<= (frame-parameter nil 'tool-bar-lines) 0)))
+       ;; On a graphical display with the toolbar disabled via X
+       ;; resources, set up the toolbar without enabling it.
+       (tool-bar-setup)
+      ;; Otherwise, enable tool-bar-mode.
+      (tool-bar-mode 1)))
+
+  ;; Re-evaluate predefined variables whose initial value depends on
+  ;; the runtime context.
+  (mapc 'custom-reevaluate-setting
+        ;; Initialize them in the same order they were loaded, in case there
+        ;; are dependencies between them.
+        (prog1 (nreverse custom-delayed-init-variables)
+          (setq custom-delayed-init-variables nil)))
 
   (normal-erase-is-backspace-setup-frame)
 
@@ -857,7 +919,11 @@ opening the first frame (e.g. open a connection to an X server).")
   ;; since users can connect to color-capable terminals and also
   ;; switch color support on or off in mid-session by setting the
   ;; tty-color-mode frame parameter.
-  (tty-register-default-colors)
+  ;; Exception: the `pc' ``window system'' has only 16 fixed colors,
+  ;; and they are already set at this point by a suitable function in
+  ;; window-system-initialization-alist.
+  (or (eq initial-window-system 'pc)
+      (tty-register-default-colors))
 
   ;; Record whether the tool-bar is present before the user and site
   ;; init files are processed.  frame-notice-user-settings uses this
@@ -897,13 +963,15 @@ opening the first frame (e.g. open a connection to an X server).")
                                   init-file-user)
                           :error)
        (if (file-directory-p (expand-file-name
-                              ;; We don't support ~USER on MS-Windows except
-                              ;; for the current user, and always load .emacs
-                              ;; from the current user's home directory (see
-                              ;; below).  So always check "~", even if invoked
-                              ;; with "-u USER", or if $USER or $LOGNAME are
-                              ;; set to something different.
-                              (if (eq system-type 'windows-nt)
+                              ;; We don't support ~USER on MS-Windows
+                              ;; and MS-DOS except for the current
+                              ;; user, and always load .emacs from
+                              ;; the current user's home directory
+                              ;; (see below).  So always check "~",
+                              ;; even if invoked with "-u USER", or
+                              ;; if $USER or $LOGNAME are set to
+                              ;; something different.
+                              (if (memq system-type '(windows-nt ms-dos))
                                   "~"
                                 (concat "~" init-file-user))))
            nil
@@ -917,7 +985,7 @@ opening the first frame (e.g. open a connection to an X server).")
          debug-on-error-should-be-set
          (debug-on-error-initial
           (if (eq init-file-debug t) 'startup init-file-debug))
-         (orig-enable-multibyte default-enable-multibyte-characters))
+         (orig-enable-multibyte (default-value 'enable-multibyte-characters)))
       (let ((debug-on-error debug-on-error-initial)
            ;; This function actually reads the init files.
            (inner
@@ -937,8 +1005,6 @@ opening the first frame (e.g. open a connection to an X server).")
                                   "~/_emacs"
                                 ;; But default to .emacs if _emacs does not exist.
                                 "~/.emacs")))
-                           ((eq system-type 'vax-vms)
-                            "sys$login:.emacs")
                            (t
                             (concat "~" init-file-user "/.emacs")))))
                      ;; This tells `load' to store the file name found
@@ -995,29 +1061,20 @@ opening the first frame (e.g. open a connection to an X server).")
                (funcall inner)
                (setq init-file-had-error nil))
            (error
-            (let ((message-log-max nil))
-              (save-excursion
-                (set-buffer (get-buffer-create "*Messages*"))
-                (insert "\n\n"
-                        (format "An error has occurred while loading `%s':\n\n"
-                                user-init-file)
-                        (format "%s%s%s"
-                                (get (car error) 'error-message)
-                                (if (cdr error) ": " "")
-                                (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
-                        "\n\n"
-                        "To ensure normal operation, you should investigate and remove the\n"
-                        "cause of the error in your initialization file.  Start Emacs with\n"
-                        "the `--debug-init' option to view a complete error backtrace.\n\n"))
-              (message "Error in init file: %s%s%s"
-                       (get (car error) 'error-message)
-                       (if (cdr error) ": " "")
-                       (mapconcat 'prin1-to-string (cdr error) ", "))
-              (let ((pop-up-windows nil))
-                (pop-to-buffer "*Messages*"))
-              (setq init-file-had-error t)))))
-
-       (if (and deactivate-mark transient-mark-mode)
+            (display-warning
+             'initialization
+             (format "An error occurred while loading `%s':\n\n%s%s%s\n\n\
+To ensure normal operation, you should investigate and remove the
+cause of the error in your initialization file.  Start Emacs with
+the `--debug-init' option to view a complete error backtrace."
+                     user-init-file
+                     (get (car error) 'error-message)
+                     (if (cdr error) ": " "")
+                     (mapconcat (lambda (s) (prin1-to-string s t)) (cdr error) ", "))
+             :warning)
+            (setq init-file-had-error t))))
+
+      (if (and deactivate-mark transient-mark-mode)
            (with-current-buffer (window-buffer)
              (deactivate-mark)))
 
@@ -1038,8 +1095,9 @@ opening the first frame (e.g. open a connection to an X server).")
                  debug-on-error-from-init-file debug-on-error)))
       (if debug-on-error-should-be-set
          (setq debug-on-error debug-on-error-from-init-file))
-      (unless (or default-enable-multibyte-characters
-                 (eq orig-enable-multibyte default-enable-multibyte-characters))
+      (unless (or (default-value 'enable-multibyte-characters)
+                 (eq orig-enable-multibyte (default-value
+                                             'enable-multibyte-characters)))
        ;; Init file changed to unibyte.  Reset existing multibyte
        ;; buffers (probably *scratch*, *Messages*, *Minibuff-0*).
        ;; Arguably this should only be done if they're free of
@@ -1105,7 +1163,7 @@ opening the first frame (e.g. open a connection to an X server).")
   (run-hooks 'after-init-hook)
 
   ;; Decode all default-directory.
-  (if (and default-enable-multibyte-characters locale-coding-system)
+  (if (and (default-value 'enable-multibyte-characters) locale-coding-system)
       (save-excursion
        (dolist (elt (buffer-list))
          (set-buffer elt)
@@ -1141,6 +1199,23 @@ opening the first frame (e.g. open a connection to an X server).")
   ;; If -batch, terminate after processing the command options.
   (if noninteractive (kill-emacs t))
 
+  ;; In daemon mode, start the server to allow clients to connect.
+  ;; This is done after loading the user's init file and after
+  ;; processing all command line arguments to allow e.g. `server-name'
+  ;; to be changed before the server starts.
+  (let ((dn (daemonp)))
+    (when dn
+      (when (stringp dn) (setq server-name dn))
+      (server-start)
+      (if server-process
+         (daemon-initialized)
+       (if (stringp dn)
+           (message
+            "Unable to start daemon: Emacs server named %S already running"
+            server-name)
+         (message "Unable to start the daemon.\nAnother instance of Emacs is running the server, either as daemon or interactively.\nYou can use emacsclient to connect to that Emacs process."))
+       (kill-emacs 1))))
+
   ;; Run emacs-session-restore (session management) if started by
   ;; the session manager and we have a session manager connection.
   (if (and (boundp 'x-session-previous-id)
@@ -1165,7 +1240,7 @@ If this is nil, no message will be displayed."
 ;;; Fancy splash screen
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defvar fancy-startup-text
+(defconst fancy-startup-text
   '((:face (variable-pitch (:foreground "red"))
      "Welcome to "
      :link ("GNU Emacs"
@@ -1180,10 +1255,8 @@ If this is nil, no message will be displayed."
             "Browse http://www.gnu.org/gnu/linux-and-gnu.html")
         '("GNU" (lambda (button) (describe-gnu-project))
           "Display info on the GNU project")))
-     " operating system.\n"
-     :face variable-pitch "To quit a partially entered command, type "
-     :face default "Control-g"
-     :face variable-pitch ".\n\n"
+     " operating system.\n\n"
+     :face variable-pitch
      :link ("Emacs Tutorial" (lambda (button) (help-with-tutorial)))
      "\tLearn basic keystroke commands"
      (lambda ()
@@ -1203,11 +1276,10 @@ If this is nil, no message will be displayed."
             ""
           (concat " (" title ")"))))
      "\n"
-     :face variable-pitch
      :link ("Emacs Guided Tour"
            (lambda (button) (browse-url "http://www.gnu.org/software/emacs/tour/"))
            "Browse http://www.gnu.org/software/emacs/tour/")
-     "\tOverview of Emacs features\n"
+     "\tOverview of Emacs features at gnu.org\n"
      :link ("View Emacs Manual" (lambda (button) (info-emacs-manual)))
      "\tView the Emacs manual using Info\n"
      :link ("Absence of Warranty" (lambda (button) (describe-no-warranty)))
@@ -1224,7 +1296,7 @@ If this is nil, no message will be displayed."
 Each element in the list should be a list of strings or pairs
 `:face FACE', like `fancy-splash-insert' accepts them.")
 
-(defvar fancy-about-text
+(defconst fancy-about-text
   '((:face (variable-pitch (:foreground "red"))
      "This is "
      :link ("GNU Emacs"
@@ -1248,7 +1320,7 @@ Each element in the list should be a list of strings or pairs
      "\n"
      (lambda () (emacs-version))
      "\n"
-     :face (variable-pitch (:height 0.5))
+     :face (variable-pitch (:height 0.8))
      (lambda () emacs-copyright)
      "\n\n"
      :face variable-pitch
@@ -1312,7 +1384,7 @@ Each element in the list should be a list of strings or pairs
   :group 'initialization)
 
 (defcustom fancy-splash-image nil
-  "*The image to show in the splash screens, or nil for defaults."
+  "The image to show in the splash screens, or nil for defaults."
   :group 'fancy-splash-screen
   :type '(choice (const :tag "Default" nil)
                 (file :tag "File")))
@@ -1366,18 +1438,25 @@ a face or button specification."
                                   'help-echo (startup-echo-area-message)))))
       (setq args (cdr args)))))
 
+(declare-function image-size "image.c" (spec &optional pixels frame))
 
 (defun fancy-splash-head ()
   "Insert the head part of the splash screen into the current buffer."
   (let* ((image-file (cond ((stringp fancy-splash-image)
                            fancy-splash-image)
-                          ((and (display-color-p)
-                                (image-type-available-p 'xpm))
-                            (if (and (fboundp 'x-display-planes)
-                                     (= (funcall 'x-display-planes) 8))
-                                "splash8.xpm"
-                              "splash.xpm"))
-                            (t "splash.pbm")))
+                          ((display-color-p)
+                           (cond ((<= (display-planes) 8)
+                                  (if (image-type-available-p 'xpm)
+                                      "splash.xpm"
+                                    "splash.pbm"))
+                                 ((image-type-available-p 'svg)
+                                  "splash.svg")
+                                 ((image-type-available-p 'png)
+                                  "splash.png")
+                                 ((image-type-available-p 'xpm)
+                                  "splash.xpm")
+                                 (t "splash.pbm")))
+                          (t "splash.pbm")))
         (img (create-image image-file))
         (image-width (and img (car (image-size img))))
         (window-width (window-width (selected-window))))
@@ -1421,11 +1500,15 @@ a face or button specification."
               (lambda (button) (customize-group 'initialization))
               "Change initialization settings including this screen")
        "\n"))
+    (fancy-splash-insert
+     :face 'variable-pitch "To quit a partially entered command, type "
+     :face 'default "Control-g"
+     :face 'variable-pitch ".\n")
     (fancy-splash-insert :face `(variable-pitch (:foreground ,fg))
                         "\nThis is "
                         (emacs-version)
                         "\n"
-                        :face '(variable-pitch (:height 0.5))
+                        :face '(variable-pitch (:height 0.8))
                         emacs-copyright
                         "\n")
     (and auto-save-list-file-prefix
@@ -1713,64 +1796,45 @@ To quit a partially entered command, type Control-g.\n")
 
   ;; If keys have their default meanings,
   ;; use precomputed string to save lots of time.
-  (if (and (eq (key-binding "\C-h") 'help-command)
-          (eq (key-binding "\C-xu") 'advertised-undo)
-          (eq (key-binding "\C-x\C-c") 'save-buffers-kill-terminal)
-          (eq (key-binding "\C-ht") 'help-with-tutorial)
-          (eq (key-binding "\C-hi") 'info)
-          (eq (key-binding "\C-hr") 'info-emacs-manual)
-          (eq (key-binding "\C-h\C-n") 'view-emacs-news))
-      (progn
-       (insert "
-Get help\t   C-h  (Hold down CTRL and press h)
-")
-       (insert-button "Emacs manual"
-                      'action (lambda (button) (info-emacs-manual))
-                      'follow-link t)
-       (insert "          C-h r\t")
-       (insert-button "Browse manuals"
-                      'action (lambda (button) (Info-directory))
-                      'follow-link t)
-       (insert "\t   C-h i
-")
-       (insert-button "Emacs tutorial"
-                      'action (lambda (button) (help-with-tutorial))
-                      'follow-link t)
-       (insert "          C-h t\tUndo changes\t   C-x u
-")
-       (insert-button "Buy manuals"
-                      'action (lambda (button) (view-order-manuals))
-                      'follow-link t)
-       (insert "\t   C-h C-m\tExit Emacs\t   C-x C-c"))
-
-    (insert (format "
-Get help\t   %s
-"
-                   (let ((where (where-is-internal
-                                 'help-command nil t)))
-                     (if where
-                         (key-description where)
-                       "M-x help"))))
+  (let* ((c-h-accessible
+          ;; If normal-erase-is-backspace is used on a tty, there's
+          ;; no way to invoke C-h and you have to use F1 instead.
+          (or (not (char-table-p keyboard-translate-table))
+              (eq (aref keyboard-translate-table ?\C-h) ?\C-h)))
+         (minor-mode-overriding-map-alist
+          (cons (cons (not c-h-accessible)
+                      ;; If C-h can't be invoked, temporarily disable its
+                      ;; binding, so where-is uses alternative bindings.
+                      (let ((map (make-sparse-keymap)))
+                        (define-key map [?\C-h] 'undefined)
+                        map))
+                minor-mode-overriding-map-alist)))
+
+    (insert (format "\nGet help\t   %s\n"
+                    (let ((where (where-is-internal 'help-command nil t)))
+                      (cond
+                       ((equal where [?\C-h])
+                        "C-h  (Hold down CTRL and press h)")
+                       (where (key-description where))
+                       (t "M-x help")))))
     (insert-button "Emacs manual"
-                  'action (lambda (button) (info-emacs-manual))
-                  'follow-link t)
+                   'action (lambda (button) (info-emacs-manual))
+                   'follow-link t)
     (insert (substitute-command-keys"\t   \\[info-emacs-manual]\t"))
     (insert-button "Browse manuals"
-                  'action (lambda (button) (Info-directory))
-                  'follow-link t)
-    (insert (substitute-command-keys "\t   \\[info]
-"))
+                   'action (lambda (button) (Info-directory))
+                   'follow-link t)
+    (insert (substitute-command-keys "\t   \\[info]\n"))
     (insert-button "Emacs tutorial"
-                  'action (lambda (button) (help-with-tutorial))
-                  'follow-link t)
+                   'action (lambda (button) (help-with-tutorial))
+                   'follow-link t)
     (insert (substitute-command-keys
-            "\t   \\[help-with-tutorial]\tUndo changes\t   \\[advertised-undo]
-"))
+             "\t   \\[help-with-tutorial]\tUndo changes\t   \\[undo]\n"))
     (insert-button "Buy manuals"
-                  'action (lambda (button) (view-order-manuals))
-                  'follow-link t)
+                   'action (lambda (button) (view-order-manuals))
+                   'follow-link t)
     (insert (substitute-command-keys
-            "\t   \\[view-order-manuals]\tExit Emacs\t   \\[save-buffers-kill-terminal]")))
+             "\t   \\[view-order-manuals]\tExit Emacs\t   \\[save-buffers-kill-terminal]")))
 
   ;; Say how to use the menu bar with the keyboard.
   (insert "\n")
@@ -1898,12 +1962,14 @@ Type \\[describe-distribution] for information on "))
   (insert "\tBuying printed manuals from the FSF\n"))
 
 (defun startup-echo-area-message ()
-  (if (eq (key-binding "\C-h\C-a") 'about-emacs)
-      "For information about GNU Emacs and the GNU system, type C-h C-a."
-    (substitute-command-keys
-     "For information about GNU Emacs and the GNU system, type \
-\\[about-emacs].")))
-
+  (cond ((daemonp)
+        "Starting Emacs daemon.")
+       ((eq (key-binding "\C-h\C-a") 'about-emacs)
+        "For information about GNU Emacs and the GNU system, type C-h C-a.")
+       (t
+        (substitute-command-keys
+         "For information about GNU Emacs and the GNU system, type \
+\\[about-emacs]."))))
 
 (defun display-startup-echo-area-message ()
   (let ((resize-mini-windows t))
@@ -1920,8 +1986,7 @@ Type \\[describe-distribution] for information on "))
                 (let ((buffer (get-buffer-create " *temp*")))
                   (prog1
                       (condition-case nil
-                          (save-excursion
-                            (set-buffer buffer)
+                          (with-current-buffer buffer
                             (insert-file-contents user-init-file)
                             (re-search-forward
                              (concat
@@ -1963,25 +2028,23 @@ A fancy display is used on graphic displays, normal otherwise."
 
 (defun command-line-1 (command-line-args-left)
   (display-startup-echo-area-message)
-
-  ;; Delay 2 seconds after an init file error message
-  ;; was displayed, so user can read it.
-  (when init-file-had-error
-    (sit-for 2))
-
   (when (and pure-space-overflow
             (not noninteractive))
     (display-warning
      'initialization
-     "Building Emacs overflowed pure space.  (See the node Pure Storage in the Lisp manual for details.)"
+     "Building Emacs overflowed pure space.\
+  (See the node Pure Storage in the Lisp manual for details.)"
      :warning))
 
   (let ((file-count 0)
        first-file-buffer)
     (when command-line-args-left
       ;; We have command args; process them.
-      (let ((dir command-line-default-directory)
-           tem
+      ;; Note that any local variables in this function affect the
+      ;; ability of -f batch-byte-compile to detect free variables.
+      ;; So we give some of them with common names a cl1- prefix.
+      (let ((cl1-dir command-line-default-directory)
+           cl1-tem
            ;; This approach loses for "-batch -L DIR --eval "(require foo)",
            ;; if foo is intended to be found in DIR.
            ;;
@@ -1999,17 +2062,21 @@ A fancy display is used on graphic displays, normal otherwise."
            ;; This includes our standard options' long versions
            ;; and long versions of what's on command-switch-alist.
            (longopts
-            (append '(("--funcall") ("--load") ("--insert") ("--kill")
-                      ("--directory") ("--eval") ("--execute") ("--no-splash")
-                      ("--find-file") ("--visit") ("--file") ("--no-desktop"))
-                    (mapcar (lambda (elt)
-                              (list (concat "-" (car elt))))
+           (append '("--funcall" "--load" "--insert" "--kill"
+                     "--directory" "--eval" "--execute" "--no-splash"
+                     "--find-file" "--visit" "--file" "--no-desktop")
+                   (mapcar (lambda (elt) (concat "-" (car elt)))
                             command-switch-alist)))
-           (line 0)
-           (column 0))
+           (cl1-line 0)
+           (cl1-column 0))
 
        ;; Add the long X options to longopts.
        (dolist (tem command-line-x-option-alist)
+         (if (string-match "^--" (car tem))
+            (push (car tem) longopts)))
+
+       ;; Add the long NS options to longopts.
+       (dolist (tem command-line-ns-option-alist)
          (if (string-match "^--" (car tem))
              (push (list (car tem)) longopts)))
 
@@ -2026,29 +2093,28 @@ A fancy display is used on graphic displays, normal otherwise."
                (setq argi "")
              ;; Convert long options to ordinary options
              ;; and separate out an attached option argument into argval.
-             (when (string-match "^\\(--[^=]*\\)=" argi)
+             (when (string-match "\\`\\(--[^=]*\\)=" argi)
                (setq argval (substring argi (match-end 0))
                      argi (match-string 1 argi)))
-             (if (equal argi "--")
-                 (setq completion nil)
-               (setq completion (try-completion argi longopts)))
-             (if (eq completion t)
-                 (setq argi (substring argi 1))
-               (if (stringp completion)
-                   (let ((elt (assoc completion longopts)))
-                     (or elt
-                         (error "Option `%s' is ambiguous" argi))
-                     (setq argi (substring (car elt) 1)))
-                 (setq argval nil
-                       argi orig-argi))))
+             (when (string-match "\\`--." orig-argi)
+               (setq completion (try-completion argi longopts))
+               (if (eq completion t)
+                   (setq argi (substring argi 1))
+                 (if (stringp completion)
+                  (let ((elt (member completion longopts)))
+                       (or elt
+                           (error "Option `%s' is ambiguous" argi))
+                       (setq argi (substring (car elt) 1)))
+                   (setq argval nil
+                         argi orig-argi)))))
 
            ;; Execute the option.
-           (cond ((setq tem (assoc argi command-switch-alist))
+           (cond ((setq cl1-tem (assoc argi command-switch-alist))
                   (if argval
                       (let ((command-line-args-left
                              (cons argval command-line-args-left)))
-                        (funcall (cdr tem) argi))
-                    (funcall (cdr tem) argi)))
+                        (funcall (cdr cl1-tem) argi))
+                    (funcall (cdr cl1-tem) argi)))
 
                  ((equal argi "-no-splash")
                   (setq inhibit-startup-screen t))
@@ -2057,22 +2123,22 @@ A fancy display is used on graphic displays, normal otherwise."
                                  "-funcall"
                                  "-e"))  ; what the source used to say
                   (setq inhibit-startup-screen t)
-                  (setq tem (intern (or argval (pop command-line-args-left))))
-                  (if (commandp tem)
-                      (command-execute tem)
-                    (funcall tem)))
+                  (setq cl1-tem (intern (or argval (pop command-line-args-left))))
+                  (if (commandp cl1-tem)
+                      (command-execute cl1-tem)
+                    (funcall cl1-tem)))
 
                  ((member argi '("-eval" "-execute"))
                   (setq inhibit-startup-screen t)
                   (eval (read (or argval (pop command-line-args-left)))))
 
                  ((member argi '("-L" "-directory"))
-                  (setq tem (expand-file-name
+                  (setq cl1-tem (expand-file-name
                              (command-line-normalize-file-name
                               (or argval (pop command-line-args-left)))))
-                  (cond (splice (setcdr splice (cons tem (cdr splice)))
+                  (cond (splice (setcdr splice (cons cl1-tem (cdr splice)))
                                 (setq splice (cdr splice)))
-                        (t (setq load-path (cons tem load-path)
+                        (t (setq load-path (cons cl1-tem load-path)
                                  splice load-path))))
 
                  ((member argi '("-l" "-load"))
@@ -2096,10 +2162,10 @@ A fancy display is used on graphic displays, normal otherwise."
 
                  ((equal argi "-insert")
                   (setq inhibit-startup-screen t)
-                  (setq tem (or argval (pop command-line-args-left)))
-                  (or (stringp tem)
+                  (setq cl1-tem (or argval (pop command-line-args-left)))
+                  (or (stringp cl1-tem)
                       (error "File name omitted from `-insert' option"))
-                  (insert-file-contents (command-line-normalize-file-name tem)))
+                  (insert-file-contents (command-line-normalize-file-name cl1-tem)))
 
                  ((equal argi "-kill")
                   (kill-emacs t))
@@ -2112,35 +2178,42 @@ A fancy display is used on graphic displays, normal otherwise."
                   (message "\"--no-desktop\" ignored because the Desktop package is not loaded"))
 
                  ((string-match "^\\+[0-9]+\\'" argi)
-                  (setq line (string-to-number argi)))
+                  (setq cl1-line (string-to-number argi)))
 
                  ((string-match "^\\+\\([0-9]+\\):\\([0-9]+\\)\\'" argi)
-                  (setq line (string-to-number (match-string 1 argi))
-                        column (string-to-number (match-string 2 argi))))
+                  (setq cl1-line (string-to-number (match-string 1 argi))
+                        cl1-column (string-to-number (match-string 2 argi))))
 
-                 ((setq tem (assoc argi command-line-x-option-alist))
+                 ((setq cl1-tem (assoc argi command-line-x-option-alist))
                   ;; Ignore X-windows options and their args if not using X.
                   (setq command-line-args-left
-                        (nthcdr (nth 1 tem) command-line-args-left)))
+                        (nthcdr (nth 1 cl1-tem) command-line-args-left)))
+
+                 ((setq cl1-tem (assoc argi command-line-ns-option-alist))
+                  ;; Ignore NS-windows options and their args if not using NS.
+                  (setq command-line-args-left
+                        (nthcdr (nth 1 cl1-tem) command-line-args-left)))
 
                  ((member argi '("-find-file" "-file" "-visit"))
                   (setq inhibit-startup-screen t)
                   ;; An explicit option to specify visiting a file.
-                  (setq tem (or argval (pop command-line-args-left)))
-                  (unless (stringp tem)
+                  (setq cl1-tem (or argval (pop command-line-args-left)))
+                  (unless (stringp cl1-tem)
                     (error "File name omitted from `%s' option" argi))
                   (setq file-count (1+ file-count))
                   (let ((file (expand-file-name
-                               (command-line-normalize-file-name tem) dir)))
+                               (command-line-normalize-file-name cl1-tem)
+                               cl1-dir)))
                     (if (= file-count 1)
                         (setq first-file-buffer (find-file file))
                       (find-file-other-window file)))
-                  (or (zerop line)
-                      (goto-line line))
-                  (setq line 0)
-                  (unless (< column 1)
-                    (move-to-column (1- column)))
-                  (setq column 0))
+                  (unless (zerop cl1-line)
+                    (goto-char (point-min))
+                    (forward-line (1- cl1-line)))
+                  (setq cl1-line 0)
+                  (unless (< cl1-column 1)
+                    (move-to-column (1- cl1-column)))
+                  (setq cl1-column 0))
 
                  ((equal argi "--")
                   (setq just-files t))
@@ -2163,18 +2236,19 @@ A fancy display is used on graphic displays, normal otherwise."
                           (let ((file
                                  (expand-file-name
                                   (command-line-normalize-file-name orig-argi)
-                                  dir)))
+                                  cl1-dir)))
                             (cond ((= file-count 1)
                                    (setq first-file-buffer (find-file file)))
                                   (inhibit-startup-screen
                                    (find-file-other-window file))
                                   (t (find-file file))))
-                          (or (zerop line)
-                              (goto-line line))
-                          (setq line 0)
-                          (unless (< column 1)
-                            (move-to-column (1- column)))
-                          (setq column 0))))))
+                          (unless (zerop cl1-line)
+                            (goto-char (point-min))
+                            (forward-line (1- cl1-line)))
+                          (setq cl1-line 0)
+                          (unless (< cl1-column 1)
+                            (move-to-column (1- cl1-column)))
+                          (setq cl1-column 0))))))
            ;; In unusual circumstances, the execution of Lisp code due
            ;; to command-line options can cause the last visible frame
            ;; to be deleted.  In this case, kill emacs to avoid an
@@ -2198,7 +2272,7 @@ A fancy display is used on graphic displays, normal otherwise."
     (if (or inhibit-startup-screen
            initial-buffer-choice
            noninteractive
-           emacs-quick-startup)
+           inhibit-x-resources)
 
        ;; Not displaying a startup screen.  If 3 or more files
        ;; visited, and not all visible, show user what they all are.
@@ -2252,6 +2326,9 @@ A fancy display is used on graphic displays, normal otherwise."
     ;; However, /// at the beginning is supposed to mean just /, not //.
     (if (string-match "^///+" file)
        (setq file (replace-match "/" t t file)))
+    (and (memq system-type '(ms-dos windows-nt))
+        (string-match "^[A-Za-z]:\\(\\\\[\\\\/]\\)" file) ; C:\/ or C:\\
+        (setq file (replace-match "/" t t file 1)))
     (while (string-match "//+" file 1)
       (setq file (replace-match "/" t t file)))
     file))