(function-key-map): Use char-names more consistently.
[bpt/emacs.git] / lisp / startup.el
index 26671e5..790d870 100644 (file)
@@ -1,6 +1,6 @@
 ;;; startup.el --- process Emacs shell arguments
 
-;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
+;; Copyright (C) 1985, 86, 92, 94, 95, 96, 97, 98, 99, 2000, 01, 02, 2004
 ;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -76,8 +76,8 @@ the startup message unless he personally acts to inhibit it."
 (defvar command-switch-alist nil
   "Alist of command-line switches.
 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
-HANDLER-FUNCTION receives switch name as sole arg;
-remaining command-line args are in the variable `command-line-args-left'.")
+HANDLER-FUNCTION receives the switch string as its sole argument;
+the remaining command-line args are in the variable `command-line-args-left'.")
 
 (defvar command-line-args-left nil
   "List of command-line args not yet processed.")
@@ -220,7 +220,7 @@ Setting `init-file-user' does not prevent Emacs from loading
   "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
-higher incidence of change, don't make sense to load into emacs'
+higher incidence of change, don't make sense to load into Emacs's
 dumped image.  Thus, the run-time load order is: 1. file described in
 this variable, if non-nil; 2. `~/.emacs'; 3. `default.el'.
 
@@ -229,9 +229,17 @@ Put them in `default.el' instead, so that users can more easily
 override them.  Users can prevent loading `default.el' with the `-q'
 option or by setting `inhibit-default-init' in their own init files,
 but inhibiting `site-start.el' requires `--no-site-file', which
-is less convenient."
+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."
   :type '(choice (const :tag "none" nil) string)
-  :group 'initialization)
+  :group 'initialization
+  :initialize 'custom-initialize-default
+  :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."
@@ -267,6 +275,8 @@ from being initialized."
                 string)
   :group 'auto-save)
 
+(defvar emacs-quick-startup nil)
+
 (defvar init-file-debug nil)
 
 (defvar init-file-had-error nil)
@@ -291,8 +301,8 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
       (let* ((this-dir (car dirs))
             (contents (directory-files this-dir))
             (default-directory this-dir)
-            (canonicalized (and (eq system-type 'windows-nt)
-                                (untranslated-canonical-name this-dir))))
+            (canonicalized (if (fboundp 'untranslated-canonical-name)
+                               (untranslated-canonical-name this-dir))))
        ;; The Windows version doesn't report meaningful inode
        ;; numbers, so use the canonicalized absolute file name of the
        ;; directory instead.
@@ -341,8 +351,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
     ;; Give *Messages* the same default-directory as *scratch*,
     ;; just to keep things predictable.
     (let ((dir default-directory))
-      (save-excursion
-       (set-buffer (get-buffer "*Messages*"))
+      (with-current-buffer "*Messages*"
        (setq default-directory dir)))
     ;; `user-full-name' is now known; reset its standard-value here.
     (put 'user-full-name 'standard-value
@@ -355,32 +364,25 @@ 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.
-    (let ((tail load-path)
-         new)
-      (while tail
-       (push (car tail) new)
-       (condition-case nil
-           (let ((default-directory (car tail)))
-             (load (expand-file-name "subdirs.el" (car tail)) t t t)))
-       (condition-case nil
-           (let ((default-directory (car tail)))
-             (load (expand-file-name "leim-list.el" (car tail)) t t t)))
-       (setq tail (cdr tail))))
-    (if (not (eq system-type 'vax-vms))
-       (progn
-         ;; 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)))))))
+    (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)))
+    (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))))))
     (setq default-directory (abbreviate-file-name default-directory))
     (let ((menubar-bindings-done nil))
       (unwind-protect
@@ -573,7 +575,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
        (if (eq system-type 'ms-dos)
            (getenv "TMPDIR")))
   (setq auto-save-file-name-transforms
-       (list (list "\\`/[^/]*:\\(.+/\\)*\\(.*\\)"
+       (list (list (car (car auto-save-file-name-transforms))
                    ;; Don't put "\\2" inside expand-file-name, since
                    ;; it will be transformed to "/2" on DOS/Windows.
                    (concat temporary-file-directory "\\2") t)))
@@ -685,6 +687,11 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
                (setq argval nil
                       argi orig-argi)))))
        (cond
+        ((equal argi "-Q")
+         (setq init-file-user nil
+               site-run-file nil
+               emacs-quick-startup t)
+         (push '(vertical-scroll-bars . nil) initial-frame-alist))
         ((member argi '("-q" "-no-init-file"))
          (setq init-file-user nil))
         ((member argi '("-u" "-user"))
@@ -716,21 +723,26 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
 
   ;; If frame was created with a menu bar, set menu-bar-mode on.
   (unless (or noninteractive
+             emacs-quick-startup
               (and (memq window-system '(x w32))
                    (<= (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-quick-startup
               (not (display-graphic-p))
               (<= (frame-parameter nil 'tool-bar-lines) 0))
     (tool-bar-mode 1))
 
-  ;; Can't do this init in defcustom because window-system isn't set.
+  ;; Can't do this init in defcustom because the relevant variables
+  ;; are not set.  If you make any changes to the `or' form below,
+  ;; you should also change the corresponding expression in the
+  ;; defcustom in frame.el, or Custom will be badly confused.
   (unless (or noninteractive
+             emacs-quick-startup
               (eq system-type 'ms-dos)
               (not (memq window-system '(x w32))))
-    (setq-default blink-cursor t)
     (blink-cursor-mode 1))
 
   (unless noninteractive
@@ -749,6 +761,7 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
       (normal-erase-is-backspace-mode 1)))
 
   (unless (or noninteractive
+             emacs-quick-startup
               (not (display-graphic-p))
               (not (fboundp 'x-show-tip)))
     (setq-default tooltip-mode t)
@@ -807,9 +820,14 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
                            ((eq system-type 'ms-dos)
                             (concat "~" init-file-user "/_emacs"))
                            ((eq system-type 'windows-nt)
+                            ;; Prefer .emacs on Windows.
                             (if (directory-files "~" nil "^\\.emacs\\(\\.elc?\\)?$")
                                 "~/.emacs"
-                              "~/_emacs"))
+                              ;; Also support _emacs for compatibility.
+                              (if (directory-files "~" nil "^_emacs\\(\\.elc?\\)?$")
+                                  "~/_emacs"
+                                ;; But default to .emacs if _emacs does not exist.
+                                "~/.emacs")))
                            ((eq system-type 'vax-vms)
                             "sys$login:.emacs")
                            (t
@@ -855,12 +873,6 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
                              (sit-for 1))
                            (setq user-init-file source))))
 
-                     (when (stringp custom-file)
-                        (unless (assoc custom-file load-history)
-                          ;; If the .emacs file has set `custom-file' but hasn't
-                          ;; loaded the file yet, let's load it.
-                          (load custom-file t t)))
-
                      (unless inhibit-default-init
                         (let ((inhibit-startup-message nil))
                           ;; Users are supposed to be told their rights.
@@ -945,6 +957,19 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
 
   (run-hooks 'after-init-hook)
 
+  ;; Decode all default-directory.
+  (if (and default-enable-multibyte-characters locale-coding-system)
+      (save-excursion
+       (dolist (elt (buffer-list))
+         (set-buffer elt)
+         (if default-directory
+             (setq default-directory
+                   (decode-coding-string default-directory
+                                         locale-coding-system t))))
+       (setq command-line-default-directory
+             (decode-coding-string command-line-default-directory
+                                   locale-coding-system t))))
+
   ;; If *scratch* exists and init file didn't change its mode, initialize it.
   (if (get-buffer "*scratch*")
       (with-current-buffer "*scratch*"
@@ -1102,8 +1127,8 @@ where FACE is a valid face specification, as it can be used with
     (when img
       (when (> window-width image-width)
        ;; Center the image in the window.
-       (let ((pos (/ (- window-width image-width) 2)))
-         (insert (propertize " " 'display `(space :align-to ,pos))))
+       (insert (propertize " " 'display
+                           `(space :align-to (+ center (-0.5 . ,img)))))
 
        ;; Change the color of the XPM version of the splash image
        ;; so that it is visible with a dark frame background.
@@ -1145,7 +1170,7 @@ where FACE is a valid face specification, as it can be used with
                         (emacs-version)
                         "\n"
                         :face '(variable-pitch :height 0.5)
-                        "Copyright (C) 2002 Free Software Foundation, Inc.")
+                        "Copyright (C) 2004 Free Software Foundation, Inc.")
     (and auto-save-list-file-prefix
         ;; Don't signal an error if the
         ;; directory for auto-save-list files
@@ -1311,7 +1336,7 @@ More Manuals / Ordering Manuals    How to order printed manuals from the FSF.
 ")
                  (insert "\n\n" (emacs-version)
                          "
-Copyright (C) 2002 Free Software Foundation, Inc."))
+Copyright (C) 2004 Free Software Foundation, Inc."))
 
              ;; No mouse menus, so give help using kbd commands.
 
@@ -1359,7 +1384,7 @@ If you have no Meta key, you may instead type ESC followed by the character.)")
 
              (insert "\n\n" (emacs-version)
                      "
-Copyright (C) 2002 Free Software Foundation, Inc.")
+Copyright (C) 2004 Free Software Foundation, Inc.")
 
              (if (and (eq (key-binding "\C-h\C-c") 'describe-copying)
                       (eq (key-binding "\C-h\C-d") 'describe-distribution)
@@ -1476,12 +1501,19 @@ normal otherwise."
           (file-count 0)
           first-file-buffer
           tem
-          ;; The directories listed in --directory/-L options will *appear*
-          ;; at the front of `load-path' in the order they appear on the
-          ;; command-line.  We cannot do this by *placing* them at the front
-          ;; in the order they appear, so we need this variable to hold them,
-          ;; temporarily.
-          extra-load-path
+          ;; This approach loses for "-batch -L DIR --eval "(require foo)",
+          ;; if foo is intended to be found in DIR.
+          ;;
+          ;; ;; The directories listed in --directory/-L options will *appear*
+          ;; ;; at the front of `load-path' in the order they appear on the
+          ;; ;; command-line.  We cannot do this by *placing* them at the front
+          ;; ;; in the order they appear, so we need this variable to hold them,
+          ;; ;; temporarily.
+          ;; extra-load-path
+          ;;
+          ;; To DTRT we keep track of the splice point and modify `load-path'
+          ;; straight away upon any --directory/-L option.
+          splice
           just-files ;; t if this follows the magic -- option.
           ;; This includes our standard options' long versions
           ;; and long versions of what's on command-switch-alist.
@@ -1550,15 +1582,15 @@ normal otherwise."
 
                 ((member argi '("-eval" "-execute"))
                  (eval (read (or argval (pop command-line-args-left)))))
-                ;; Set the default directory as specified in -L.
 
                 ((member argi '("-L" "-directory"))
-                 (setq tem (or argval (pop command-line-args-left)))
-                 ;; We will reverse `extra-load-path' and prepend it to
-                 ;; `load-path' after all the arguments have been processed.
-                 (push
-                  (expand-file-name (command-line-normalize-file-name tem))
-                  extra-load-path))
+                 (setq tem (expand-file-name
+                            (command-line-normalize-file-name
+                             (or argval (pop command-line-args-left)))))
+                 (cond (splice (setcdr splice (cons tem (cdr splice)))
+                               (setq splice (cdr splice)))
+                       (t (setq load-path (cons tem load-path)
+                                splice load-path))))
 
                 ((member argi '("-l" "-load"))
                  (let* ((file (command-line-normalize-file-name
@@ -1639,10 +1671,6 @@ normal otherwise."
                            (move-to-column (1- column)))
                          (setq column 0))))))))
 
-      ;; See --directory/-L option above.
-      (when extra-load-path
-        (setq load-path (append (nreverse extra-load-path) load-path)))
-
       ;; If 3 or more files visited, and not all visible,
       ;; show user what they all are.  But leave the last one current.
       (and (> file-count 2)
@@ -1652,11 +1680,13 @@ normal otherwise."
                (list-buffers)))))
 
   ;; Maybe display a startup screen.
-  (when (and (not inhibit-startup-message) (not noninteractive)
+  (unless (or inhibit-startup-message
+             noninteractive
+             emacs-quick-startup
             ;; Don't display startup screen if init file
             ;; has started some sort of server.
-            (not (and (fboundp 'process-list)
-                      (process-list))))
+            (and (fboundp 'process-list)
+                 (process-list)))
     ;; Display a startup screen, after some preparations.
 
     ;; If there are no switches to process, we might as well