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