Sync with r21_2_36.
[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 (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     (when (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       (if (featurep 'utf-2000)
434           (load (expand-file-name
435                  (file-name-sans-extension autoload-file-name)
436                  (expand-file-name "utf-2000" lisp-directory))
437                 nil t)))
438
439     (if (not inhibit-autoloads)
440         (progn
441           (if (not inhibit-early-packages)
442               (packages-load-package-auto-autoloads early-package-load-path))
443           (packages-load-package-auto-autoloads late-package-load-path)
444           (packages-load-package-auto-autoloads last-package-load-path)))
445
446     (unwind-protect
447         (command-line)
448       ;; Do this again, in case .emacs defined more abbreviations.
449       (setq default-directory (abbreviate-file-name default-directory))
450       ;; Specify the file for recording all the auto save files of
451       ;; this session.  This is used by recover-session.
452       (setq auto-save-list-file-name
453             (expand-file-name
454              (format "%s%d-%s"
455                      auto-save-list-file-prefix
456                      (emacs-pid)
457                      (system-name))))
458       (run-hooks 'emacs-startup-hook)
459       (and term-setup-hook
460            (run-hooks 'term-setup-hook))
461       (setq term-setup-hook nil)
462       ;;      ;; Modify the initial frame based on what .emacs puts into
463       ;;      ;; ...-frame-alist.
464       (frame-notice-user-settings)
465       ;;      ;;####FSFmacs junk
466       ;;      ;; Now we know the user's default font, so add it to the menu.
467       ;;      (if (fboundp 'font-menu-add-default)
468       ;;          (font-menu-add-default))
469       (when window-setup-hook
470         (run-hooks 'window-setup-hook))
471       (setq window-setup-hook nil))
472
473     (if load-user-init-file-p
474         (maybe-migrate-user-init-file))
475     ;;####FSFmacs junk
476     ;;      (or menubar-bindings-done
477     ;;    (precompute-menubar-bindings))
478     ))
479
480 ;;####FSFmacs junk
481 ;;; Precompute the keyboard equivalents in the menu bar items.
482 ;;(defun precompute-menubar-bindings ()
483 ;;  (if (eq window-system 'x)
484 ;;      (let ((submap (lookup-key global-map [menu-bar])))
485 ;;      (while submap
486 ;;        (and (consp (car submap))
487 ;;             (symbolp (car (car submap)))
488 ;;             (stringp (car-safe (cdr (car submap))))
489 ;;             (keymapp (cdr (cdr (car submap))))
490 ;;             (x-popup-menu nil (cdr (cdr (car submap)))))
491 ;;        (setq submap (cdr submap))))))
492
493 (defun command-line-early (args)
494   ;; This processes those switches which need to be processed before
495   ;; starting up the window system.
496
497   (setq command-line-default-directory default-directory)
498
499   ;; See if we should import version-control from the environment variable.
500   (let ((vc (getenv "VERSION_CONTROL")))
501     (cond ((eq vc nil))                 ;don't do anything if not set
502           ((or (string= vc "t")
503                (string= vc "numbered"))
504            (setq version-control t))
505           ((or (string= vc "nil")
506                (string= vc "existing"))
507            (setq version-control nil))
508           ((or (string= vc "never")
509                (string= vc "simple"))
510            (setq version-control 'never))))
511
512   ;;####FSFmacs
513   ;;  (if (let ((ctype
514   ;;         ;; Use the first of these three envvars that has a nonempty value.
515   ;;         (or (let ((string (getenv "LC_ALL")))
516   ;;               (and (not (equal string "")) string))
517   ;;             (let ((string (getenv "LC_CTYPE")))
518   ;;               (and (not (equal string "")) string))
519   ;;             (let ((string (getenv "LANG")))
520   ;;               (and (not (equal string "")) string)))))
521   ;;    (and ctype
522   ;;         (string-match iso-8859-1-locale-regexp ctype)))
523   ;;      (progn
524   ;;    (standard-display-european t)
525   ;;    (require 'iso-syntax)))
526
527   (setq load-user-init-file-p (not (noninteractive)))
528
529   ;; Allow (at least) these arguments anywhere in the command line
530   (let ((new-args nil)
531         (arg      nil))
532     (while args
533       (setq arg (pop args))
534       (cond
535        ((or (string= arg "-q")
536             (string= arg "-no-init-file"))
537         (setq load-user-init-file-p nil))
538        ((string= arg "-no-site-file")
539         (setq site-start-file nil))
540        ((or (string= arg "-no-early-packages")
541             (string= arg "--no-early-packages"))
542         (setq inhibit-early-packages t))
543        ((or (string= arg "-vanilla")
544             (string= arg "--vanilla")
545             ;; Some work on this one already done in emacs.c.
546             (string= arg "-no-autoloads")
547             (string= arg "--no-autoloads"))
548         (setq load-user-init-file-p nil
549               site-start-file nil))
550        ((string= arg "-user-init-file")
551         (setq user-init-file (pop args)))
552        ((string= arg "-user-init-directory")
553         (setq user-init-directory (file-name-as-directory (pop args))))
554        ((or (string= arg "-u")
555             (string= arg "-user"))
556         (let* ((user (pop args))
557                (home-user (concat "~" user)))
558           (setq user-init-directory (file-name-as-directory
559                                      (paths-construct-path
560                                       (list home-user user-init-directory-base))))
561           (setq user-init-file
562                 (find-user-init-file user-init-directory home-user))
563           (setq custom-file
564                 (make-custom-file-name user-init-file))))
565        ((string= arg "-debug-init")
566         (setq init-file-debug t))
567        ((string= arg "-unmapped")
568         (setq initial-frame-unmapped-p t))
569        ((or (string= arg "-debug-paths")
570             (string= arg "--debug-paths"))
571         t)
572        ((or (string= arg "--") (string= arg "-"))
573         (while args
574           (push (pop args) new-args)))
575        (t (push arg new-args))))
576
577     (setq init-file-user (and load-user-init-file-p ""))
578
579     (nreverse new-args)))
580
581 (defconst initial-scratch-message "\
582 ;; This buffer is for notes you don't want to save, and for Lisp evaluation.
583 ;; If you want to create a file, first visit that file with C-x C-f,
584 ;; then enter the text in that file's own buffer.
585
586 "
587   "Initial message displayed in *scratch* buffer at startup.
588 If this is nil, no message will be displayed.")
589
590 (defun command-line ()
591   (let ((command-line-args-left (cdr command-line-args)))
592
593     (let ((debugger 'early-error-handler)
594           (debug-on-error t))
595
596       ;; Process magic command-line switches like -q and -u.  Do this
597       ;; before creating the first frame because some of these switches
598       ;; may affect that.  I think it's ok to do this before establishing
599       ;; the X connection, and maybe someday things like -nw can be
600       ;; handled here instead of down in C.
601       (setq command-line-args-left (command-line-early command-line-args-left))
602
603       ;; Setup the toolbar icon directory
604       (when (featurep 'toolbar)
605         (init-toolbar-location))
606
607       ;; Run the window system's init function.  tty is considered to be
608       ;; a type of window system for this purpose.  This creates the
609       ;; initial (non stdio) device.
610       (when (and initial-window-system (not noninteractive))
611         (funcall (intern (concat "init-"
612                                  (symbol-name initial-window-system)
613                                  "-win"))))
614
615       ;; When not in batch mode, this creates the first visible frame,
616       ;; and deletes the stdio device.
617       (frame-initialize))
618
619     ;; Reinitialize faces if necessary.  This function changes face if
620     ;; it is created during auto-autoloads loading.  Otherwise, it
621     ;; does nothing.
622     (startup-initialize-custom-faces)
623
624     ;;
625     ;; We have normality, I repeat, we have normality.  Anything you still
626     ;; can't cope with is therefore your own problem.  (And we don't need
627     ;; to kill XEmacs for it.)
628     ;;
629
630     ;;; Load init files.
631     (load-init-file)
632
633     (with-current-buffer (get-buffer "*scratch*")
634       (erase-buffer)
635       ;; (insert initial-scratch-message)
636       (set-buffer-modified-p nil)
637       (when (eq major-mode 'fundamental-mode)
638         (funcall initial-major-mode)))
639
640     ;; Load library for our terminal type.
641     ;; User init file can set term-file-prefix to nil to prevent this.
642     ;; Note that for any TTY's opened subsequently, the TTY init
643     ;; code will run this.
644     (when (and (eq 'tty (console-type))
645                (not (noninteractive)))
646       (load-terminal-library))
647
648     ;; Process the remaining args.
649     (command-line-1)
650
651     ;; it was turned on by default so that the warnings don't get displayed
652     ;; until after the splash screen.
653     (setq inhibit-warning-display nil)
654     ;; If -batch, terminate after processing the command options.
655     (when (noninteractive) (kill-emacs t))))
656
657 (defun load-terminal-library ()
658   (when term-file-prefix
659     (let ((term (getenv "TERM"))
660           hyphend)
661       (while (and term
662                   (not (load (concat term-file-prefix term) t t)))
663         ;; Strip off last hyphen and what follows, then try again
664         (if (setq hyphend (string-match "[-_][^-_]+\\'" term))
665             (setq term (substring term 0 hyphend))
666           (setq term nil))))))
667
668 (defun find-user-init-directory-init-file (&optional init-directory)
669   "Determine the user's init file if in the init directory."
670   (let ((init-directory (or init-directory user-init-directory)))
671     (catch 'found
672       (dolist (file user-init-file-base-list)
673         (let ((expanded (expand-file-name file init-directory)))
674           (when (file-readable-p expanded)
675             (throw 'found expanded)))))))
676
677 (defun find-user-home-directory-init-file (&optional home-directory)
678   "Determine the user's init file if in the home directory."
679   (let ((home-directory (or home-directory "~")))
680     (catch 'found
681       (dolist (file user-home-init-file-base-list)
682         (let ((expanded (expand-file-name file home-directory)))
683           (when (file-readable-p expanded)
684             (throw 'found expanded))))
685       nil)))
686
687 (defun find-user-init-file (&optional init-directory home-directory)
688   "Determine the user's init file."
689   (if load-home-init-file
690       (find-user-home-directory-init-file home-directory)
691     (or (find-user-init-directory-init-file init-directory)
692         (find-user-home-directory-init-file home-directory))))
693
694 (defun maybe-migrate-user-init-file ()
695   "Ask user if she wants to migrate the init file(s) to new location."
696   (if (and (not load-home-init-file)
697            (not (find-user-init-directory-init-file user-init-directory))
698            (stringp user-init-file)
699            (file-readable-p user-init-file))
700       (if (with-output-to-temp-buffer (help-buffer-name nil)
701             (progn
702               (princ "XEmacs recommends that the initialization code in
703 ")
704               (princ user-init-file)
705               (princ "
706 be migrated to the ")
707               (princ user-init-directory)
708               (princ " directory.  XEmacs can
709 perform the migration automatically.
710
711 After the migration, init.el/init.elc holds user-written
712 initialization code.  Moreover the customize settings will be in
713 custom.el.
714
715 If you choose not to do this now, XEmacs will not ask you this
716 question in the future.  However, you can still make XEmacs
717 perform the migration at any time with M-x migrate-user-init-file.")
718               (show-temp-buffer-in-current-frame standard-output)
719               (yes-or-no-p-minibuf (concat "Migrate init file to "
720                                            user-init-directory
721                                            "? "))))
722           (migrate-user-init-file)
723         (customize-save-variable 'load-home-init-file t))))
724
725 (defun migrate-user-init-file ()
726   "Migrate the init file from the home directory."
727   (interactive)
728   (if (not (file-exists-p user-init-directory))
729       (progn
730         (message "Creating %s directory..." user-init-directory)
731         (make-directory user-init-directory)))
732   (message "Migrating custom file...")
733   (custom-migrate-custom-file (make-custom-file-name user-init-file
734                                                      'force-new))
735   (message "Moving init file...")
736   (rename-file user-init-file
737                (expand-file-name user-init-file-base
738                                  user-init-directory))
739   (message "Migration done."))
740
741 (defun load-user-init-file ()
742   "This function actually reads the init file."
743   (if (not user-init-file)
744       (setq user-init-file
745             (find-user-init-file user-init-directory)))
746   (if (and user-init-file
747            (file-readable-p user-init-file))
748       (load user-init-file t t t))
749   (if (not custom-file)
750       (setq custom-file (make-custom-file-name user-init-file)))
751   (if (and custom-file
752            (or (not user-init-file)
753                (not (string= custom-file user-init-file)))
754            (file-readable-p custom-file))
755       (load custom-file t t t))
756   (unless inhibit-default-init
757     (let ((inhibit-startup-message nil))
758       ;; Users are supposed to be told their rights.
759       ;; (Plus how to get help and how to undo.)
760       ;; Don't you dare turn this off for anyone except yourself.
761       (load "default" t t))))
762
763 ;;; Load user's init file and default ones.
764 (defun load-init-file ()
765   (run-hooks 'before-init-hook)
766
767   ;; Run the site-start library if it exists.  The point of this file is
768   ;; that it is run before .emacs.  There is no point in doing this after
769   ;; .emacs; that is useless.
770   (when site-start-file
771     (load site-start-file t t))
772
773   ;; Sites should not disable this.  Only individuals should disable
774   ;; the startup message.
775   (setq inhibit-startup-message nil)
776
777   (let (debug-on-error-from-init-file
778         debug-on-error-should-be-set
779         (debug-on-error-initial
780          (if (eq init-file-debug t) 'startup init-file-debug)))
781     (let ((debug-on-error debug-on-error-initial))
782       (if (and load-user-init-file-p init-file-debug)
783           (progn
784             ;; Do this without a condition-case if the user wants to debug.
785             (load-user-init-file))
786         (condition-case error
787             (progn
788               (if load-user-init-file-p
789                   (load-user-init-file))
790               (setq init-file-had-error nil))
791           (error
792            (message "Error in init file: %s" (error-message-string error))
793            (display-warning 'initialization
794              (format "\
795 An error has occurred while loading %s:
796
797 %s
798
799 To ensure normal operation, you should investigate the cause of the error
800 in your initialization file and remove it.  Use the `-debug-init' option
801 to XEmacs to view a complete error backtrace."
802                      user-init-file (error-message-string error))
803              'error)
804            (setq init-file-had-error t))))
805       ;; If we can tell that the init file altered debug-on-error,
806       ;; arrange to preserve the value that it set up.
807       (or (eq debug-on-error debug-on-error-initial)
808           (setq debug-on-error-should-be-set t
809                 debug-on-error-from-init-file debug-on-error)))
810     (when debug-on-error-should-be-set
811       (setq debug-on-error debug-on-error-from-init-file)))
812
813   (setq init-file-loaded t)
814
815   ;; Do this here in case the init file sets mail-host-address.
816   ;; Don't do this here unless noninteractive, it is frequently wrong. -sb
817   ;; (or user-mail-address
818   (when noninteractive
819     (setq user-mail-address (concat (user-login-name) "@"
820                                     (or mail-host-address
821                                         (system-name)))))
822
823   (run-hooks 'after-init-hook)
824   nil)
825
826 (defun load-options-file (filename)
827   "Load the file of saved options (from the Options menu) called FILENAME.
828 Currently this does nothing but call `load', but it might be redefined
829 in the future to support automatically converting older options files to
830 a new format, when variables have changed, etc."
831   (load filename))
832
833 (defun command-line-1 ()
834   (cond
835    ((null command-line-args-left)
836     (unless noninteractive
837       ;; If there are no switches to process, run the term-setup-hook
838       ;; before displaying the copyright notice; there may be some need
839       ;; to do it before doing any output.  If we're not going to
840       ;; display a copyright notice (because other options are present)
841       ;; then this is run after those options are processed.
842       (run-hooks 'term-setup-hook)
843       ;; Don't let the hook be run twice.
844       (setq term-setup-hook nil)
845
846       ;; Don't clobber a non-scratch buffer if init file
847       ;; has selected it.
848       (when (string= (buffer-name) "*scratch*")
849         (unless (or inhibit-startup-message
850                     (input-pending-p))
851           (let (tmout circ-tmout)
852             (unwind-protect
853                 ;; Guts of with-timeout
854                 (catch 'tmout
855                   (setq tmout (add-timeout startup-message-timeout
856                                            (lambda (ignore)
857                                              (condition-case nil
858                                                  (throw 'tmout t)
859                                                (error nil)))
860                                            nil))
861                   (setq circ-tmout (display-splash-frame))
862                   (or nil;; (pos-visible-in-window-p (point-min))
863                       (goto-char (point-min)))
864                   (sit-for 0)
865                   (setq unread-command-event (next-command-event)))
866               (when tmout (disable-timeout tmout))
867               (when circ-tmout (disable-timeout circ-tmout)))))
868         (with-current-buffer (get-buffer "*scratch*")
869           ;; In case the XEmacs server has already selected
870           ;; another buffer, erase the one our message is in.
871           (erase-buffer)
872           (when (stringp initial-scratch-message)
873             (insert initial-scratch-message))
874           (set-buffer-modified-p nil)))))
875
876    (t
877     ;; Command-line-options exist
878     (let ((dir command-line-default-directory)
879           (file-count 0)
880           (line nil)
881           (end-of-options nil)
882           file-p arg tem)
883       (while command-line-args-left
884         (setq arg (pop command-line-args-left))
885         (cond
886          (end-of-options
887           (setq file-p t))
888          ((setq tem (when (eq (aref arg 0) ?-)
889                       (or (assoc arg command-switch-alist)
890                           (assoc (substring arg 1)
891                                  command-switch-alist))))
892           (funcall (cdr tem) arg))
893          ((string-match "\\`\\+[0-9]+\\'" arg)
894           (setq line (string-to-int arg)))
895          ;; "- file" means don't treat "file" as a switch
896          ;;  ("+0 file" has the same effect; "-" added
897          ;;   for unixoidiality).
898          ;; This is worthless; the `unixoid' way is "./file". -jwz
899          ((or (string= arg "-") (string= arg "--"))
900           (setq end-of-options t))
901          (t
902           (setq file-p t)))
903
904         (when file-p
905           (setq file-p nil)
906           (incf file-count)
907           (setq arg (expand-file-name arg dir))
908           (cond
909            ((= file-count 1)
910             (find-file arg))
911            (noninteractive (find-file arg))
912            (t (find-file-other-window arg)))
913           (when line
914             (goto-line line)
915             (setq line nil))))))))
916
917 (defvar startup-presentation-hack-keymap
918   (let ((map (make-sparse-keymap)))
919     (set-keymap-name map 'startup-presentation-hack-keymap)
920     (define-key map '[button1] 'startup-presentation-hack)
921     (define-key map '[button2] 'startup-presentation-hack)
922     map)
923   "Putting yesterday in the future tomorrow.")
924
925 (defun startup-presentation-hack ()
926   (interactive)
927   (let ((e last-command-event))
928     (and (button-press-event-p e)
929          (setq e (extent-at (event-point e)
930                             (event-buffer e)
931                             'startup-presentation-hack))
932          (setq e (extent-property e 'startup-presentation-hack))
933          (if (consp e)
934              (apply (car e) (cdr e))
935            (while (keymapp (indirect-function e))
936              (let ((map e)
937                    (overriding-local-map (indirect-function e)))
938                (setq e (read-key-sequence
939                         (let ((p (keymap-prompt map t)))
940                           (cond ((symbolp map)
941                                  (if p
942                                      (format "%s %s " map p)
943                                    (format "%s " map)))
944                                 (p)
945                                 (t
946                                  (prin1-to-string map))))))
947                (if (and (button-release-event-p (elt e 0))
948                         (null (key-binding e)))
949                    (setq e map)         ; try again
950                  (setq e (key-binding e)))))
951            (call-interactively e)))))
952
953 (defun startup-presentation-hack-help (e)
954   (setq e (extent-property e 'startup-presentation-hack))
955   (if (consp e)
956       (format "Evaluate %S" e)
957     (symbol-name e)))
958
959 (defun splash-frame-present-hack (e v)
960   ;;   (set-extent-property e 'mouse-face 'highlight)
961   ;;   (set-extent-property e 'keymap
962   ;;                           startup-presentation-hack-keymap)
963   ;;   (set-extent-property e 'startup-presentation-hack v)
964   ;;   (set-extent-property e 'help-echo
965   ;;                           'startup-presentation-hack-help)
966   )
967
968 (defun splash-hack-version-string ()
969   (save-excursion
970     (save-restriction
971       (goto-char (point-min))
972       (re-search-forward "^XEmacs" nil t)
973       (narrow-to-region (point-at-bol) (point-at-eol))
974       (goto-char (point-min))
975       (when (re-search-forward " \\[Lucid\\]" nil t)
976         (delete-region (match-beginning 0) (match-end 0)))
977       (when (re-search-forward "[^(][^)]*-[^)]*-" nil t)
978         (delete-region (1+ (match-beginning 0)) (match-end 0))
979         (insert "("))
980       (goto-char (point-max))
981       (search-backward " " nil t)
982       (when (search-forward "." nil t)
983         (delete-region (1- (point)) (point-max))))))
984
985 (defun splash-frame-present (l)
986   (cond ((stringp l)
987          (insert l))
988         ((eq (car-safe l) 'face)
989          ;; (face name string)
990          (let ((p (point)))
991            (splash-frame-present (elt l 2))
992            (if (fboundp 'set-extent-face)
993                (set-extent-face (make-extent p (point))
994                                 (elt l 1)))))
995         ((eq (car-safe l) 'key)
996          (let* ((c (elt l 1))
997                 (p (point))
998                 (k (where-is-internal c nil t)))
999            (insert (if k (key-description k)
1000                      (format "M-x %s" c)))
1001            (if (fboundp 'set-extent-face)
1002                (let ((e (make-extent p (point))))
1003                  (set-extent-face e 'bold)
1004                  (splash-frame-present-hack e c)))))
1005         ((eq (car-safe l) 'funcall)
1006          ;; (funcall (fun . args) string)
1007          (let ((p (point)))
1008            (splash-frame-present (elt l 2))
1009            (if (fboundp 'set-extent-face)
1010                (splash-frame-present-hack (make-extent p (point))
1011                                           (elt l 1)))))
1012         ((consp l)
1013          (mapcar 'splash-frame-present l))
1014         (t
1015          (error "WTF!?"))))
1016
1017 (defun startup-center-spaces (glyph)
1018   ;; Return the number of spaces to insert in order to center
1019   ;; the given glyph (may be a string or a pixmap).
1020   ;; Assume spaces are as wide as avg-pixwidth.
1021   ;; Won't be quite right for proportional fonts, but it's the best we can do.
1022   ;; Maybe the new redisplay will export something a glyph-width function.
1023   ;;; #### Yes, there is a glyph-width function but it isn't quite what
1024   ;;; #### this was expecting.  Or is it?
1025   ;; (An alternate way to get avg-pixwidth would be to use x-font-properties
1026   ;; and calculate RESOLUTION_X * AVERAGE_WIDTH / 722.7, but it's no better.)
1027
1028   ;; This function is used in about.el too.
1029   (let* ((avg-pixwidth     (round (/ (frame-pixel-width) (frame-width))))
1030          (fill-area-width  (* avg-pixwidth (- fill-column left-margin)))
1031          (glyph-pixwidth   (cond ((stringp glyph)
1032                                   (* avg-pixwidth (length glyph)))
1033                                  ;; #### the pixmap option should be removed
1034                                  ;;((pixmapp glyph)
1035                                  ;; (pixmap-width glyph))
1036                                  ((glyphp glyph)
1037                                   (glyph-width glyph))
1038                                  (t
1039                                   (error "startup-center-spaces: bad arg")))))
1040     (+ left-margin
1041        (round (/ (/ (- fill-area-width glyph-pixwidth) 2) avg-pixwidth)))))
1042
1043 (defun splash-frame-body ()
1044   `[((face (blue bold underline)
1045            "\nDistribution, copying license, warranty:\n\n")
1046      "Please visit the XEmacs website at http://www.xemacs.org !\n\n"
1047      ,@(if (featurep 'sparcworks)
1048            `( "\
1049 Sun provides support for the WorkShop/XEmacs integration package only.
1050 All other XEmacs packages are provided to you \"AS IS\".\n"
1051               ,@(let ((lang (or (getenv "LC_ALL") (getenv "LC_MESSAGES")
1052                                 (getenv "LANG"))))
1053                   (if (and
1054                        (not (featurep 'mule)) ;; Already got mule?
1055                        ;; No Mule support on tty's yet
1056                        (not (eq 'tty (console-type)))
1057                        lang ;; Non-English locale?
1058                        (not (string= lang "C"))
1059                        (not (string-match "^en" lang))
1060                        ;; Comes with Sun WorkShop
1061                        (locate-file "xemacs-mule" exec-path))
1062                       '( "\
1063 This version of XEmacs has been built with support for Latin-1 languages only.
1064 To handle other languages you need to run a Multi-lingual (`Mule') version of
1065 XEmacs, by either running the command `xemacs-mule', or by using the X resource
1066 `ESERVE*defaultXEmacsPath: xemacs-mule' when starting XEmacs from Sun WorkShop.
1067 \n")))))
1068      ((key describe-no-warranty)
1069       ": "(face (red bold) "XEmacs comes with ABSOLUTELY NO WARRANTY\n"))
1070      ((key describe-copying)
1071       ": conditions to give out copies of XEmacs\n")
1072      ((key describe-distribution)
1073       ": how to get the latest version\n")
1074      "\n--\n"
1075      (face italic "\
1076 Copyright (C) 1985-1999 Free Software Foundation, Inc.
1077 Copyright (C) 1990-1994 Lucid, Inc.
1078 Copyright (C) 1993-1997 Sun Microsystems, Inc. All Rights Reserved.
1079 Copyright (C) 1994-1996 Board of Trustees, University of Illinois
1080 Copyright (C) 1995-1996 Ben Wing
1081 Copyright (C) 1996-2000 MORIOKA Tomohiko
1082 "))
1083
1084     ((face (blue bold underline) "\nInformation, on-line help:\n\n")
1085      "XEmacs comes with plenty of documentation...\n\n"
1086      ,@(if (string-match "beta" emacs-version)
1087            `((key describe-beta)
1088              ": " (face (red bold)
1089                         "This is an Experimental version of XEmacs.\n"))
1090          `( "\n"))
1091      ((key xemacs-local-faq)
1092       ": read the XEmacs FAQ (a " (face underline "capital") " F!)\n")
1093      ((key help-with-tutorial)
1094       ": read the XEmacs tutorial (also available through the "
1095       (face bold "Help") " menu)\n")
1096      ((key help-command)
1097       ": get help on using XEmacs (also available through the "
1098       (face bold "Help") " menu)\n")
1099      ((key info) ": read the on-line documentation\n\n")
1100      ((key describe-project) ": read about the GNU project\n")
1101      ((key about-xemacs) ": see who's developing XEmacs\n"))
1102
1103     ((face (blue bold underline) "\nUseful stuff:\n\n")
1104      "Things that you should know rather quickly...\n\n"
1105      ((key find-file) ": visit a file\n")
1106      ((key save-buffer) ": save changes\n")
1107      ((key advertised-undo) ": undo changes\n")
1108      ((key save-buffers-kill-emacs) ": exit XEmacs\n"))
1109     ])
1110
1111 ;; I really hate global variables, oh well.
1112 ;(defvar xemacs-startup-logo-function nil
1113 ;  "If non-nil, function called to provide the startup logo.
1114 ;This function should return an initialized glyph if it is used.")
1115
1116 ;; This will hopefully go away when gettext is functional.
1117 (defconst splash-frame-static-body
1118   `(,(emacs-version) "\n\n"
1119     (face italic "`C-' means the control key,`M-' means the meta key\n\n")))
1120
1121
1122 (defun circulate-splash-frame-elements (client-data)
1123   (with-current-buffer (aref client-data 2)
1124     (let ((buffer-read-only nil)
1125           (elements (aref client-data 3))
1126           (indice (aref client-data 0)))
1127       (goto-char (aref client-data 1))
1128       (delete-region (point) (point-max))
1129       (splash-frame-present (aref elements indice))
1130       (set-buffer-modified-p nil)
1131       (aset client-data 0
1132             (if (= indice (- (length elements) 1))
1133                 0
1134               (1+ indice )))
1135       )))
1136
1137 ;; #### This function now returns the (possibly nil) timeout circulating the
1138 ;; splash-frame elements
1139 (defun display-splash-frame ()
1140   (let ((logo xemacs-logo)
1141         (buffer-read-only nil)
1142         (cramped-p (eq 'tty (console-type))))
1143     (unless cramped-p (insert "\n"))
1144     (indent-to (startup-center-spaces logo))
1145     (set-extent-begin-glyph (make-extent (point) (point)) logo)
1146     ;;(splash-frame-present-hack (make-extent p (point)) 'about-xemacs))
1147     (insert "\n\n")
1148     (splash-frame-present splash-frame-static-body)
1149     (splash-hack-version-string)
1150     (goto-char (point-max))
1151     (let* ((after-change-functions nil) ; no font-lock, thank you
1152            (elements (splash-frame-body))
1153            (client-data `[ 1 ,(point) ,(current-buffer) ,elements ])
1154            tmout)
1155       (if (listp  elements) ;; A single element to display
1156           (splash-frame-present (splash-frame-body))
1157         ;; several elements to rotate
1158         (splash-frame-present (aref elements 0))
1159         (setq tmout (add-timeout splash-frame-timeout
1160                                  'circulate-splash-frame-elements
1161                                  client-data splash-frame-timeout)))
1162       (set-buffer-modified-p nil)
1163       tmout)))
1164
1165 ;;  (let ((present-file
1166 ;;         #'(lambda (f)
1167 ;;             (splash-frame-present
1168 ;;            (list 'funcall
1169 ;;                  (list 'find-file-other-window
1170 ;;                        (expand-file-name f data-directory))
1171 ;;                  f)))))
1172 ;;    (insert "For customization examples, see the files ")
1173 ;;    (funcall present-file "sample.emacs")
1174 ;;    (insert " and ")
1175 ;;    (funcall present-file "sample.Xdefaults")
1176 ;;    (insert (format "\nin the directory %s." data-directory)))
1177
1178 (defun startup-set-invocation-environment ()
1179   ;; XEmacs -- Steven Baur says invocation directory is nil if you
1180   ;; try to use XEmacs as a login shell.
1181   (or invocation-directory (setq invocation-directory default-directory))
1182   (setq invocation-directory
1183         ;; don't let /tmp_mnt/... get into the load-path or exec-path.
1184         (abbreviate-file-name invocation-directory)))
1185
1186 (defun startup-setup-paths (roots user-init-directory
1187                                   &optional
1188                                   inhibit-early-packages inhibit-site-lisp
1189                                   debug-paths)
1190   "Setup all the various paths.
1191 ROOTS is a list of plausible roots of the XEmacs directory hierarchy.
1192 If INHIBIT-PACKAGES is non-NIL, don't do packages.
1193 If INHIBIT-SITE-LISP is non-NIL, don't do site-lisp.
1194 If DEBUG-PATHS is non-NIL, print paths as they are detected.
1195 It's idempotent, so call this as often as you like!"
1196
1197   (apply #'(lambda (early late last)
1198              (setq early-packages (and (not inhibit-early-packages)
1199                                        early))
1200              (setq late-packages late)
1201              (setq last-packages last))
1202          (packages-find-packages
1203           roots
1204           (packages-compute-package-locations user-init-directory)))
1205
1206   (setq early-package-load-path (packages-find-package-load-path early-packages))
1207   (setq late-package-load-path (packages-find-package-load-path late-packages))
1208   (setq last-package-load-path (packages-find-package-load-path last-packages))
1209
1210   (if debug-paths
1211       (progn
1212         (princ (format "configure-package-path:\n%S\n" configure-package-path)
1213                'external-debugging-output)
1214         (princ (format "early-packages and early-package-load-path:\n%S\n%S\n"
1215                        early-packages early-package-load-path)
1216                'external-debugging-output)
1217         (princ (format "late-packages and late-package-load-path:\n%S\n%S\n"
1218                        late-packages late-package-load-path)
1219                'external-debugging-output)
1220         (princ (format "last-packages and last-package-load-path:\n%S\n%S\n"
1221                        last-packages last-package-load-path)
1222                'external-debugging-output)))
1223
1224   (setq lisp-directory (paths-find-lisp-directory roots))
1225
1226   (if debug-paths
1227       (princ (format "lisp-directory:\n%S\n" lisp-directory)
1228              'external-debugging-output))
1229
1230   (setq site-directory (and (null inhibit-site-lisp)
1231                             (paths-find-site-lisp-directory roots)))
1232
1233   (if (and debug-paths (null inhibit-site-lisp))
1234       (princ (format "site-directory:\n%S\n" site-directory)
1235              'external-debugging-output))
1236
1237   (setq load-path (paths-construct-load-path roots
1238                                              early-package-load-path
1239                                              late-package-load-path
1240                                              last-package-load-path
1241                                              lisp-directory
1242                                              site-directory))
1243
1244   (setq Info-directory-list
1245         (paths-construct-info-path roots
1246                                    early-packages late-packages last-packages))
1247
1248
1249   (if debug-paths
1250       (princ (format "Info-directory-list:\n%S\n" Info-directory-list)
1251              'external-debugging-output))
1252
1253   (setq exec-directory (paths-find-exec-directory roots))
1254
1255   (if debug-paths
1256       (princ (format "exec-directory:\n%s\n" exec-directory)
1257              'external-debugging-output))
1258
1259   (setq exec-path
1260         (paths-construct-exec-path roots exec-directory
1261                                    early-packages late-packages last-packages))
1262
1263   (if debug-paths
1264       (princ (format "exec-path:\n%S\n" exec-path)
1265              'external-debugging-output))
1266
1267   (setq doc-directory (paths-find-doc-directory roots))
1268
1269   (if debug-paths
1270       (princ (format "doc-directory:\n%S\n" doc-directory)
1271              'external-debugging-output))
1272
1273   (setq data-directory (paths-find-data-directory roots))
1274
1275   (if debug-paths
1276       (princ (format "data-directory:\n%S\n" data-directory)
1277              'external-debugging-output))
1278
1279   (setq data-directory-list (paths-construct-data-directory-list data-directory
1280                                                                  early-packages
1281                                                                  late-packages
1282                                                                  last-packages))
1283   (if debug-paths
1284       (princ (format "data-directory-list:\n%S\n" data-directory-list)
1285              'external-debugging-output)))
1286
1287 (defun startup-find-roots-warning ()
1288   (save-excursion
1289     (set-buffer (get-buffer-create " *warning-tmp*"))
1290     (erase-buffer)
1291     (buffer-disable-undo (current-buffer))
1292
1293     (insert "Couldn't find an obvious default for the root of the\n"
1294             "XEmacs hierarchy.")
1295
1296     (princ "\nWARNING:\n" 'external-debugging-output)
1297     (princ (buffer-string) 'external-debugging-output)))
1298
1299 (defun startup-setup-paths-warning ()
1300   (let ((warnings '()))
1301     (cond
1302      ((null (and lisp-directory exec-directory data-directory doc-directory
1303                  load-path))
1304       (save-excursion
1305         (set-buffer (get-buffer-create " *warning-tmp*"))
1306         (erase-buffer)
1307         (buffer-disable-undo (current-buffer))
1308         (if (null lisp-directory) (push "lisp-directory" warnings))
1309         (if (null exec-directory) (push "exec-directory" warnings))
1310         (if (null data-directory) (push "data-directory" warnings))
1311         (if (null doc-directory)  (push "doc-directory"  warnings))
1312         (if (null load-path)      (push "load-path"      warnings))
1313
1314         (insert "Couldn't find obvious defaults for:\n")
1315         (while warnings
1316           (insert (car warnings) "\n")
1317           (setq warnings (cdr warnings)))
1318         (insert "Perhaps some directories don't exist, "
1319                 "or the XEmacs executable,\n" (concat invocation-directory
1320                                                      invocation-name)
1321                 "\nis in a strange place?")
1322
1323         (princ "\nWARNING:\n" 'external-debugging-output)
1324         (princ (buffer-string) 'external-debugging-output)
1325         (erase-buffer)
1326         t)))))
1327
1328 ;;; startup.el ends here