1 ;; loadup.el --- load up standardly loaded Lisp files for XEmacs.
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.
7 ;; Maintainer: XEmacs Development Team
8 ;; Keywords: internal, dumped
10 ;; This file is part of XEmacs.
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)
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.
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
27 ;;; Synched up with: Last synched with FSF 19.30, with wild divergence since.
31 ;; Please do not edit this file. Use site-init.el or site-load.el instead.
33 ;; This is loaded into a bare XEmacs to make a dumpable one.
37 (when (fboundp 'error)
38 (error "loadup.el already loaded!"))
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.")
45 (defvar Installation-string nil
46 "Description of XEmacs installation.")
50 (let ((gc-cons-threshold
51 ;; setting it low makes loadup incredibly fucking slow.
52 ;; no need to do it when not dumping.
54 (not (memq 'quick-build internal-error-checking)))
57 ;; This is awfully damn early to be getting an error, right?
58 (call-with-condition-handler 'really-early-error-handler
61 ;; Initialize Installation-string. We do it before loading
62 ;; anything so that dumped code can make use of its value.
63 (setq Installation-string
65 (set-buffer (get-buffer-create (generate-new-buffer-name
67 ;; insert-file-contents-internal bogusly calls
68 ;; format-decode without checking if it's defined.
69 (fset 'format-decode #'(lambda (f l &optional v) l))
70 (insert-file-contents-internal "../Installation")
71 (fmakunbound 'format-decode)
72 (prog1 (buffer-substring)
73 (kill-buffer (current-buffer)))))
75 (let ((build-root (expand-file-name ".." invocation-directory)))
76 (setq load-path (list (expand-file-name "lisp" build-root)))
77 (setq module-load-path (list (expand-file-name "modules" build-root))))
79 ;; message not defined yet ...
80 (external-debugging-output (format "\nUsing load-path %s" load-path))
81 (external-debugging-output (format "\nUsing module-load-path %s"
84 ;; We don't want to have any undo records in the dumped XEmacs.
85 (buffer-disable-undo (get-buffer "*scratch*"))
87 ;; Load our first bootstrap support
88 (load "very-early-lisp" nil t)
90 ;; lread.c (or src/Makefile.in.in) has prepended
91 ;; "${srcdir}/../lisp/" to load-path, which is how this file
92 ;; has been found. At this point, enough of XEmacs has been
93 ;; initialized that we can start dumping "standard" lisp.
94 ;; Dumped lisp from external packages is added when we search
96 ;; #### This code is duplicated in two other places.
97 (let ((temp-path (expand-file-name "." (car load-path))))
98 (setq load-path (nconc (mapcar
99 #'(lambda (i) (concat i "/"))
100 (directory-files temp-path t "^[^-.]"
102 (cons (file-name-as-directory temp-path)
105 (setq load-warn-when-source-newer t ; Used to be set to nil at the end
106 load-warn-when-source-only t) ; Set to nil at the end
108 ;; garbage collect after loading every file in an attempt to
109 ;; minimize the size of the dumped image (if we don't do this,
110 ;; there will be lots of extra space in the data segment filled
111 ;; with garbage-collected junk)
112 (defun pureload (file)
114 (locate-file file load-path
115 (if load-ignore-elc-files
116 '(".el" "") '(".elc" ".el" "")))))
120 ;; but garbage collection really slows down loading.
121 (unless (memq 'quick-build internal-error-checking)
123 (external-debugging-output (format "\nLoad file %s: not found\n"
125 ;; Uncomment in case of trouble
126 ;;(print (format "late-packages: %S" late-packages))
127 ;;(print (format "guessed-roots: %S" (paths-find-emacs-roots invocation-directory invocation-name)))
130 (load (expand-file-name "../lisp/dumped-lisp.el"))
132 (let ((files preloaded-file-list)
134 (while (setq file (car files))
135 (unless (pureload file)
136 (external-debugging-output "Fatal error during load, aborting")
138 (setq files (cdr files)))
139 (when (not (featurep 'toolbar))
140 ;; else still define a few functions.
141 (defun toolbar-button-p (obj) "No toolbar support." nil)
142 (defun toolbar-specifier-p (obj) "No toolbar support." nil))
143 (fmakunbound 'pureload))
145 (packages-load-package-dumped-lisps late-package-load-path)
147 )) ;; end of call-with-condition-handler
149 ;; Fix up the preloaded file list
150 (setq preloaded-file-list (mapcar #'file-name-sans-extension
151 preloaded-file-list))
153 (setq load-warn-when-source-newer t ; set to t at top of file
154 load-warn-when-source-only nil)
156 (setq debugger 'debug)
158 (when (member "no-site-file" command-line-args)
159 (setq site-start-file nil))
161 ;; If you want additional libraries to be preloaded and their
162 ;; doc strings kept in the DOC file rather than in core,
163 ;; you may load them with a "site-load.el" file.
164 ;; But you must also cause them to be scanned when the DOC file
165 ;; is generated. For VMS, you must edit ../../vms/makedoc.com.
166 ;; For other systems, you must edit ../../src/Makefile.in.in.
167 (when (load "site-load" t)
172 ;;(if (fboundp 'x-popup-menu)
173 ;; (precompute-menubar-bindings))
174 ;;; Turn on recording of which commands get rebound,
175 ;;; for the sake of the next call to precompute-menubar-bindings.
176 ;(setq define-key-rebound-commands nil)
178 ;; Note: all compiled Lisp files loaded above this point
179 ;; must be among the ones parsed by make-docfile
180 ;; to construct DOC. Any that are not processed
181 ;; for DOC will not have doc strings in the dumped XEmacs.
183 ;; Don't bother with these if we're running temacs, i.e. if we're
184 ;; just debugging don't waste time finding doc strings.
186 ;; purify-flag is nil if called from loadup-el.el.
188 (message "Finding pointers to doc strings...")
189 (Snarf-documentation "DOC")
190 (message "Finding pointers to doc strings...done")
191 (Verify-documentation))
193 ;; Note: You can cause additional libraries to be preloaded
194 ;; by writing a site-init.el that loads them.
195 ;; See also "site-load" above.
196 (when (stringp site-start-file)
197 (load "site-init" t))
198 (setq current-load-list nil)
201 ;;; At this point, we're ready to resume undo recording for scratch.
202 (buffer-enable-undo "*scratch*")
204 ) ;; frequent garbage collection
208 ;; yuck! need to insert the function def here, and rewrite the dolist
211 ;(defun loadup-profile-results (&optional info stream)
212 ; "Print profiling info INFO to STREAM in a pretty format.
213 ;If INFO is omitted, the current profiling info is retrieved using
214 ; `get-profiling-info'.
215 ;If STREAM is omitted, either a *Profiling Results* buffer or standard
216 ; output are used, depending on whether the function was called
217 ; interactively or not."
219 ; (setq info (if info
221 ; (get-profiling-info)))
222 ; (when (and (not stream)
224 ; (pop-to-buffer (get-buffer-create "*Profiling Results*"))
226 ; (let ((standard-output (or stream (if (interactive-p)
229 ; ;; Calculate the longest function
230 ; (maxfunlen (apply #'max
231 ; (length "Function Name")
234 ; ;; Functions longer than 50 characters (usually
235 ; ;; anonymous functions) don't qualify
236 ; (let ((l (length (format "%s" (car el)))))
240 ; (princ (format "%-*s Ticks %%/Total Call Count\n"
241 ; maxfunlen "Function Name"))
242 ; (princ (make-string maxfunlen ?=))
243 ; (princ " ===== ======= ==========\n")
244 ; (let ((sum (float (apply #'+ (mapcar #'cdr info)))))
246 ; (entry-list (nreverse (sort info #'cdr-less-than-cdr))))
248 ; (setq entry (car entry-list))
249 ; (princ (format "%-*s %-5d %-6.3f %s\n"
250 ; maxfunlen (car entry) (cdr entry)
251 ; (* 100 (/ (cdr entry) sum))
252 ; (or (gethash (car entry) call-count-profile-table)
254 ; (setq entry-list (cdr entry-list))))
255 ; (princ (make-string maxfunlen ?-))
256 ; (princ "---------------------------------\n")
257 ; (princ (format "%-*s %-5d %-6.2f\n" maxfunlen "Total" sum 100.0))
258 ; (princ (format "\n\nOne tick = %g ms\n"
259 ; (/ default-profiling-interval 1000.0)))
260 ; (and (boundp 'internal-error-checking)
261 ; internal-error-checking
263 ;WARNING: Error checking is turned on in this XEmacs. This might make
264 ; the measurements very unreliable.\n"))))
265 ; (when (and (not stream)
267 ; (goto-char (point-min))))
269 ;(loadup-profile-results nil 'external-debugging-output)
271 ;; Dump into the name `xemacs' (only)
272 (when (member "dump" command-line-args)
273 (message "Dumping under the name xemacs")
274 ;; This is handled earlier in the build process.
275 ;; (condition-case () (delete-file "xemacs") (file-error nil))
276 (when (fboundp 'really-free)
280 ((featurep 'infodock) "infodock")
282 ;; If we want to dump under a name other than `xemacs', do that here!
283 ;; ((featurep 'gtk) "xemacs-gtk")
288 ;; Avoid error if user loads some more libraries now.
289 (setq purify-flag nil)
291 (when (member "run-temacs" command-line-args)
292 (message "\nBootstrapping from temacs...")
293 ;; Remove all args up to and including "run-temacs"
294 (apply #'run-emacs-from-temacs (cdr (member "run-temacs" command-line-args)))
295 ;; run-emacs-from-temacs doesn't actually return anyway.
299 ;; If you are using 'recompile', then you should have used -l loadup-el.el
300 ;; so that the .el files always get loaded (the .elc files may be out-of-
302 (when (member "recompile" command-line-args)
303 (setq command-line-args-left (cdr (member "recompile" command-line-args)))
304 (batch-byte-recompile-directory)
307 ;; For machines with CANNOT_DUMP defined in config.h,
308 ;; this file must be loaded each time Emacs is run.
309 ;; So run the startup code now.
311 (when (not (fboundp 'dump-emacs))
312 ;; Avoid loading loadup.el a second time!
313 (setq command-line-args (cdr (cdr command-line-args)))
316 ;;; loadup.el ends here