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