XEmacs 21.2.31 "Iris".
[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 (when (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 (defvar Installation-string nil
46   "Description of XEmacs installation.")
47
48 (let ((gc-cons-threshold 30000))
49   
50 ;; This is awfully damn early to be getting an error, right?
51 (call-with-condition-handler 'really-early-error-handler
52     #'(lambda ()
53
54         ;; Initialize Installation-string.  We do it before loading
55         ;; anything so that dumped code can make use of its value.
56         (setq Installation-string
57               (save-current-buffer
58                 (set-buffer (get-buffer-create (generate-new-buffer-name
59                                                 " *temp*")))
60                 ;; insert-file-contents-internal bogusly calls
61                 ;; format-decode without checking if it's defined.
62                 (fset 'format-decode #'(lambda (f l &optional v) l))
63                 (insert-file-contents-internal "../Installation")
64                 (fmakunbound 'format-decode)
65                 (prog1 (buffer-substring)
66                   (kill-buffer (current-buffer)))))
67
68         (let ((build-root (expand-file-name ".." invocation-directory)))
69           (setq load-path (list (expand-file-name "lisp" build-root)))
70           (setq module-load-path (list (expand-file-name "modules" build-root))))
71
72         ;; message not defined yet ...
73         (external-debugging-output (format "\nUsing load-path %s" load-path))
74         (external-debugging-output (format "\nUsing module-load-path %s"
75                                            module-load-path))
76
77         ;; We don't want to have any undo records in the dumped XEmacs.
78         (buffer-disable-undo (get-buffer "*scratch*"))
79
80         ;; Load our first bootstrap support
81         (load "very-early-lisp" nil t)
82
83         ;; lread.c (or src/Makefile.in.in) has prepended
84         ;; "${srcdir}/../lisp/" to load-path, which is how this file
85         ;; has been found.  At this point, enough of XEmacs has been
86         ;; initialized that we can start dumping "standard" lisp.
87         ;; Dumped lisp from external packages is added when we search
88         ;; the package path.
89         ;; #### This code is duplicated in two other places.
90         (let ((temp-path (expand-file-name "." (car load-path))))
91           (setq load-path (nconc (mapcar
92                                   #'(lambda (i) (concat i "/"))
93                                   (directory-files temp-path t "^[^-.]"
94                                                    nil 'dirs-only))
95                                  (cons (file-name-as-directory temp-path)
96                                        load-path))))
97
98         (setq load-warn-when-source-newer t ; Used to be set to nil at the end
99               load-warn-when-source-only  t) ; Set to nil at the end
100
101         ;; garbage collect after loading every file in an attempt to
102         ;; minimize the size of the dumped image (if we don't do this,
103         ;; there will be lots of extra space in the data segment filled
104         ;; with garbage-collected junk)
105         (defun pureload (file)
106           (let ((full-path
107                  (locate-file file load-path
108                               (if load-ignore-elc-files
109                                   '(".el" "") '(".elc" ".el" "")))))
110             (if full-path
111                 (prog1
112                   (load full-path)
113                   (garbage-collect))
114               (external-debugging-output (format "\nLoad file %s: not found\n"
115                                                  file))
116               ;; Uncomment in case of trouble
117               ;;(print (format "late-packages: %S" late-packages))
118               ;;(print (format "guessed-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name)))
119               nil)))
120
121         (load (expand-file-name "../lisp/dumped-lisp.el"))
122
123         (let ((files preloaded-file-list)
124               file)
125           (while (setq file (car files))
126             (unless (pureload file)
127               (external-debugging-output "Fatal error during load, aborting")
128               (kill-emacs 1))
129             (setq files (cdr files)))
130           (when (not (featurep 'toolbar))
131             ;; else still define a few functions.
132             (defun toolbar-button-p    (obj) "No toolbar support." nil)
133             (defun toolbar-specifier-p (obj) "No toolbar support." nil))
134           (fmakunbound 'pureload))
135
136         (packages-load-package-dumped-lisps late-package-load-path)
137
138         )) ;; end of call-with-condition-handler
139 \f
140 ;; Fix up the preloaded file list
141 (setq preloaded-file-list (mapcar #'file-name-sans-extension
142                                   preloaded-file-list))
143
144 (setq load-warn-when-source-newer t ; set to t at top of file
145       load-warn-when-source-only nil)
146
147 (setq debugger 'debug)
148
149 (when (member "no-site-file" command-line-args)
150   (setq site-start-file nil))
151
152 ;; If you want additional libraries to be preloaded and their
153 ;; doc strings kept in the DOC file rather than in core,
154 ;; you may load them with a "site-load.el" file.
155 ;; But you must also cause them to be scanned when the DOC file
156 ;; is generated.  For VMS, you must edit ../../vms/makedoc.com.
157 ;; For other systems, you must edit ../../src/Makefile.in.in.
158 (when (load "site-load" t)
159   (garbage-collect))
160
161 ;;FSFmacs randomness
162 ;;(if (fboundp 'x-popup-menu)
163 ;;    (precompute-menubar-bindings))
164 ;;; Turn on recording of which commands get rebound,
165 ;;; for the sake of the next call to precompute-menubar-bindings.
166 ;(setq define-key-rebound-commands nil)
167
168 ;; Note: all compiled Lisp files loaded above this point
169 ;; must be among the ones parsed by make-docfile
170 ;; to construct DOC.  Any that are not processed
171 ;; for DOC will not have doc strings in the dumped XEmacs.
172
173 ;; Don't bother with these if we're running temacs, i.e. if we're
174 ;; just debugging don't waste time finding doc strings.
175
176 ;; purify-flag is nil if called from loadup-el.el.
177 (when purify-flag
178   (message "Finding pointers to doc strings...")
179   (Snarf-documentation "DOC")
180   (message "Finding pointers to doc strings...done")
181   (Verify-documentation))
182
183 ;; Note: You can cause additional libraries to be preloaded
184 ;; by writing a site-init.el that loads them.
185 ;; See also "site-load" above.
186 (when (stringp site-start-file)
187   (load "site-init" t))
188 (setq current-load-list nil)
189 (garbage-collect)
190
191 ;;; At this point, we're ready to resume undo recording for scratch.
192 (buffer-enable-undo "*scratch*")
193
194 ) ;; frequent garbage collection
195
196 ;; Dump into the name `xemacs' (only)
197 (when (member "dump" command-line-args)
198   (message "Dumping under the name xemacs")
199   ;; This is handled earlier in the build process.
200   ;; (condition-case () (delete-file "xemacs") (file-error nil))
201   (when (fboundp 'really-free)
202     (really-free))
203   (dump-emacs (if (featurep 'infodock) "infodock" "xemacs") "temacs")
204   (kill-emacs))
205
206 ;; Avoid error if user loads some more libraries now.
207 (setq purify-flag nil)
208
209 (when (member "run-temacs" command-line-args)
210   (message "\nBootstrapping from temacs...")
211   ;; Remove all args up to and including "run-temacs"
212   (apply #'run-emacs-from-temacs (cdr (member "run-temacs" command-line-args)))
213   ;; run-emacs-from-temacs doesn't actually return anyway.
214   (kill-emacs))
215
216 ;; XEmacs change
217 ;; If you are using 'recompile', then you should have used -l loadup-el.el
218 ;; so that the .el files always get loaded (the .elc files may be out-of-
219 ;; date or bad).
220 (when (member "recompile" command-line-args)
221   (setq command-line-args-left (cdr (member "recompile" command-line-args)))
222   (batch-byte-recompile-directory)
223   (kill-emacs))
224
225 ;; For machines with CANNOT_DUMP defined in config.h,
226 ;; this file must be loaded each time Emacs is run.
227 ;; So run the startup code now.
228
229 (when (not (fboundp 'dump-emacs))
230   ;; Avoid loading loadup.el a second time!
231   (setq command-line-args (cdr (cdr command-line-args)))
232   (eval top-level))
233
234 ;;; loadup.el ends here