61188a9a694d18c46c152db0559d469977a6821d
[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
46 (let ((gc-cons-threshold 30000))
47   
48 ;; This is awfully damn early to be getting an error, right?
49 (call-with-condition-handler 'really-early-error-handler
50     #'(lambda ()
51         ;; message not defined yet ...
52         (setq load-path (split-path (getenv "EMACSBOOTSTRAPLOADPATH")))
53
54         (external-debugging-output (format "\nUsing load-path %s" load-path))
55
56         ;; We don't want to have any undo records in the dumped XEmacs.
57         (buffer-disable-undo (get-buffer "*scratch*"))
58
59         ;; Load our first bootstrap support
60         (load "very-early-lisp" nil t)
61
62         ;; lread.c (or src/Makefile.in.in) has prepended
63         ;; "${srcdir}/../lisp/" to load-path, which is how this file
64         ;; has been found.  At this point, enough of XEmacs has been
65         ;; initialized that we can start dumping "standard" lisp.
66         ;; Dumped lisp from external packages is added when we search
67         ;; the package path.
68         ;; #### This code is duplicated in two other places.
69         (let ((temp-path (expand-file-name "." (car load-path))))
70           (setq load-path (nconc (mapcar
71                                   #'(lambda (i) (concat i "/"))
72                                   (directory-files temp-path t "^[^-.]"
73                                                    nil 'dirs-only))
74                                  (cons (file-name-as-directory temp-path)
75                                        load-path))))
76
77         (setq load-warn-when-source-newer t ; Used to be set to nil at the end
78               load-warn-when-source-only  t) ; Set to nil at the end
79
80         ;; garbage collect after loading every file in an attempt to
81         ;; minimize the size of the dumped image (if we don't do this,
82         ;; there will be lots of extra space in the data segment filled
83         ;; with garbage-collected junk)
84         (defun pureload (file)
85           (let ((full-path
86                  (locate-file file load-path
87                               (if load-ignore-elc-files ".el:" ".elc:.el:"))))
88             (if full-path
89                 (prog1
90                   (load full-path)
91                   (garbage-collect))
92               (external-debugging-output (format "\nLoad file %s: not found\n"
93                                                  file))
94               ;; Uncomment in case of trouble
95               ;;(print (format "late-packages: %S" late-packages))
96               ;;(print (format "guessed-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name)))
97               nil)))
98
99         (load (concat default-directory "../lisp/dumped-lisp.el"))
100
101         (let ((files preloaded-file-list)
102               file)
103           (while (setq file (car files))
104             (unless (pureload file)
105               (external-debugging-output "Fatal error during load, aborting")
106               (kill-emacs 1))
107             (setq files (cdr files)))
108           (when (not (featurep 'toolbar))
109             ;; else still define a few functions.
110             (defun toolbar-button-p    (obj) "No toolbar support." nil)
111             (defun toolbar-specifier-p (obj) "No toolbar support." nil))
112           (fmakunbound 'pureload))
113
114         (packages-load-package-dumped-lisps late-package-load-path)
115
116         )) ;; end of call-with-condition-handler
117 \f
118 ;; Fix up the preloaded file list
119 (setq preloaded-file-list (mapcar #'file-name-sans-extension
120                                   preloaded-file-list))
121
122 (setq load-warn-when-source-newer t ; set to t at top of file
123       load-warn-when-source-only nil)
124
125 (setq debugger 'debug)
126
127 (when (member "no-site-file" command-line-args)
128   (setq site-start-file nil))
129
130 ;; If you want additional libraries to be preloaded and their
131 ;; doc strings kept in the DOC file rather than in core,
132 ;; you may load them with a "site-load.el" file.
133 ;; But you must also cause them to be scanned when the DOC file
134 ;; is generated.  For VMS, you must edit ../../vms/makedoc.com.
135 ;; For other systems, you must edit ../../src/Makefile.in.in.
136 (when (load "site-load" t)
137   (garbage-collect))
138
139 ;;FSFmacs randomness
140 ;;(if (fboundp 'x-popup-menu)
141 ;;    (precompute-menubar-bindings))
142 ;;; Turn on recording of which commands get rebound,
143 ;;; for the sake of the next call to precompute-menubar-bindings.
144 ;(setq define-key-rebound-commands nil)
145
146
147 ;; Note: all compiled Lisp files loaded above this point
148 ;; must be among the ones parsed by make-docfile
149 ;; to construct DOC.  Any that are not processed
150 ;; for DOC will not have doc strings in the dumped XEmacs.
151
152 ;; Don't bother with these if we're running temacs, i.e. if we're
153 ;; just debugging don't waste time finding doc strings.
154
155 ;; purify-flag is nil if called from loadup-el.el.
156 (when purify-flag
157   (message "Finding pointers to doc strings...")
158   (Snarf-documentation "DOC")
159   (message "Finding pointers to doc strings...done")
160   (Verify-documentation))
161
162 ;; Note: You can cause additional libraries to be preloaded
163 ;; by writing a site-init.el that loads them.
164 ;; See also "site-load" above.
165 (when (stringp site-start-file)
166   (load "site-init" t))
167 (setq current-load-list nil)
168 (garbage-collect)
169
170 ;;; At this point, we're ready to resume undo recording for scratch.
171 (buffer-enable-undo "*scratch*")
172
173 ) ;; frequent garbage collection
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   (setq 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