XEmacs 21.2.36 "Notos"
[chise/xemacs-chise.git.1] / lisp / startup.el
1 ;;; startup.el --- process XEmacs shell arguments
2
3 ;; Copyright (C) 1985-1986, 1990, 1992-1997 Free Software Foundation, Inc.
4 ;; Copyright (c) 1993, 1994 Sun Microsystems, Inc.
5 ;; Copyright (C) 1995 Board of Trustees, University of Illinois
6
7 ;; Maintainer: XEmacs Development Team
8 ;; Keywords: internal, dumped
9
10 ;; This file is part of XEmacs.
11
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XEmacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Synched up with: FSF 19.34.
28
29 ;;; Commentary:
30
31 ;; This file is dumped with XEmacs.
32
33 ;; -batch, -t, and -nw are processed by main() in emacs.c and are
34 ;; never seen by lisp code.
35
36 ;; -version and -help are special-cased as well: they imply -batch,
37 ;; but are left on the list for lisp code to process.
38
39 ;;; Code:
40 \f
41 (setq top-level '(normal-top-level))
42
43 (defvar command-line-processed nil "t once command line has been processed")
44
45 (defconst startup-message-timeout 12000) ; More or less disable the timeout
46 (defconst splash-frame-timeout 7) ; interval between splash frame elements
47
48 (defconst inhibit-startup-message nil
49   "*Non-nil inhibits the initial startup message.
50 This is for use in your personal init file, once you are familiar
51 with the contents of the startup message.")
52
53 ;; #### FSFmacs randomness
54 ;;(defconst inhibit-startup-echo-area-message nil
55 ;;  "*Non-nil inhibits the initial startup echo area message.
56 ;;Inhibition takes effect only if your `.emacs' file contains
57 ;;a line of this form:
58 ;; (setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\")
59 ;;If your `.emacs' file is byte-compiled, use the following form instead:
60 ;; (eval '(setq inhibit-startup-echo-area-message \"YOUR-USER-NAME\"))
61 ;;Thus, someone else using a copy of your `.emacs' file will see
62 ;;the startup message unless he personally acts to inhibit it.")
63
64 (defconst inhibit-default-init nil
65   "*Non-nil inhibits loading the `default' library.")
66
67 (defvar command-line-args-left nil
68   "List of command-line args not yet processed.") ; bound by `command-line'
69
70 (defvar command-line-default-directory nil
71   "Default directory to use for command line arguments.
72 This is normally copied from `default-directory' when XEmacs starts.")
73
74 (defvar before-init-hook nil
75   "Functions to call after handling urgent options but before init files.
76 The frame system uses this to open frames to display messages while
77 XEmacs loads the user's initialization file.")
78
79 (defvar after-init-hook nil
80   "*Functions to call after loading the init file (`.emacs').
81 The call is not protected by a condition-case, so you can set `debug-on-error'
82 in `.emacs', and put all the actual code on `after-init-hook'.")
83
84 (defvar term-setup-hook nil
85   "*Functions to be called after loading terminal-specific Lisp code.
86 See `run-hooks'.  This variable exists for users to set, so as to
87 override the definitions made by the terminal-specific file.  XEmacs
88 never sets this variable itself.")
89
90 (defvar keyboard-type nil
91   "The brand of keyboard you are using.
92 This variable is used to define the proper function and keypad keys
93 for use under X.  It is used in a fashion analogous to the environment
94 value TERM.")
95
96 (defvar window-setup-hook nil
97   "Normal hook run to initialize window system display.
98 XEmacs runs this hook after processing the command line arguments and loading
99 the user's init file.")
100
101 (defconst initial-major-mode 'lisp-interaction-mode
102   "Major mode command symbol to use for the initial *scratch* buffer.")
103
104 (defvar emacs-roots nil
105   "List of plausible roots of the XEmacs hierarchy.")
106
107 (defvar user-init-directory-base ".xemacs"
108   "Base of directory where user-installed init files may go.")
109
110 (defvar user-init-directory
111   (file-name-as-directory
112    (paths-construct-path (list "~" user-init-directory-base)))
113   "Directory where user-installed init files may go.")
114
115 (defvar user-init-file-base "init.el"
116   "Default name of the user init file if uncompiled.
117 This should be used for migration purposes only.")
118
119 (defvar user-init-file-base-list '("init.elc" "init.el")
120   "List of allowed init files in the user's init directory.
121 The first one found takes precedence.")
122
123 (defvar user-home-init-file-base-list
124   (append '(".emacs.elc" ".emacs.el" ".emacs")
125           (and (eq system-type 'windows-nt)
126                '("_emacs.elc" "_emacs.el" "_emacs")))
127   "List of allowed init files in the user's home directory.
128 The first one found takes precedence.")
129
130 (defvar load-home-init-file nil
131   "Non-nil if XEmacs should load the init file from the home directory.
132 Otherwise, XEmacs will offer migration to the init directory.")
133
134 (defvar load-user-init-file-p t
135   "Non-nil if XEmacs should load the user's init file.")
136
137 ;; #### called `site-run-file' in FSFmacs
138
139 (defvar site-start-file (purecopy "site-start")
140   "File containing site-wide run-time initializations.
141 This file is loaded at run-time before `.emacs'.  It
142 contains inits that need to be in place for the entire site, but
143 which, due to their higher incidence of change, don't make sense to
144 load into XEmacs' dumped image.  Thus, the run-time load order is:
145
146   1. file described in this variable, if non-nil;
147   2. `.emacs';
148   3. `/path/to/xemacs/lisp/default.el'.
149
150 Don't use the `site-start.el' file for things some users may not like.
151 Put them in `default.el' instead, so that users can more easily
152 override them.  Users can prevent loading `default.el' with the `-q'
153 option or by setting `inhibit-default-init' in their own init files,
154 but inhibiting `site-start.el' requires `--no-site-file', which
155 is less convenient.")
156
157 ;;(defconst iso-8859-1-locale-regexp "8859[-_]?1"
158 ;;  "Regexp that specifies when to enable the ISO 8859-1 character set.
159 ;;We do that if this regexp matches the locale name
160 ;;specified by the LC_ALL, LC_CTYPE and LANG environment variables.")
161
162 (defcustom mail-host-address nil
163   "*Name of this machine, for purposes of naming users."
164   :type 'string
165   :group 'mail)
166
167 (defcustom user-mail-address nil
168   "*Full mailing address of this user.
169 This is initialized based on `mail-host-address',
170 after your init file is read, in case it sets `mail-host-address'."
171   :type 'string
172   :group 'mail)
173
174 (defvar auto-save-list-file-prefix "~/.saves-"
175   "Prefix for generating auto-save-list-file-name.
176 Emacs's pid and the system name will be appended to
177 this prefix to create a unique file name.")
178
179 (defvar init-file-debug nil)
180
181 (defvar init-file-had-error nil)
182
183 (defvar init-file-loaded nil
184   "True after the user's init file has been loaded (or suppressed with -q).
185 This will be true when `after-init-hook' is run and at all times
186 after, and will not be true at any time before.")
187
188 (defvar initial-frame-unmapped-p nil)
189
190 \f
191
192 (defvar command-switch-alist
193   (purecopy
194    '(("-help"   . command-line-do-help)
195      ("-version". command-line-do-version)
196      ("-V"      . command-line-do-version)
197      ("-funcall". command-line-do-funcall)
198      ("-f"      . command-line-do-funcall)
199      ("-e"      . command-line-do-funcall-1)
200      ("-eval"   . command-line-do-eval)
201      ("-load"   . command-line-do-load)
202      ("-l"      . command-line-do-load)
203      ("-insert" . command-line-do-insert)
204      ("-i"      . command-line-do-insert)
205      ("-kill"   . command-line-do-kill)
206      ;; Options like +35 are handled specially.
207      ;; Window-system, site, or package-specific code might add to this.
208      ;; X11 handles its options by letting Xt remove args from this list.
209      ))
210   "Alist of command-line switches.
211 Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
212 HANDLER-FUNCTION receives switch name as sole arg;
213 remaining command-line args are in the variable `command-line-args-left'.")
214
215 ;;; default switches
216 ;;; Note: these doc strings are semi-magical.
217
218 (defun command-line-do-help (arg)
219   "Print the XEmacs usage message and exit."
220   (let ((standard-output 'external-debugging-output))
221     (princ (concat "\n" (emacs-version) "\n\n"))
222     (princ
223      (if (featurep 'x)
224          (concat "When creating a window on an X display, "
225                  (emacs-name)
226                  " accepts all standard X Toolkit
227 command line options plus the following:
228   -iconname <title>     Use title as the icon name.
229   -mc <color>           Use color as the mouse color.
230   -cr <color>           Use color as the text-cursor foregound color.
231   -private              Install a private colormap.
232
233 In addition, the")
234        "The"))
235     (princ " following options are accepted:
236   -t <device>           Use TTY <device> instead of the terminal for input
237                         and output.  This implies the -nw option.
238   -nw                   Inhibit the use of any window-system-specific
239                         display code: use the current tty.
240   -batch                Execute noninteractively (messages go to stderr).
241   -debug-init           Enter the debugger if an error in the init file occurs.
242   -unmapped             Do not map the initial frame.
243   -no-site-file         Do not load the site-specific init file (site-start.el).
244   -no-init-file         Do not load the user-specific init file (~/.emacs).
245   -no-early-packages    Do not process early packages.
246   -no-autoloads         Do not load global symbol files (auto-autoloads) at
247                         startup.  Also implies `-vanilla'.
248   -vanilla              Equivalent to -q -no-site-file -no-early-packages.
249   -q                    Same as -no-init-file.
250   -user-init-file <file> Use <file> as init file.
251   -user-init-directory <directory> use <directory> as init directory.
252   -user <user>          Load user's init file instead of your own.
253                         Equivalent to -user-init-file ~<user>/.emacs
254                                       -user-init-directory ~<user>/.xemacs/
255   -u <user>             Same as -user.\n")
256    (let ((l command-switch-alist)
257           (insert (lambda (&rest x)
258                     (princ "  ")
259                     (let ((len 2))
260                       (while x
261                         (princ (car x))
262                         (incf len (length (car x)))
263                         (setq x (cdr x)))
264                       (when (>= len 24)
265                         (terpri) (setq len 0))
266                       (while (< len 24)
267                         (princ " ")
268                         (incf len))))))
269       (while l
270         (let ((name (car (car l)))
271               (fn (cdr (car l)))
272               doc arg cons)
273           (cond
274            ((and (symbolp fn) (get fn 'undocumented)) nil)
275            (t
276             (setq doc (documentation fn))
277             (if (member doc '(nil "")) (setq doc "(undocumented)"))
278             (cond ((string-match "\n\\(<.*>\\)\n?\\'" doc)
279                    ;; Doc of the form "The frobber switch\n<arg1> <arg2>"
280                    (setq arg (substring doc (match-beginning 1) (match-end 1))
281                          doc (substring doc 0 (match-beginning 0))))
282                   ((string-match "\n+\\'" doc)
283                    (setq doc (substring doc 0 (match-beginning 0)))))
284             (if (and (setq cons (rassq fn command-switch-alist))
285                      (not (eq cons (car l))))
286                 (setq doc (format "Same as %s." (car cons))))
287             (if arg
288                 (funcall insert name " " arg)
289               (funcall insert name))
290             (princ doc)
291             (terpri))))
292         (setq l (cdr l))))
293     (princ (concat "\
294   +N <file>             Start displaying <file> at line N.
295
296 Anything else is considered a file name, and is placed into a buffer for
297 editing.
298
299 " (emacs-name) " has an online tutorial and manuals.  Type ^Ht (Control-h t) after
300 starting XEmacs to run the tutorial.  Type ^Hi to enter the manual browser.
301 Type ^H^H^H (Control-h Control-h Control-h) to get more help options.\n")
302
303     (kill-emacs 0))))
304
305 (defun command-line-do-funcall (arg)
306   "Invoke the named lisp function with no arguments.
307 <function>"
308   (funcall (intern (pop command-line-args-left))))
309 (fset 'command-line-do-funcall-1 'command-line-do-funcall)
310 (put 'command-line-do-funcall-1 'undocumented t)
311
312 (defun command-line-do-eval (arg)
313   "Evaluate the lisp form.  Quote it carefully.
314 <form>"
315   (eval (read (pop command-line-args-left))))
316
317 (defun command-line-do-load (arg)
318   "Load the named file of Lisp code into XEmacs.
319 <file>"
320   (let ((file (pop command-line-args-left)))
321     ;; Take file from default dir if it exists there;
322     ;; otherwise let `load' search for it.
323     (if (file-exists-p (expand-file-name file))
324         (setq file (expand-file-name file)))
325     (load file nil t)))
326
327 (defun command-line-do-insert (arg)
328   "Insert file into the current buffer.
329 <file>"
330   (insert-file-contents (pop command-line-args-left)))
331
332 (defun command-line-do-kill (arg)
333   "Exit XEmacs."
334   (kill-emacs t))
335
336 (defun command-line-do-version (arg)
337   "Print version info and exit."
338   (princ (concat (emacs-version) "\n"))
339   (kill-emacs 0))
340
341 \f
342 ;;; Processing the command line and loading various init files
343
344 (defun early-error-handler (&rest debugger-args)
345   "You should probably not be using this."
346   ;; Used as the debugger during XEmacs initialization; if an error occurs,
347   ;; print some diagnostics, and kill XEmacs.
348
349   ;; output the contents of the warning buffer, since it won't be seen
350   ;; otherwise.
351   ;; #### kludge!  The call to Feval forces the pending warnings to
352   ;; get output.  There definitely needs to be a better way.
353   (let ((buffer (eval (get-buffer-create "*Warnings*"))))
354     (princ (buffer-substring (point-min buffer) (point-max buffer) buffer)
355            'external-debugging-output))
356
357   (let ((string "Initialization error")
358         (error (nth 1 debugger-args))
359         (debug-on-error nil)
360         (stream 'external-debugging-output))
361     (if (null error)
362         (princ string stream)
363       (princ (concat "\n" string ": ") stream)
364       (condition-case ()
365           (display-error error stream)
366         (error (princ "<<< error printing error message >>>" stream)))
367       (princ "\n" stream)
368       (if (memq (car-safe error) '(void-function void-variable))
369           (princ "
370         This probably means that XEmacs is picking up an old version of
371         the lisp library, or that some .elc files are not up-to-date.\n"
372                  stream)))
373     (when (not suppress-early-error-handler-backtrace)
374       (let ((print-length 1000)
375             (print-level 1000)
376             (print-escape-newlines t)
377             (print-readably nil))
378         (when (getenv "EMACSLOADPATH")
379           (princ (format "\n$EMACSLOADPATH is %s" (getenv "EMACSLOADPATH"))
380                  stream))
381         (princ (format "\nexec-directory is %S" exec-directory) stream)
382         (princ (format "\ndata-directory is %S" data-directory) stream)
383         (princ (format "\ndata-directory-list is %S" data-directory-list) stream)
384         (princ (format "\ndoc-directory is %S" doc-directory) stream)
385         (princ (format "\nload-path is %S" load-path) stream)
386         (princ "\n\n" stream)))
387     (when (not suppress-early-error-handler-backtrace)
388       (backtrace stream t)))
389   (if (fboundp 'mswindows-message-box)
390       (mswindows-message-box "Initialization error"))
391   (kill-emacs -1))
392
393 (defun normal-top-level ()
394   (if command-line-processed
395       (message "Back to top level.")
396     (setq command-line-processed t)
397     ;; Canonicalize HOME (PWD is canonicalized by init_buffer in buffer.c)
398     (let ((value (user-home-directory)))
399       (if (and value
400                (< (length value) (length default-directory))
401                (equal (file-attributes default-directory)
402                       (file-attributes value)))
403           (setq default-directory (file-name-as-directory value))))
404     (setq default-directory (abbreviate-file-name default-directory))
405     (initialize-xemacs-paths)
406
407     (startup-set-invocation-environment)
408
409     (let ((debug-paths (or debug-paths
410                            (and (getenv "EMACSDEBUGPATHS")
411                                 t))))
412
413       (setq emacs-roots (paths-find-emacs-roots invocation-directory
414                                                 invocation-name))
415
416       (if debug-paths
417           (princ (format "emacs-roots:\n%S\n" emacs-roots)
418                  'external-debugging-output))
419
420       (if (null emacs-roots)
421           (startup-find-roots-warning)
422         (startup-setup-paths emacs-roots
423                              user-init-directory
424                              inhibit-early-packages
425                              inhibit-site-lisp
426                              debug-paths))
427       (startup-setup-paths-warning))
428
429     (if (and (not inhibit-autoloads)
430              lisp-directory)
431         (load (expand-file-name (file-name-sans-extension autoload-file-name)
432                                 lisp-directory) nil t))
433
434     (if (not inhibit-autoloads)
435         (progn
436           (if (not inhibit-early-packages)
437               (packages-load-package-auto-autoloads early-package-load-path))
438           (packages-load-package-auto-autoloads late-package-load-path)
439           (packages-load-package-auto-autoloads last-package-load-path)))
440
441     (unwind-protect
442         (command-line)
443       ;; Do this again, in case .emacs defined more abbreviations.
444       (setq default-directory (abbreviate-file-name default-directory))
445       ;; Specify the file for recording all the auto save files of
446       ;; this session.  This is used by recover-session.
447       (setq auto-save-list-file-name
448             (expand-file-name
449              (format "%s%d-%s"
450                      auto-save-list-file-prefix
451                      (emacs-pid)
452                      (system-name))))
453       (run-hooks 'emacs-startup-hook)
454       (and term-setup-hook
455            (run-hooks 'term-setup-hook))
456       (setq term-setup-hook nil)
457       ;;      ;; Modify the initial frame based on what .emacs puts into
458       ;;      ;; ...-frame-alist.
459       (frame-notice-user-settings)
460       ;;      ;;####FSFmacs junk
461       ;;      ;; Now we know the user's default font, so add it to the menu.
462       ;;      (if (fboundp 'font-menu-add-default)
463       ;;          (font-menu-add-default))
464       (when window-setup-hook
465         (run-hooks 'window-setup-hook))
466       (setq window-setup-hook nil))
467
468     (if load-user-init-file-p
469         (maybe-migrate-user-init-file))
470     ;;####FSFmacs junk
471     ;;      (or menubar-bindings-done
472     ;;    (precompute-menubar-bindings))
473     ))
474
475 ;;####FSFmacs junk
476 ;;; Precompute the keyboard equivalents in the menu bar items.
477 ;;(defun precompute-menubar-bindings ()
478 ;;  (if (eq window-system 'x)
479 ;;      (let ((submap (lookup-key global-map [menu-bar])))
480 ;;      (while submap
481 ;;        (and (consp (car submap))
482 ;;             (symbolp (car (car submap)))
483 ;;             (stringp (car-safe (cdr (car submap))))
484 ;;             (keymapp (cdr (cdr (car submap))))
485 ;;             (x-popup-menu nil (cdr (cdr (car submap)))))
486 ;;        (setq submap (cdr submap))))))
487
488 (defun command-line-early (args)
489   ;; This processes those switches which need to be processed before
490   ;; starting up the window system.
491
492   (setq command-line-default-directory default-directory)
493
494   ;; See if we should import version-control from the environment variable.
495   (let ((vc (getenv "VERSION_CONTROL")))
496     (cond ((eq vc nil))                 ;don't do anything if not set
497           ((or (string= vc "t")
498                (string= vc "numbered"))
499            (setq version-control t))
500           ((or (string= vc "nil")
501                (string= vc "existing"))
502            (setq version-control nil))
503           ((or (string= vc "never")
504                (string= vc "simple"))
505            (setq version-control 'never))))
506
507   ;;####FSFmacs
508   ;;  (if (let ((ctype
509   ;;         ;; Use the first of these three envvars that has a nonempty value.
510   ;;         (or (let ((string (getenv "LC_ALL")))
511   ;;               (and (not (equal string "")) string))
512   ;;             (let ((string (getenv "LC_CTYPE")))
513   ;;               (and (not (equal string "")) string))
514   ;;             (let ((string (getenv "LANG")))
515   ;;               (and (not (equal string "")) string)))))
516   ;;    (and ctype
517   ;;         (string-match iso-8859-1-locale-regexp ctype)))
518   ;;      (progn
519   ;;    (standard-display-european t)
520   ;;    (require 'iso-syntax)))
521
522   (setq load-user-init-file-p (not (noninteractive)))
523
524   ;; Allow (at least) these arguments anywhere in the command line
525   (let ((new-args nil)
526         (arg      nil))
527     (while args
528       (setq arg (pop args))
529       (cond
530        ((or (string= arg "-q")
531             (string= arg "-no-init-file"))
532         (setq load-user-init-file-p nil))
533        ((string= arg "-no-site-file")
534         (setq site-start-file nil))
535        ((or (string= arg "-no-early-packages")
536             (string= arg "--no-early-packages"))
537         (setq inhibit-early-packages t))
538        ((or (string= arg "-vanilla")
539             (string= arg "--vanilla")
540             ;; Some work on this one already done in emacs.c.
541             (string= arg "-no-autoloads")
542             (string= arg "--no-autoloads"))
543         (setq load-user-init-file-p nil
544               site-start-file nil))
545        ((string= arg "-user-init-file")
546         (setq user-init-file (pop args)))
547        ((string= arg "-user-init-directory")
548         (setq user-init-directory (file-name-as-directory (pop args))))
549        ((or (string= arg "-u")
550             (string= arg "-user"))
551         (let* ((user (pop args))
552                (home-user (concat "~" user)))
553           (setq user-init-directory (file-name-as-directory
554                                      (paths-construct-path
555                                       (list home-user user-init-directory-base))))
556           (setq user-init-file
557                 (find-user-init-file user-init-directory home-user))
558           (setq custom-file
559                 (make-custom-file-name user-init-file))))
560        ((string= arg "-debug-init")
561         (setq init-file-debug t))
562        ((string= arg "-unmapped")
563         (setq initial-frame-unmapped-p t))
564        ((or (string= arg "-debug-paths")
565             (string= arg "--debug-paths"))
566         t)
567        ((or (string= arg "--") (string= arg "-"))
568         (while args
569           (push (pop args) new-args)))
570        (t (push arg new-args))))
571
572     (setq init-file-user (and load-user-init-file-p ""))
573
574     (nreverse new-args)))
575
576 (defconst initial-scratch-message "\
577 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
578 ;; If you want to create a file, first visit that file with C-x C-f,
579 ;; then enter the text in that file's own buffer.
580
581 "
582   "Initial message displayed in *scratch* buffer at startup.
583 If this is nil, no message will be displayed.")
584
585 (defun command-line ()
586   (let ((command-line-args-left (cdr command-line-args)))
587
588     (let ((debugger 'early-error-handler)
589           (debug-on-error t))
590
591       ;; Process magic command-line switches like -q and -u.  Do this
592       ;; before creating the first frame because some of these switches
593       ;; may affect that.  I think it's ok to do this before establishing
594       ;; the X connection, and maybe someday things like -nw can be
595       ;; handled here instead of down in C.
596       (setq command-line-args-left (command-line-early command-line-args-left))
597
598       ;; Setup the toolbar icon directory
599       (when (featurep 'toolbar)
600         (init-toolbar-location))
601
602       ;; Run the window system's init function.  tty is considered to be
603       ;; a type of window system for this purpose.  This creates the
604       ;; initial (non stdio) device.
605       (when (and initial-window-system (not noninteractive))
606         (funcall (intern (concat "init-"
607                                  (symbol-name initial-window-system)
608                                  "-win"))))
609
610       ;; When not in batch mode, this creates the first visible frame,
611       ;; and deletes the stdio device.
612       (frame-initialize))
613
614     ;; Reinitialize faces if necessary.  This function changes face if
615     ;; it is created during auto-autoloads loading.  Otherwise, it
616     ;; does nothing.
617     (startup-initialize-custom-faces)
618
619     ;;
620     ;; We have normality, I repeat, we have normality.  Anything you still
621     ;; can't cope with is therefore your own problem.  (And we don't need
622     ;; to kill XEmacs for it.)
623     ;;
624
625     ;;; Load init files.
626     (load-init-file)
627
628     (with-current-buffer (get-buffer "*scratch*")
629       (erase-buffer)
630       ;; (insert initial-scratch-message)
631       (set-buffer-modified-p nil)
632       (when (eq major-mode 'fundamental-mode)
633         (funcall initial-major-mode)))
634
635     ;; Load library for our terminal type.
636     ;; User init file can set term-file-prefix to nil to prevent this.
637     ;; Note that for any TTY's opened subsequently, the TTY init
638     ;; code will run this.
639     (when (and (eq 'tty (console-type))
640                (not (noninteractive)))
641       (load-terminal-library))
642
643     ;; Process the remaining args.
644     (command-line-1)
645
646     ;; it was turned on by default so that the warnings don't get displayed
647     ;; until after the splash screen.
648     (setq inhibit-warning-display nil)
649     ;; If -batch, terminate after processing the command options.
650     (when (noninteractive) (kill-emacs t))))
651
652 (defun load-terminal-library ()
653   (when term-file-prefix
654     (let ((term (getenv "TERM"))
655           hyphend)
656       (while (and term
657                   (not (load (concat term-file-prefix term) t t)))
658         ;; Strip off last hyphen and what follows, then try again
659         (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
660             (setq term (substring term 0 hyphend))
661           (setq term nil))))))
662
663 (defun find-user-init-directory-init-file (&optional init-directory)
664   "Determine the user's init file if in the init directory."
665   (let ((init-directory (or init-directory user-init-directory)))
666     (catch 'found
667       (dolist (file user-init-file-base-list)
668         (let ((expanded (expand-file-name file init-directory)))
669           (when (file-readable-p expanded)
670             (throw 'found expanded)))))))
671
672 (defun find-user-home-directory-init-file (&optional home-directory)
673   "Determine the user's init file if in the home directory."
674   (let ((home-directory (or home-directory "~")))
675     (catch 'found
676       (dolist (file user-home-init-file-base-list)
677         (let ((expanded (expand-file-name file home-directory)))
678           (when (file-readable-p expanded)
679             (throw 'found expanded))))
680       nil)))
681
682 (defun find-user-init-file (&optional init-directory home-directory)
683   "Determine the user's init file."
684   (if load-home-init-file
685       (find-user-home-directory-init-file home-directory)
686     (or (find-user-init-directory-init-file init-directory)
687         (find-user-home-directory-init-file home-directory))))
688
689 (defun maybe-migrate-user-init-file ()
690   "Ask user if she wants to migrate the init file(s) to new location."
691   (if (and (not load-home-init-file)
692            (not (find-user-init-directory-init-file user-init-directory))
693            (stringp user-init-file)
694            (file-readable-p user-init-file))
695       (if (with-output-to-temp-buffer (help-buffer-name nil)
696             (progn
697               (princ "XEmacs recommends that the initialization code in
698 ")
699               (princ user-init-file)
700               (princ "
701 be migrated to the ")
702               (princ user-init-directory)
703               (princ " directory.  XEmacs can
704 perform the migration automatically.
705
706 After the migration, init.el/init.elc holds user-written
707 initialization code.  Moreover the customize settings will be in
708 custom.el.
709
710 If you choose not to do this now, XEmacs will not ask you this
711 question in the future.  However, you can still make XEmacs
712 perform the migration at any time with M-x migrate-user-init-file.")
713               (show-temp-buffer-in-current-frame standard-output)
714               (yes-or-no-p-minibuf (concat "Migrate init file to "
715                                            user-init-directory
716                                            "? "))))
717           (migrate-user-init-file)
718         (customize-save-variable 'load-home-init-file t))))
719
720 (defun migrate-user-init-file ()
721   "Migrate the init file from the home directory."
722   (interactive)
723   (if (not (file-exists-p user-init-directory))
724       (progn
725         (message "Creating %s directory..." user-init-directory)
726         (make-directory user-init-directory)))
727   (message "Migrating custom file...")
728   (custom-migrate-custom-file (make-custom-file-name user-init-file
729                                                      'force-new))
730   (message "Moving init file...")
731   (rename-file user-init-file
732                (expand-file-name user-init-file-base
733                                  user-init-directory))
734   (message "Migration done."))
735
736 (defun load-user-init-file ()
737   "This function actually reads the init file."
738   (if (not user-init-file)
739       (setq user-init-file
740             (find-user-init-file user-init-directory)))
741   (if (and user-init-file
742            (file-readable-p user-init-file))
743       (load user-init-file t t t))
744   (if (not custom-file)
745       (setq custom-file (make-custom-file-name user-init-file)))
746   (if (and custom-file
747            (or (not user-init-file)
748                (not (string= custom-file user-init-file)))
749            (file-readable-p custom-file))
750       (load custom-file t t t))
751   (unless inhibit-default-init
752     (let ((inhibit-startup-message nil))
753       ;; Users are supposed to be told their rights.
754       ;; (Plus how to get help and how to undo.)
755       ;; Don't you dare turn this off for anyone except yourself.
756       (load "default" t t))))
757
758 ;;; Load user's init file and default ones.
759 (defun load-init-file ()
760   (run-hooks 'before-init-hook)
761
762   ;; Run the site-start library if it exists.  The point of this file is
763   ;; that it is run before .emacs.  There is no point in doing this after
764   ;; .emacs; that is useless.
765   (when site-start-file
766     (load site-start-file t t))
767
768   ;; Sites should not disable this.  Only individuals should disable
769   ;; the startup message.
770   (setq inhibit-startup-message nil)
771
772   (let (debug-on-error-from-init-file
773         debug-on-error-should-be-set
774         (debug-on-error-initial
775          (if (eq init-file-debug t) 'startup init-file-debug)))
776     (let ((debug-on-error debug-on-error-initial))
777       (if (and load-user-init-file-p init-file-debug)
778           (progn
779             ;; Do this without a condition-case if the user wants to debug.
780             (load-user-init-file))
781         (condition-case error
782             (progn
783               (if load-user-init-file-p
784                   (load-user-init-file))
785               (setq init-file-had-error nil))
786           (error
787            (message "Error in init file: %s" (error-message-string error))
788            (display-warning 'initialization
789              (format "\
790 An error has occurred while loading %s:
791
792 %s
793
794 To ensure normal operation, you should investigate the cause of the error
795 in your initialization file and remove it.  Use the `-debug-init' option
796 to XEmacs to view a complete error backtrace."
797                      user-init-file (error-message-string error))
798              'error)
799            (setq init-file-had-error t))))
800       ;; If we can tell that the init file altered debug-on-error,
801       ;; arrange to preserve the value that it set up.
802       (or (eq debug-on-error debug-on-error-initial)
803           (setq debug-on-error-should-be-set t
804                 debug-on-error-from-init-file debug-on-error)))
805     (when debug-on-error-should-be-set
806       (setq debug-on-error debug-on-error-from-init-file)))
807
808   (setq init-file-loaded t)
809
810   ;; Do this here in case the init file sets mail-host-address.
811   ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
812   ;; (or user-mail-address
813   (when noninteractive
814     (setq user-mail-address (concat (user-login-name) "@"
815                                     (or mail-host-address
816                                         (system-name)))))
817
818   (run-hooks 'after-init-hook)
819   nil)
820
821 (defun load-options-file (filename)
822   "Load the file of saved options (from the Options menu) called FILENAME.
823 Currently this does nothing but call `load', but it might be redefined
824 in the future to support automatically converting older options files to
825 a new format, when variables have changed, etc."
826   (load filename))
827
828 (defun command-line-1 ()
829   (cond
830    ((null command-line-args-left)
831     (unless noninteractive
832       ;; If there are no switches to process, run the term-setup-hook
833       ;; before displaying the copyright notice; there may be some need
834       ;; to do it before doing any output.  If we're not going to
835       ;; display a copyright notice (because other options are present)
836       ;; then this is run after those options are processed.
837       (run-hooks 'term-setup-hook)
838       ;; Don't let the hook be run twice.
839       (setq term-setup-hook nil)
840
841       ;; Don't clobber a non-scratch buffer if init file
842       ;; has selected it.
843       (when (string= (buffer-name) "*scratch*")
844         (unless (or inhibit-startup-message
845                     (input-pending-p))
846           (let (tmout circ-tmout)
847             (unwind-protect
848                 ;; Guts of with-timeout
849                 (catch 'tmout
850                   (setq tmout (add-timeout startup-message-timeout
851                                            (lambda (ignore)
852                                              (condition-case nil
853                                                  (throw 'tmout t)
854                                                (error nil)))
855                                            nil))
856                   (setq circ-tmout (display-splash-frame))
857                   (or nil;; (pos-visible-in-window-p (point-min))
858                       (goto-char (point-min)))
859                   (sit-for 0)
860                   (setq unread-command-event (next-command-event)))
861               (when tmout (disable-timeout tmout))
862               (when circ-tmout (disable-timeout circ-tmout)))))
863         (with-current-buffer (get-buffer "*scratch*")
864           ;; In case the XEmacs server has already selected
865           ;; another buffer, erase the one our message is in.
866           (erase-buffer)
867           (when (stringp initial-scratch-message)
868             (insert initial-scratch-message))
869           (set-buffer-modified-p nil)))))
870
871    (t
872     ;; Command-line-options exist
873     (let ((dir command-line-default-directory)
874           (file-count 0)
875           (line nil)
876           (end-of-options nil)
877           file-p arg tem)
878       (while command-line-args-left
879         (setq arg (pop command-line-args-left))
880         (cond
881          (end-of-options
882           (setq file-p t))
883          ((setq tem (when (eq (aref arg 0) ?-)
884                       (or (assoc arg command-switch-alist)
885                           (assoc (substring arg 1)
886                                  command-switch-alist))))
887           (funcall (cdr tem) arg))
888          ((string-match "\\`\\+[0-9]+\\'" arg)
889           (setq line (string-to-int arg)))
890          ;; "- file" means don't treat "file" as a switch
891          ;;  ("+0 file" has the same effect; "-" added
892          ;;   for unixoidiality).
893          ;; This is worthless; the `unixoid' way is "./file". -jwz
894          ((or (string= arg "-") (string= arg "--"))
895           (setq end-of-options t))
896          (t
897           (setq file-p t)))
898
899         (when file-p
900           (setq file-p nil)
901           (incf file-count)
902           (setq arg (expand-file-name arg dir))
903           (cond
904            ((= file-count 1)
905             (find-file arg))
906            (noninteractive (find-file arg))
907            (t (find-file-other-window arg)))
908           (when line
909             (goto-line line)
910             (setq line nil))))))))
911
912 (defvar startup-presentation-hack-keymap
913   (let ((map (make-sparse-keymap)))
914     (set-keymap-name map 'startup-presentation-hack-keymap)
915     (define-key map '[button1] 'startup-presentation-hack)
916     (define-key map '[button2] 'startup-presentation-hack)
917     map)
918   "Putting yesterday in the future tomorrow.")
919
920 (defun startup-presentation-hack ()
921   (interactive)
922   (let ((e last-command-event))
923     (and (button-press-event-p e)
924          (setq e (extent-at (event-point e)
925                             (event-buffer e)
926                             'startup-presentation-hack))
927          (setq e (extent-property e 'startup-presentation-hack))
928          (if (consp e)
929              (apply (car e) (cdr e))
930            (while (keymapp (indirect-function e))
931              (let ((map e)
932                    (overriding-local-map (indirect-function e)))
933                (setq e (read-key-sequence
934                         (let ((p (keymap-prompt map t)))
935                           (cond ((symbolp map)
936                                  (if p
937                                      (format "%s %s " map p)
938                                    (format "%s " map)))
939                                 (p)
940                                 (t
941                                  (prin1-to-string map))))))
942                (if (and (button-release-event-p (elt e 0))
943                         (null (key-binding e)))
944                    (setq e map)         ; try again
945                  (setq e (key-binding e)))))
946            (call-interactively e)))))
947
948 (defun startup-presentation-hack-help (e)
949   (setq e (extent-property e 'startup-presentation-hack))
950   (if (consp e)
951       (format "Evaluate %S" e)
952     (symbol-name e)))
953
954 (defun splash-frame-present-hack (e v)
955   ;;   (set-extent-property e 'mouse-face 'highlight)
956   ;;   (set-extent-property e 'keymap
957   ;;                           startup-presentation-hack-keymap)
958   ;;   (set-extent-property e 'startup-presentation-hack v)
959   ;;   (set-extent-property e 'help-echo
960   ;;                           'startup-presentation-hack-help)
961   )
962
963 (defun splash-hack-version-string ()
964   (save-excursion
965     (save-restriction
966       (goto-char (point-min))
967       (re-search-forward "^XEmacs" nil t)
968       (narrow-to-region (point-at-bol) (point-at-eol))
969       (goto-char (point-min))
970       (when (re-search-forward " \\[Lucid\\]" nil t)
971         (delete-region (match-beginning 0) (match-end 0)))
972       (when (re-search-forward "[^(][^)]*-[^)]*-" nil t)
973         (delete-region (1+ (match-beginning 0)) (match-end 0))
974         (insert "("))
975       (goto-char (point-max))
976       (search-backward " " nil t)
977       (when (search-forward "." nil t)
978         (delete-region (1- (point)) (point-max))))))
979
980 (defun splash-frame-present (l)
981   (cond ((stringp l)
982          (insert l))
983         ((eq (car-safe l) 'face)
984          ;; (face name string)
985          (let ((p (point)))
986            (splash-frame-present (elt l 2))
987            (if (fboundp 'set-extent-face)
988                (set-extent-face (make-extent p (point))
989                                 (elt l 1)))))
990         ((eq (car-safe l) 'key)
991          (let* ((c (elt l 1))
992                 (p (point))
993                 (k (where-is-internal c nil t)))
994            (insert (if k (key-description k)
995                      (format "M-x %s" c)))
996            (if (fboundp 'set-extent-face)
997                (let ((e (make-extent p (point))))
998                  (set-extent-face e 'bold)
999                  (splash-frame-present-hack e c)))))
1000         ((eq (car-safe l) 'funcall)
1001          ;; (funcall (fun . args) string)
1002          (let ((p (point)))
1003            (splash-frame-present (elt l 2))
1004            (if (fboundp 'set-extent-face)
1005                (splash-frame-present-hack (make-extent p (point))
1006                                           (elt l 1)))))
1007         ((consp l)
1008          (mapcar 'splash-frame-present l))
1009         (t
1010          (error "WTF!?"))))
1011
1012 (defun startup-center-spaces (glyph)
1013   ;; Return the number of spaces to insert in order to center
1014   ;; the given glyph (may be a string or a pixmap).
1015   ;; Assume spaces are as wide as avg-pixwidth.
1016   ;; Won't be quite right for proportional fonts, but it's the best we can do.
1017   ;; Maybe the new redisplay will export something a glyph-width function.
1018   ;;; #### Yes, there is a glyph-width function but it isn't quite what
1019   ;;; #### this was expecting.  Or is it?
1020   ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
1021   ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
1022
1023   ;; This function is used in about.el too.
1024   (let* ((avg-pixwidth     (round (/ (frame-pixel-width) (frame-width))))
1025          (fill-area-width  (* avg-pixwidth (- fill-column left-margin)))
1026          (glyph-pixwidth   (cond ((stringp glyph)
1027                                   (* avg-pixwidth (length glyph)))
1028                                  ;; #### the pixmap option should be removed
1029                                  ;;((pixmapp glyph)
1030                                  ;; (pixmap-width glyph))
1031                                  ((glyphp glyph)
1032                                   (glyph-width glyph))
1033                                  (t
1034                                   (error "startup-center-spaces: bad arg")))))
1035     (+ left-margin
1036        (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
1037
1038 (defun splash-frame-body ()
1039   `[((face (blue bold underline)
1040            "\nDistribution, copying license, warranty:\n\n")
1041      "Please visit the XEmacs website at http://www.xemacs.org !\n\n"
1042      ,@(if (featurep 'sparcworks)
1043            `( "\
1044 Sun provides support for the WorkShop/XEmacs integration package only.
1045 All other XEmacs packages are provided to you \"AS IS\".\n"
1046               ,@(let ((lang (or (getenv "LC_ALL") (getenv "LC_MESSAGES")
1047                                 (getenv "LANG"))))
1048                   (if (and
1049                        (not (featurep 'mule)) ;; Already got mule?
1050                        ;; No Mule support on tty's yet
1051                        (not (eq 'tty (console-type)))
1052                        lang ;; Non-English locale?
1053                        (not (string= lang "C"))
1054                        (not (string-match "^en" lang))
1055                        ;; Comes with Sun WorkShop
1056                        (locate-file "xemacs-mule" exec-path))
1057                       '( "\
1058 This version of XEmacs has been built with support for Latin-1 languages only.
1059 To handle other languages you need to run a Multi-lingual (`Mule') version of
1060 XEmacs, by either running the command `xemacs-mule', or by using the X resource
1061 `ESERVE*defaultXEmacsPath: xemacs-mule' when starting XEmacs from Sun WorkShop.
1062 \n")))))
1063      ((key describe-no-warranty)
1064       ": "(face (red bold) "XEmacs comes with ABSOLUTELY NO WARRANTY\n"))
1065      ((key describe-copying)
1066       ": conditions to give out copies of XEmacs\n")
1067      ((key describe-distribution)
1068       ": how to get the latest version\n")
1069      "\n--\n"
1070      (face italic "\
1071 Copyright (C) 1985-1999 Free Software Foundation, Inc.
1072 Copyright (C) 1990-1994 Lucid, Inc.
1073 Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
1074 Copyright (C) 1994-1996 Board of Trustees, University of Illinois
1075 Copyright (C) 1995-1996 Ben Wing\n"))
1076
1077     ((face (blue bold underline) "\nInformation, on-line help:\n\n")
1078      "XEmacs comes with plenty of documentation...\n\n"
1079      ,@(if (string-match "beta" emacs-version)
1080            `((key describe-beta)
1081              ": " (face (red bold)
1082                         "This is an Experimental version of XEmacs.\n"))
1083          `( "\n"))
1084      ((key xemacs-local-faq)
1085       ": read the XEmacs FAQ (a " (face underline "capital") " F!)\n")
1086      ((key help-with-tutorial)
1087       ": read the XEmacs tutorial (also available through the "
1088       (face bold "Help") " menu)\n")
1089      ((key help-command)
1090       ": get help on using XEmacs (also available through the "
1091       (face bold "Help") " menu)\n")
1092      ((key info) ": read the on-line documentation\n\n")
1093      ((key describe-project) ": read about the GNU project\n")
1094      ((key about-xemacs) ": see who's developing XEmacs\n"))
1095
1096     ((face (blue bold underline) "\nUseful stuff:\n\n")
1097      "Things that you should know rather quickly...\n\n"
1098      ((key find-file) ": visit a file\n")
1099      ((key save-buffer) ": save changes\n")
1100      ((key advertised-undo) ": undo changes\n")
1101      ((key save-buffers-kill-emacs) ": exit XEmacs\n"))
1102     ])
1103
1104 ;; I really hate global variables, oh well.
1105 ;(defvar xemacs-startup-logo-function nil
1106 ;  "If non-nil, function called to provide the startup logo.
1107 ;This function should return an initialized glyph if it is used.")
1108
1109 ;; This will hopefully go away when gettext is functional.
1110 (defconst splash-frame-static-body
1111   `(,(emacs-version) "\n\n"
1112     (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
1113
1114
1115 (defun circulate-splash-frame-elements (client-data)
1116   (with-current-buffer (aref client-data 2)
1117     (let ((buffer-read-only nil)
1118           (elements (aref client-data 3))
1119           (indice (aref client-data 0)))
1120       (goto-char (aref client-data 1))
1121       (delete-region (point) (point-max))
1122       (splash-frame-present (aref elements indice))
1123       (set-buffer-modified-p nil)
1124       (aset client-data 0
1125             (if (= indice (- (length elements) 1))
1126                 0
1127               (1+ indice )))
1128       )))
1129
1130 ;; #### This function now returns the (possibly nil) timeout circulating the
1131 ;; splash-frame elements
1132 (defun display-splash-frame ()
1133   (let ((logo xemacs-logo)
1134         (buffer-read-only nil)
1135         (cramped-p (eq 'tty (console-type))))
1136     (unless cramped-p (insert "\n"))
1137     (indent-to (startup-center-spaces logo))
1138     (set-extent-begin-glyph (make-extent (point) (point)) logo)
1139     ;;(splash-frame-present-hack (make-extent p (point)) 'about-xemacs))
1140     (insert "\n\n")
1141     (splash-frame-present splash-frame-static-body)
1142     (splash-hack-version-string)
1143     (goto-char (point-max))
1144     (let* ((after-change-functions nil) ; no font-lock, thank you
1145            (elements (splash-frame-body))
1146            (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1147            tmout)
1148       (if (listp  elements) ;; A single element to display
1149           (splash-frame-present (splash-frame-body))
1150         ;; several elements to rotate
1151         (splash-frame-present (aref elements 0))
1152         (setq tmout (add-timeout splash-frame-timeout
1153                                  'circulate-splash-frame-elements
1154                                  client-data splash-frame-timeout)))
1155       (set-buffer-modified-p nil)
1156       tmout)))
1157
1158 ;;  (let ((present-file
1159 ;;         #'(lambda (f)
1160 ;;             (splash-frame-present
1161 ;;            (list 'funcall
1162 ;;                  (list 'find-file-other-window
1163 ;;                        (expand-file-name f data-directory))
1164 ;;                  f)))))
1165 ;;    (insert "For customization examples, see the files ")
1166 ;;    (funcall present-file "sample.emacs")
1167 ;;    (insert " and ")
1168 ;;    (funcall present-file "sample.Xdefaults")
1169 ;;    (insert (format "\nin the directory %s." data-directory)))
1170
1171 (defun startup-set-invocation-environment ()
1172   ;; XEmacs -- Steven Baur says invocation directory is nil if you
1173   ;; try to use XEmacs as a login shell.
1174   (or invocation-directory (setq invocation-directory default-directory))
1175   (setq invocation-directory
1176         ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1177         (abbreviate-file-name invocation-directory)))
1178
1179 (defun startup-setup-paths (roots user-init-directory
1180                                   &optional
1181                                   inhibit-early-packages inhibit-site-lisp
1182                                   debug-paths)
1183   "Setup all the various paths.
1184 ROOTS is a list of plausible roots of the XEmacs directory hierarchy.
1185 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1186 If INHIBIT-SITE-LISP is non-NIL, don't do site-lisp.
1187 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1188 It's idempotent, so call this as often as you like!"
1189
1190   (apply #'(lambda (early late last)
1191              (setq early-packages (and (not inhibit-early-packages)
1192                                        early))
1193              (setq late-packages late)
1194              (setq last-packages last))
1195          (packages-find-packages
1196           roots
1197           (packages-compute-package-locations user-init-directory)))
1198
1199   (setq early-package-load-path (packages-find-package-load-path early-packages))
1200   (setq late-package-load-path (packages-find-package-load-path late-packages))
1201   (setq last-package-load-path (packages-find-package-load-path last-packages))
1202
1203   (if debug-paths
1204       (progn
1205         (princ (format "configure-package-path:\n%S\n" configure-package-path)
1206                'external-debugging-output)
1207         (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1208                        early-packages early-package-load-path)
1209                'external-debugging-output)
1210         (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1211                        late-packages late-package-load-path)
1212                'external-debugging-output)
1213         (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1214                        last-packages last-package-load-path)
1215                'external-debugging-output)))
1216
1217   (setq lisp-directory (paths-find-lisp-directory roots))
1218
1219   (if debug-paths
1220       (princ (format "lisp-directory:\n%S\n" lisp-directory)
1221              'external-debugging-output))
1222
1223   (setq site-directory (and (null inhibit-site-lisp)
1224                             (paths-find-site-lisp-directory roots)))
1225
1226   (if (and debug-paths (null inhibit-site-lisp))
1227       (princ (format "site-directory:\n%S\n" site-directory)
1228              'external-debugging-output))
1229
1230   (setq load-path (paths-construct-load-path roots
1231                                              early-package-load-path
1232                                              late-package-load-path
1233                                              last-package-load-path
1234                                              lisp-directory
1235                                              site-directory))
1236
1237   (setq Info-directory-list
1238         (paths-construct-info-path roots
1239                                    early-packages late-packages last-packages))
1240
1241
1242   (if debug-paths
1243       (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1244              'external-debugging-output))
1245
1246   (setq exec-directory (paths-find-exec-directory roots))
1247
1248   (if debug-paths
1249       (princ (format "exec-directory:\n%s\n" exec-directory)
1250              'external-debugging-output))
1251
1252   (setq exec-path
1253         (paths-construct-exec-path roots exec-directory
1254                                    early-packages late-packages last-packages))
1255
1256   (if debug-paths
1257       (princ (format "exec-path:\n%S\n" exec-path)
1258              'external-debugging-output))
1259
1260   (setq doc-directory (paths-find-doc-directory roots))
1261
1262   (if debug-paths
1263       (princ (format "doc-directory:\n%S\n" doc-directory)
1264              'external-debugging-output))
1265
1266   (setq data-directory (paths-find-data-directory roots))
1267
1268   (if debug-paths
1269       (princ (format "data-directory:\n%S\n" data-directory)
1270              'external-debugging-output))
1271
1272   (setq data-directory-list (paths-construct-data-directory-list data-directory
1273                                                                  early-packages
1274                                                                  late-packages
1275                                                                  last-packages))
1276   (if debug-paths
1277       (princ (format "data-directory-list:\n%S\n" data-directory-list)
1278              'external-debugging-output)))
1279
1280 (defun startup-find-roots-warning ()
1281   (save-excursion
1282     (set-buffer (get-buffer-create " *warning-tmp*"))
1283     (erase-buffer)
1284     (buffer-disable-undo (current-buffer))
1285
1286     (insert "Couldn't find an obvious default for the root of the\n"
1287             "XEmacs hierarchy.")
1288
1289     (princ "\nWARNING:\n" 'external-debugging-output)
1290     (princ (buffer-string) 'external-debugging-output)))
1291
1292 (defun startup-setup-paths-warning ()
1293   (let ((warnings '()))
1294     (cond
1295      ((null (and lisp-directory exec-directory data-directory doc-directory
1296                  load-path))
1297       (save-excursion
1298         (set-buffer (get-buffer-create " *warning-tmp*"))
1299         (erase-buffer)
1300         (buffer-disable-undo (current-buffer))
1301         (if (null lisp-directory) (push "lisp-directory" warnings))
1302         (if (null exec-directory) (push "exec-directory" warnings))
1303         (if (null data-directory) (push "data-directory" warnings))
1304         (if (null doc-directory)  (push "doc-directory"  warnings))
1305         (if (null load-path)      (push "load-path"      warnings))
1306
1307         (insert "Couldn't find obvious defaults for:\n")
1308         (while warnings
1309           (insert (car warnings) "\n")
1310           (setq warnings (cdr warnings)))
1311         (insert "Perhaps some directories don't exist, "
1312                 "or the XEmacs executable,\n" (concat invocation-directory
1313                                                      invocation-name)
1314                 "\nis in a strange place?")
1315
1316         (princ "\nWARNING:\n" 'external-debugging-output)
1317         (princ (buffer-string) 'external-debugging-output)
1318         (erase-buffer)
1319         t)))))
1320
1321 ;;; startup.el ends here