Rename `struct device' to `struct terminal'. Rename some terminal-related functions...
[bpt/emacs.git] / lisp / startup.el
index 8ad1962..cef3841 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, 2004, 2005  Free Software Foundation, Inc.
+;;   2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: internal
@@ -20,8 +20,8 @@
 
 ;; 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., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -44,17 +44,17 @@ The value is nil if the selected frame is on a text-only-terminal.")
 (make-variable-frame-local 'window-system)
 
 (defgroup initialization nil
-  "Emacs start-up procedure"
+  "Emacs start-up procedure."
   :group 'internal)
 
-(defcustom inhibit-startup-message nil
-  "*Non-nil inhibits the initial startup message.
+(defcustom inhibit-splash-screen nil
+  "*Non-nil inhibits the startup screen.
 This is for use in your personal init file, once you are familiar
-with the contents of the startup message."
+with the contents of the startup screen."
   :type 'boolean
   :group 'initialization)
 
-(defvaralias 'inhibit-splash-screen 'inhibit-startup-message)
+(defvaralias 'inhibit-startup-message 'inhibit-splash-screen)
 
 (defcustom inhibit-startup-echo-area-message nil
   "*Non-nil inhibits the initial startup echo area message.
@@ -128,8 +128,7 @@ This is normally copied from `default-directory' when Emacs starts.")
     ("-bg" 1 x-handle-switch background-color)
     ("-background" 1 x-handle-switch background-color)
     ("-ms" 1 x-handle-switch mouse-color)
-    ("-itype" 0 x-handle-switch icon-type t)
-    ("-i" 0 x-handle-switch icon-type t)
+    ("-nbi" 0 x-handle-switch icon-type nil)
     ("-iconic" 0 x-handle-iconic)
     ("-xrm" 1 x-handle-xrm-switch)
     ("-cr" 1 x-handle-switch cursor-color)
@@ -150,7 +149,7 @@ This is normally copied from `default-directory' when Emacs starts.")
     ("--foreground-color" 1 x-handle-switch foreground-color)
     ("--background-color" 1 x-handle-switch background-color)
     ("--mouse-color" 1 x-handle-switch mouse-color)
-    ("--icon-type" 0 x-handle-switch icon-type t)
+    ("--no-bitmap-icon" 0 x-handle-switch icon-type nil)
     ("--iconic" 0 x-handle-iconic)
     ("--xrm" 1 x-handle-xrm-switch)
     ("--cursor-color" 1 x-handle-switch cursor-color)
@@ -191,9 +190,9 @@ This is because we already did so.")
 
 (defvar keyboard-type nil
   "The brand of keyboard you are using.
-This variable is used to define
-the proper function and keypad keys for use under X.  It is used in a
-fashion analogous to the environment variable TERM.")
+This variable is used to define the proper function and keypad
+keys for use under X.  It is used in a fashion analogous to the
+environment variable TERM.")
 
 (defvar window-setup-hook nil
   "Normal hook run to initialize window system display.
@@ -241,7 +240,7 @@ is less convenient.
 This variable is defined for customization so as to make
 it visible in the relevant context.  However, actually customizing it
 is not allowed, since it would not work anyway.  The only way to set
-this variable usefully is to set it during while building and dumping Emacs."
+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
@@ -294,6 +293,8 @@ from being initialized."
 
 (defvar no-blinking-cursor nil)
 
+(defvar default-frame-background-mode)
+
 (defvar pure-space-overflow nil
   "Non-nil if building Emacs overflowed pure space.")
 
@@ -375,11 +376,17 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
     ;; of that dir into load-path,
     ;; Look for a leim-list.el file too.  Loading it will register
     ;; available input methods.
-    (dolist (dir load-path)
-      (let ((default-directory dir))
-       (load (expand-file-name "subdirs.el") t t t))
-      (let ((default-directory dir))
-       (load (expand-file-name "leim-list.el") t t t)))
+    (let ((tail load-path) dir)
+      (while tail
+        (setq dir (car tail))
+        (let ((default-directory dir))
+          (load (expand-file-name "subdirs.el") t t t))
+        (let ((default-directory dir))
+          (load (expand-file-name "leim-list.el") t t t))
+        ;; We don't use a dolist loop and we put this "setq-cdr" command at
+        ;; 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")))
@@ -498,7 +505,7 @@ from the returned command line.")
 Window-system startup files should add their own initialization
 function to this list.  The function should take no arguments,
 and initialize the window system environment to prepare for
-opening the first frame (e.g. open a connection to the server).")
+opening the first frame (e.g. open a connection to an X server).")
 
 ;; Handle the X-like command-line arguments "-fg", "-bg", "-name", etc.
 (defun tty-handle-args (args)
@@ -571,7 +578,7 @@ opening the first frame (e.g. open a connection to the server).")
 
   ;; Choose a reasonable location for temporary files.
   (custom-reevaluate-setting 'temporary-file-directory)
-  (custom-reevaluate-setting 'small-emporary-file-directory)
+  (custom-reevaluate-setting 'small-temporary-file-directory)
   (custom-reevaluate-setting 'auto-save-file-name-transforms)
 
   ;; See if we should import version-control from the environment variable.
@@ -640,6 +647,24 @@ opening the first frame (e.g. open a connection to the server).")
 
   (set-locale-environment nil)
 
+  ;; Convert preloaded file names to absolute.
+  (let ((lisp-dir
+        (file-name-directory
+         (locate-file "simple" load-path
+                      load-suffixes))))
+
+    (setq load-history
+         (mapcar (lambda (elt)
+                   (if (and (stringp (car elt))
+                            (not (file-name-absolute-p (car elt))))
+                       (cons (concat lisp-dir
+                                     (car elt)
+                                     (if (string-match "[.]el$" (car elt))
+                                         "" ".elc"))
+                             (cdr elt))
+                     elt))
+                 load-history)))
+
   ;; Convert the arguments to Emacs internal representation.
   (let ((args (cdr command-line-args)))
     (while args
@@ -662,9 +687,9 @@ opening the first frame (e.g. open a connection to the server).")
     ;; processed.  This is consistent with the way main in emacs.c
     ;; does things.
     (while (and (not done) args)
-      (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--user")
-                         ("--debug-init") ("--iconic") ("--icon-type")
-                        ("--no-blinking-cursor") ("--bare-bones")))
+      (let* ((longopts '(("--no-init-file") ("--no-site-file") ("--debug-init")
+                         ("--user") ("--iconic") ("--icon-type") ("--quick")
+                        ("--no-blinking-cursor") ("--basic-display")))
              (argi (pop args))
              (orig-argi argi)
              argval)
@@ -719,6 +744,8 @@ opening the first frame (e.g. open a connection to the server).")
     (and command-line-args
          (setcdr command-line-args args)))
 
+  (run-hooks 'before-init-hook)
+
   ;; Under X Window, this creates the X frame and deletes the terminal frame.
   (when (fboundp 'frame-initialize)
     (frame-initialize))
@@ -749,22 +776,21 @@ opening the first frame (e.g. open a connection to the server).")
   ;; Can't do this init in defcustom because the relevant variables
   ;; are not set.
   (custom-reevaluate-setting 'blink-cursor-mode)
-  (custom-reevaluate-setting 'normal-erase-is-backspace)
+  (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)
 
-  ;; If you change the code below, you need to also change the
-  ;; corresponding code in the tooltip-mode defcustom.  The two need
-  ;; to be equivalent under all conditions, or Custom will get confused.
-  (unless (or noninteractive
-             emacs-basic-display
-              (not (display-graphic-p))
-              (not (fboundp 'x-show-tip)))
-    (tooltip-mode 1))
+  (normal-erase-is-backspace-setup-frame)
 
   ;; Register default TTY colors for the case the terminal hasn't a
-  ;; terminal init file.
-  ;; We do this regardles of whether the terminal supports colors
-  ;; or not, since they can switch that support on or off in
-  ;; mid-session by setting the tty-color-mode frame parameter.
+  ;; terminal init file.  We do this regardles of whether the terminal
+  ;; supports colors or not and regardless the current display type,
+  ;; 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)
 
   ;; Record whether the tool-bar is present before the user and site
@@ -783,8 +809,6 @@ opening the first frame (e.g. open a connection to the server).")
        (old-font-list-limit font-list-limit)
        (old-face-ignored-fonts face-ignored-fonts))
 
-    (run-hooks 'before-init-hook)
-
     ;; Run the site-start library if it exists.  The point of this file is
     ;; that it is run before .emacs.  There is no point in doing this after
     ;; .emacs; that is useless.
@@ -795,6 +819,20 @@ opening the first frame (e.g. open a connection to the server).")
     ;; the startup message.
     (setq inhibit-startup-message nil)
 
+    ;; Warn for invalid user name.
+    (when init-file-user
+      (if (string-match "[~/:\n]" init-file-user)
+         (display-warning 'initialization
+                          (format "Invalid user name %s"
+                                  init-file-user)
+                          :error)
+       (if (file-directory-p (expand-file-name (concat "~" init-file-user)))
+           nil
+         (display-warning 'initialization
+                          (format "User %s has no home directory"
+                                  init-file-user)
+                          :error))))
+
     ;; Load that user's init file, or the default one, or none.
     (let (debug-on-error-from-init-file
          debug-on-error-should-be-set
@@ -831,14 +869,12 @@ opening the first frame (e.g. open a connection to the server).")
 
                      (when (eq user-init-file t)
                        ;; If we did not find ~/.emacs, try
-                       ;; ~/.emacs.d/.emacs.
+                       ;; ~/.emacs.d/init.el.
                        (let ((otherfile
                               (expand-file-name
-                               (file-name-nondirectory user-init-file-1)
+                               "init"
                                (file-name-as-directory
-                                (expand-file-name
-                                 ".emacs.d"
-                                 (file-name-directory user-init-file-1))))))
+                                (concat "~" init-file-user "/.emacs.d")))))
                          (load otherfile t t)
 
                          ;; If we did not find the user's init file,
@@ -902,6 +938,10 @@ opening the first frame (e.g. open a connection to the server).")
                 (pop-to-buffer "*Messages*"))
               (setq init-file-had-error t)))))
 
+       (if (and deactivate-mark transient-mark-mode)
+           (with-current-buffer (window-buffer)
+             (deactivate-mark)))
+
        ;; If the user has a file of abbrevs, read it.
        (if (file-exists-p abbrev-file-name)
            (quietly-read-abbrev-file abbrev-file-name))
@@ -939,6 +979,38 @@ opening the first frame (e.g. open a connection to the server).")
                                        (or mail-host-address
                                            (system-name)))))
 
+    ;; Originally face attributes were specified via
+    ;; `font-lock-face-attributes'.  Users then changed the default
+    ;; face attributes by setting that variable.  However, we try and
+    ;; be back-compatible and respect its value if set except for
+    ;; faces where M-x customize has been used to save changes for the
+    ;; face.
+    (when (boundp 'font-lock-face-attributes)
+      (let ((face-attributes font-lock-face-attributes))
+       (while face-attributes
+         (let* ((face-attribute (pop face-attributes))
+                (face (car face-attribute)))
+           ;; Rustle up a `defface' SPEC from a
+           ;; `font-lock-face-attributes' entry.
+           (unless (get face 'saved-face)
+             (let ((foreground (nth 1 face-attribute))
+                   (background (nth 2 face-attribute))
+                   (bold-p (nth 3 face-attribute))
+                   (italic-p (nth 4 face-attribute))
+                   (underline-p (nth 5 face-attribute))
+                   face-spec)
+               (when foreground
+                 (setq face-spec (cons ':foreground (cons foreground face-spec))))
+               (when background
+                 (setq face-spec (cons ':background (cons background face-spec))))
+               (when bold-p
+                 (setq face-spec (append '(:weight bold) face-spec)))
+               (when italic-p
+                 (setq face-spec (append '(:slant italic) face-spec)))
+               (when underline-p
+                 (setq face-spec (append '(:underline t) face-spec)))
+               (face-spec-set face (list (list t face-spec)) nil)))))))
+
     ;; If parameter have been changed in the init file which influence
     ;; face realization, clear the face cache so that new faces will
     ;; be realized.
@@ -971,17 +1043,8 @@ opening the first frame (e.g. open a connection to the server).")
   ;; Load library for our terminal type.
   ;; User init file can set term-file-prefix to nil to prevent this.
   (unless (or noninteractive
-              initial-window-system
-              (null term-file-prefix))
-    (let ((term (getenv "TERM"))
-          hyphend)
-      (while (and term
-                  (not (load (concat term-file-prefix term) t t)))
-        ;; Strip off last hyphen and what follows, then try again
-        (setq term
-              (if (setq hyphend (string-match "[-_][^-_]+$" term))
-                  (substring term 0 hyphend)
-                nil)))))
+              initial-window-system)
+    (tty-run-terminal-initialization (selected-frame)))
 
   ;; Update the out-of-memory error message based on user's key bindings
   ;; for save-some-buffers.
@@ -1054,6 +1117,7 @@ Read the Emacs Manual\tView the Emacs manual using Info
           :face variable-pitch
           "\
 Copying Conditions\tConditions for redistributing and changing Emacs
+Getting New Versions\tHow to obtain the latest version of Emacs
 More Manuals / Ordering Manuals       Buying printed manuals from the FSF\n")
   (:face variable-pitch
           "You can do basic editing with the menu bar and scroll bar \
@@ -1233,7 +1297,13 @@ This is an internal function used to turn off the splash screen after
 the user caused an input event by hitting a key or clicking with the
 mouse."
   (interactive)
-  (push last-command-event unread-command-events)
+  (if (and (memq 'down (event-modifiers last-command-event))
+          (eq (posn-window (event-start last-command-event))
+              (selected-window)))
+      ;; This is a mouse-down event in the spash screen window.
+      ;; Ignore it and consume the corresponding mouse-up event.
+      (read-event)
+    (push last-command-event unread-command-events))
   (throw 'exit nil))
 
 
@@ -1339,20 +1409,20 @@ You can do basic editing with the menu bar and scroll bar using the mouse.
 
 Useful File menu items:
 Exit Emacs             (or type Control-x followed by Control-c)
-Recover Session                recover files you were editing before a crash
+Recover Crashed Session        Recover files you were editing before a crash
 
 Important Help menu items:
-Emacs Tutorial         Learn-by-doing tutorial for using Emacs efficiently.
+Emacs Tutorial         Learn how to use Emacs efficiently
 Emacs FAQ              Frequently asked questions and answers
 Read the Emacs Manual  View the Emacs manual using Info
 \(Non)Warranty         GNU Emacs comes with ABSOLUTELY NO WARRANTY
-Copying Conditions     Conditions for redistributing and changing Emacs.
-Getting New Versions   How to obtain the latest version of Emacs.
-More Manuals / Ordering Manuals    How to order printed manuals from the FSF.
+Copying Conditions     Conditions for redistributing and changing Emacs
+Getting New Versions   How to obtain the latest version of Emacs
+More Manuals / Ordering Manuals    How to order printed manuals from the FSF
 ")
                  (insert "\n\n" (emacs-version)
                          "
-Copyright (C) 2004 Free Software Foundation, Inc."))
+Copyright (C) 2005 Free Software Foundation, Inc."))
 
              ;; No mouse menus, so give help using kbd commands.
 
@@ -1360,7 +1430,7 @@ Copyright (C) 2004 Free Software Foundation, Inc."))
              ;; 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-emacs)
+                      (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)
@@ -1377,7 +1447,7 @@ Browse manuals     C-h i")
 Get help          %s
 Emacs manual      \\[info-emacs-manual]
 Emacs tutorial    \\[help-with-tutorial]\tUndo changes\t\\[advertised-undo]
-Buy manuals        \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-emacs]
+Buy manuals        \\[view-order-manuals]\tExit Emacs\t\\[save-buffers-kill-terminal]
 Browse manuals     \\[info]"
                                 (let ((where (where-is-internal
                                               'help-command nil t)))
@@ -1400,7 +1470,7 @@ If you have no Meta key, you may instead type ESC followed by the character.)")
 
              (insert "\n\n" (emacs-version)
                      "
-Copyright (C) 2004 Free Software Foundation, Inc.")
+Copyright (C) 2005 Free Software Foundation, Inc.")
 
              (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
                       (eq (key-binding "\C-h\C-d") 'describe-distribution)
@@ -1459,7 +1529,7 @@ Type \\[describe-distribution] for information on getting the latest version."))
 
 (defun display-startup-echo-area-message ()
   (let ((resize-mini-windows t))
-    (message (startup-echo-area-message))))
+    (message "%s" (startup-echo-area-message))))
 
 
 (defun display-splash-screen ()
@@ -1625,6 +1695,15 @@ normal otherwise."
                      (setq file file-ex))
                    (load file nil t)))
 
+               ;; This is used to handle -script.  It's not clear
+               ;; we need to document it.
+                ((member argi '("-scriptload"))
+                 (let* ((file (command-line-normalize-file-name
+                               (or argval (pop command-line-args-left))))
+                        ;; Take file from default dir.
+                        (file-ex (expand-file-name file)))
+                   (load file-ex nil t t)))
+
                 ((equal argi "-insert")
                  (setq tem (or argval (pop command-line-args-left)))
                  (or (stringp tem)
@@ -1705,11 +1784,7 @@ normal otherwise."
   ;; Maybe display a startup screen.
   (unless (or inhibit-startup-message
              noninteractive
-             emacs-quick-startup
-            ;; Don't display startup screen if init file
-            ;; has started some sort of server.
-            (and (fboundp 'process-list)
-                 (process-list)))
+             emacs-quick-startup)
     ;; Display a startup screen, after some preparations.
 
     ;; If there are no switches to process, we might as well