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