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