XEmacs 21.2-b2
[chise/xemacs-chise.git.1] / lisp / loadup.el
1 ;; loadup.el --- load up standardly loaded Lisp files for XEmacs.
2
3 ;; Copyright (C) 1985, 1986, 1992, 1994, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1996 Richard Mlynarik.
5 ;; Copyright (C) 1995, 1996 Ben Wing.
6
7 ;; Maintainer: XEmacs Development Team
8 ;; Keywords: internal, dumped
9
10 ;; This file is part of XEmacs.
11
12 ;; XEmacs is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; XEmacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;; 02111-1307, USA.
26
27 ;;; Synched up with: Last synched with FSF 19.30, with wild divergence since.
28
29 ;;; Commentary:
30
31 ;; Please do not edit this file.  Use site-init.el or site-load.el instead.
32
33 ;; This is loaded into a bare XEmacs to make a dumpable one.
34
35 ;;; Code:
36
37 (if (fboundp 'error)
38     (error "loadup.el already loaded!"))
39
40 (defvar running-xemacs t
41   "Non-nil when the current emacs is XEmacs.")
42 (defvar preloaded-file-list nil
43   "List of files preloaded into the XEmacs binary image.")
44
45 ;; This is awfully damn early to be getting an error, right?
46 (call-with-condition-handler 'really-early-error-handler
47     #'(lambda ()
48         ;; message not defined yet ...
49         (setq load-path (split-path (getenv "EMACSBOOTSTRAPLOADPATH")))
50
51         (external-debugging-output (format "\nUsing load-path %s" load-path))
52
53         ;; We don't want to have any undo records in the dumped XEmacs.
54         (buffer-disable-undo (get-buffer "*scratch*"))
55
56         ;; Load our first bootstrap support
57         (load "very-early-lisp" nil t)
58
59         ;; lread.c (or src/Makefile.in.in) has prepended
60         ;; "${srcdir}/../lisp/" to load-path, which is how this file
61         ;; has been found.  At this point, enough of XEmacs has been
62         ;; initialized that we can start dumping "standard" lisp.
63         ;; Dumped lisp from external packages is added when we search
64         ;; the package path.
65         ;; #### This code is duplicated in two other places.
66         (let ((temp-path (expand-file-name "." (car load-path))))
67           (setq load-path (nconc (mapcar
68                                   #'(lambda (i) (concat i "/"))
69                                   (directory-files temp-path t "^[^-.]"
70                                                    nil 'dirs-only))
71                                  (cons (file-name-as-directory temp-path)
72                                        load-path))))
73
74         (setq load-warn-when-source-newer t ; Used to be set to nil at the end
75               load-warn-when-source-only  t) ; Set to nil at the end
76
77         ;; garbage collect after loading every file in an attempt to
78         ;; minimize the size of the dumped image (if we don't do this,
79         ;; there will be lots of extra space in the data segment filled
80         ;; with garbage-collected junk)
81         (defun pureload (file)
82           (let ((full-path (locate-file file
83                                         load-path
84                                         (if load-ignore-elc-files
85                                             ".el:"
86                                           ".elc:.el:"))))
87             (if full-path
88                 (prog1
89                   (load full-path)
90                   (garbage-collect))
91               (external-debugging-output (format "\nLoad file %s: not found\n"
92                                                  file))
93               ;; Uncomment in case of trouble
94               ;;(print (format "late-packages: %S" late-packages))
95               ;;(print (format "guessed-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name)))
96               nil)))
97
98         (load (concat default-directory "../lisp/dumped-lisp.el"))
99
100         (let ((files preloaded-file-list)
101               file)
102           (while (setq file (car files))
103             (or (pureload file)
104               (progn
105                 (external-debugging-output "Fatal error during load, aborting")
106                 (kill-emacs 1)))
107             (setq files (cdr files)))
108           (if (not (featurep 'toolbar))
109               (progn
110                 ;; else still define a few functions.
111                 (defun toolbar-button-p    (obj) "No toolbar support." nil)
112                 (defun toolbar-specifier-p (obj) "No toolbar support." nil)))
113           (fmakunbound 'pureload))
114
115         (packages-load-package-dumped-lisps late-package-load-path)
116
117         )) ;; end of call-with-condition-handler
118 \f
119 ;; Fix up the preloaded file list
120 (setq preloaded-file-list (mapcar #'file-name-sans-extension
121                                   preloaded-file-list))
122
123 (setq load-warn-when-source-newer t ; set to t at top of file
124       load-warn-when-source-only nil)
125
126 (setq debugger 'debug)
127
128 (when (member "no-site-file" command-line-args)
129   (setq site-start-file nil))
130
131 ;; If you want additional libraries to be preloaded and their
132 ;; doc strings kept in the DOC file rather than in core,
133 ;; you may load them with a "site-load.el" file.
134 ;; But you must also cause them to be scanned when the DOC file
135 ;; is generated.  For VMS, you must edit ../../vms/makedoc.com.
136 ;; For other systems, you must edit ../../src/Makefile.in.in.
137 (if (load "site-load" t)
138     (garbage-collect))
139
140 ;;FSFmacs randomness
141 ;;(if (fboundp 'x-popup-menu)
142 ;;    (precompute-menubar-bindings))
143 ;;; Turn on recording of which commands get rebound,
144 ;;; for the sake of the next call to precompute-menubar-bindings.
145 ;(setq define-key-rebound-commands nil)
146
147
148 ;; Note: all compiled Lisp files loaded above this point
149 ;; must be among the ones parsed by make-docfile
150 ;; to construct DOC.  Any that are not processed
151 ;; for DOC will not have doc strings in the dumped XEmacs.
152
153 ;; Don't bother with these if we're running temacs, i.e. if we're
154 ;; just debugging don't waste time finding doc strings.
155
156 ;; purify-flag is nil if called from loadup-el.el.
157 (when purify-flag
158   (message "Finding pointers to doc strings...")
159   (Snarf-documentation "DOC")
160   (message "Finding pointers to doc strings...done")
161   (Verify-documentation)
162   )
163
164 ;; Note: You can cause additional libraries to be preloaded
165 ;; by writing a site-init.el that loads them.
166 ;; See also "site-load" above.
167 (if (stringp site-start-file)
168     (load "site-init" t))
169 (setq current-load-list nil)
170 (garbage-collect)
171
172 ;;; At this point, we're ready to resume undo recording for scratch.
173 (buffer-enable-undo "*scratch*")
174
175 ;; Dump into the name `xemacs' (only)
176 (when (member "dump" command-line-args)
177     (message "Dumping under the name xemacs")
178     ;; This is handled earlier in the build process.
179     ;; (condition-case () (delete-file "xemacs") (file-error nil))
180     (when (fboundp 'really-free)
181       (really-free))
182     (dump-emacs (if (featurep 'infodock) "infodock" "xemacs") "temacs")
183     (kill-emacs))
184
185 ;; Avoid error if user loads some more libraries now.
186 (setq purify-flag nil)
187
188 (when (member "run-temacs" command-line-args)
189   (message "\nBootstrapping from temacs...")
190   ;; Remove all args up to and including "run-temacs"
191   (apply #'run-emacs-from-temacs (cdr (member "run-temacs" command-line-args)))
192   ;; run-emacs-from-temacs doesn't actually return anyway.
193   (kill-emacs))
194
195 ;; XEmacs change
196 ;; If you are using 'recompile', then you should have used -l loadup-el.el
197 ;; so that the .el files always get loaded (the .elc files may be out-of-
198 ;; date or bad).
199 (when (member "recompile" command-line-args)
200   (let ((command-line-args-left (cdr (member "recompile" command-line-args))))
201     (batch-byte-recompile-directory)
202     (kill-emacs)))
203
204 ;; For machines with CANNOT_DUMP defined in config.h,
205 ;; this file must be loaded each time Emacs is run.
206 ;; So run the startup code now.
207
208 (when (not (fboundp 'dump-emacs))
209   ;; Avoid loading loadup.el a second time!
210   (setq command-line-args (cdr (cdr command-line-args)))
211   (eval top-level))
212
213 ;;; loadup.el ends here