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