Spelling fixes.
[bpt/emacs.git] / lisp / loadup.el
1 ;;; loadup.el --- load up standardly loaded Lisp files for Emacs
2
3 ;; Copyright (C) 1985-1986, 1992, 1994, 2001-2012
4 ;; Free Software Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: internal
8 ;; Package: emacs
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24
25 ;;; Commentary:
26
27 ;; This is loaded into a bare Emacs to make a dumpable one.
28
29 ;; If you add/remove Lisp files to be loaded here, consider the
30 ;; following issues:
31
32 ;; i) Any file loaded on any platform should appear in $lisp in src/lisp.mk.
33 ;; Use the .el or .elc version as appropriate.
34
35 ;; This ensures both that the Lisp files are compiled (if necessary)
36 ;; before the emacs executable is dumped, and that they are passed to
37 ;; make-docfile. (Any that are not processed for DOC will not have
38 ;; doc strings in the dumped Emacs.) Because of this:
39
40 ;; ii) If the file is loaded uncompiled, it should (where possible)
41 ;; obey the doc-string conventions expected by make-docfile.
42
43 ;;; Code:
44
45 ;; Add subdirectories to the load-path for files that might get
46 ;; autoloaded when bootstrapping.
47 ;; This is because PATH_DUMPLOADSEARCH is just "../lisp".
48 ;; Note that we reset load-path below just before dumping,
49 ;; since lread.c:init_lread checks for changes to load-path
50 ;; in deciding whether to modify it.
51 (if (or (equal (nth 3 command-line-args) "bootstrap")
52 (equal (nth 4 command-line-args) "bootstrap")
53 (equal (nth 3 command-line-args) "unidata-gen.el")
54 (equal (nth 4 command-line-args) "unidata-gen-files")
55 ;; In case CANNOT_DUMP.
56 (string-match "src/bootstrap-emacs" (nth 0 command-line-args)))
57 (let ((dir (car load-path)))
58 ;; We'll probably overflow the pure space.
59 (setq purify-flag nil)
60 (setq load-path (list dir
61 (expand-file-name "emacs-lisp" dir)
62 (expand-file-name "language" dir)
63 (expand-file-name "international" dir)
64 (expand-file-name "textmodes" dir)))))
65
66 (if (eq t purify-flag)
67 ;; Hash consing saved around 11% of pure space in my tests.
68 (setq purify-flag (make-hash-table :test 'equal :size 70000)))
69
70 (message "Using load-path %s" load-path)
71
72 (if (or (member (nth 3 command-line-args) '("dump" "bootstrap"))
73 (member (nth 4 command-line-args) '("dump" "bootstrap")))
74 ;; To reduce the size of dumped Emacs, we avoid making huge
75 ;; char-tables.
76 (setq inhibit-load-charset-map t))
77
78 ;; We don't want to have any undo records in the dumped Emacs.
79 (set-buffer "*scratch*")
80 (setq buffer-undo-list t)
81
82 (load "emacs-lisp/byte-run")
83 (load "emacs-lisp/backquote")
84 (load "subr")
85
86 ;; Do it after subr, since both after-load-functions and add-hook are
87 ;; implemented in subr.el.
88 (add-hook 'after-load-functions (lambda (f) (garbage-collect)))
89
90 (load "version")
91
92 (load "widget")
93 (load "custom")
94 (load "emacs-lisp/map-ynp")
95 (load "international/mule")
96 (load "international/mule-conf")
97 (load "env")
98 (load "format")
99 (load "bindings")
100 (load "cus-start")
101 (load "window") ; Needed here for `replace-buffer-in-windows'.
102 (setq load-source-file-function 'load-with-code-conversion)
103 (load "files")
104
105 (load "cus-face")
106 (load "faces") ; after here, `defface' may be used.
107
108 (load "button")
109 (load "startup")
110
111 (condition-case nil
112 ;; Don't get confused if someone compiled this by mistake.
113 (load "loaddefs.el")
114 ;; In case loaddefs hasn't been generated yet.
115 (file-error (load "ldefs-boot.el")))
116
117 (load "minibuffer")
118 (load "abbrev") ;lisp-mode.el and simple.el use define-abbrev-table.
119 (load "simple")
120
121 (load "help")
122
123 (load "jka-cmpr-hook")
124 (load "epa-hook")
125 ;; Any Emacs Lisp source file (*.el) loaded here after can contain
126 ;; multilingual text.
127 (load "international/mule-cmds")
128 (load "case-table")
129 ;; This file doesn't exist when building a development version of Emacs
130 ;; from the repository. It is generated just after temacs is built.
131 (load "international/charprop.el" t)
132 (load "international/characters")
133 (load "composite")
134
135 ;; Load language-specific files.
136 (load "language/chinese")
137 (load "language/cyrillic")
138 (load "language/indian")
139 (load "language/sinhala")
140 (load "language/english")
141 (load "language/ethiopic")
142 (load "language/european")
143 (load "language/czech")
144 (load "language/slovak")
145 (load "language/romanian")
146 (load "language/greek")
147 (load "language/hebrew")
148 (load "language/japanese")
149 (load "language/korean")
150 (load "language/lao")
151 (load "language/tai-viet")
152 (load "language/thai")
153 (load "language/tibetan")
154 (load "language/vietnamese")
155 (load "language/misc-lang")
156 (load "language/utf-8-lang")
157 (load "language/georgian")
158 (load "language/khmer")
159 (load "language/burmese")
160 (load "language/cham")
161
162 (load "indent")
163 (load "frame")
164 (load "term/tty-colors")
165 (load "font-core")
166 ;; facemenu must be loaded before font-lock, because `facemenu-keymap'
167 ;; needs to be defined when font-lock is loaded.
168 (load "facemenu")
169 (load "emacs-lisp/syntax")
170 (load "font-lock")
171 (load "jit-lock")
172
173 (if (fboundp 'track-mouse)
174 (progn
175 (load "mouse")
176 (and (boundp 'x-toolkit-scroll-bars)
177 (load "scroll-bar"))
178 (load "select")))
179 (load "emacs-lisp/timer")
180 (load "isearch")
181 (load "rfn-eshadow")
182
183 (load "menu-bar")
184 (load "emacs-lisp/lisp")
185 (load "textmodes/page")
186 (load "register")
187 (load "textmodes/paragraphs")
188 (load "emacs-lisp/lisp-mode")
189 (load "textmodes/text-mode")
190 (load "textmodes/fill")
191 (load "newcomment")
192
193 (load "replace")
194 (load "emacs-lisp/tabulated-list")
195 (load "buff-menu")
196
197 (if (fboundp 'x-create-frame)
198 (progn
199 (load "fringe")
200 ;; Needed by `imagemagick-register-types'
201 (load "emacs-lisp/regexp-opt")
202 (load "image")
203 (load "international/fontset")
204 (load "dnd")
205 (load "tool-bar")))
206
207 (if (featurep 'dynamic-setting)
208 (load "dynamic-setting"))
209
210 (if (featurep 'x)
211 (progn
212 (load "x-dnd")
213 (load "term/common-win")
214 (load "term/x-win")))
215
216 (if (eq system-type 'windows-nt)
217 (progn
218 (load "w32-vars")
219 (load "term/common-win")
220 (load "term/w32-win")
221 (load "ls-lisp")
222 (load "disp-table")
223 (load "dos-w32")
224 (load "w32-fns")))
225 (if (eq system-type 'ms-dos)
226 (progn
227 (load "dos-w32")
228 (load "dos-fns")
229 (load "dos-vars")
230 ;; Don't load term/common-win: it isn't appropriate for the `pc'
231 ;; ``window system'', which generally behaves like a terminal.
232 (load "term/pc-win")
233 (load "ls-lisp")
234 (load "disp-table"))) ; needed to setup ibm-pc char set, see internal.el
235 (if (featurep 'ns)
236 (progn
237 (load "term/common-win")
238 (load "term/ns-win")))
239 (if (fboundp 'x-create-frame)
240 ;; Do it after loading term/foo-win.el since the value of the
241 ;; mouse-wheel-*-event vars depends on those files being loaded or not.
242 (load "mwheel"))
243 ;; Preload some constants and floating point functions.
244 (load "emacs-lisp/float-sup")
245
246 (load "vc/vc-hooks")
247 (load "vc/ediff-hook")
248 (if (fboundp 'x-show-tip) (load "tooltip"))
249
250 ;If you want additional libraries to be preloaded and their
251 ;doc strings kept in the DOC file rather than in core,
252 ;you may load them with a "site-load.el" file.
253 ;But you must also cause them to be scanned when the DOC file
254 ;is generated.
255 ;For other systems, you must edit ../src/Makefile.in.
256 (load "site-load" t)
257
258 ;; ¡¡¡ Big Ugly Hack !!!
259 ;; src/bootstrap-emacs is mostly used to compile .el files, so it needs
260 ;; macroexp, bytecomp, cconv, and byte-opt to be fast. Generally this is done
261 ;; by compiling those files first, but this only makes a difference if those
262 ;; files are not preloaded. As it so happens, macroexp.el tends to be
263 ;; accidentally preloaded in src/bootstrap-emacs because cl.el and cl-macs.el
264 ;; require it. So let's unload it here, if needed, to make sure the
265 ;; byte-compiled version is used.
266 (if (or (not (fboundp 'macroexpand-all))
267 (byte-code-function-p (symbol-function 'macroexpand-all)))
268 nil
269 (fmakunbound 'macroexpand-all)
270 (setq features (delq 'macroexp features))
271 (autoload 'macroexpand-all "macroexp"))
272
273 ;; Determine which last version number to use
274 ;; based on the executables that now exist.
275 (if (and (or (equal (nth 3 command-line-args) "dump")
276 (equal (nth 4 command-line-args) "dump"))
277 (not (eq system-type 'ms-dos)))
278 (let* ((base (concat "emacs-" emacs-version "."))
279 (files (file-name-all-completions base default-directory))
280 (versions (mapcar (function (lambda (name)
281 (string-to-number (substring name (length base)))))
282 files)))
283 (setq emacs-bzr-version (condition-case nil (emacs-bzr-get-version)
284 (error nil)))
285 ;; `emacs-version' is a constant, so we shouldn't change it with `setq'.
286 (defconst emacs-version
287 (format "%s.%d"
288 emacs-version (if versions (1+ (apply 'max versions)) 1)))))
289
290
291 (message "Finding pointers to doc strings...")
292 (if (or (equal (nth 3 command-line-args) "dump")
293 (equal (nth 4 command-line-args) "dump"))
294 (let ((name emacs-version))
295 (while (string-match "[^-+_.a-zA-Z0-9]+" name)
296 (setq name (concat (downcase (substring name 0 (match-beginning 0)))
297 "-"
298 (substring name (match-end 0)))))
299 (if (memq system-type '(ms-dos windows-nt))
300 (setq name (expand-file-name
301 (if (fboundp 'x-create-frame) "DOC-X" "DOC") "../etc"))
302 (setq name (concat (expand-file-name "../etc/DOC-") name))
303 (if (file-exists-p name)
304 (delete-file name))
305 (copy-file (expand-file-name "../etc/DOC") name t))
306 (Snarf-documentation (file-name-nondirectory name)))
307 (condition-case nil
308 (Snarf-documentation "DOC")
309 (error nil)))
310 (message "Finding pointers to doc strings...done")
311
312 ;; Note: You can cause additional libraries to be preloaded
313 ;; by writing a site-init.el that loads them.
314 ;; See also "site-load" above.
315 (load "site-init" t)
316 (setq current-load-list nil)
317
318 ;; We keep the load-history data in PURE space.
319 ;; Make sure that the spine of the list is not in pure space because it can
320 ;; be destructively mutated in lread.c:build_load_history.
321 (setq load-history (mapcar 'purecopy load-history))
322
323 (set-buffer-modified-p nil)
324
325 ;; reset the load-path. See lread.c:init_lread why.
326 (if (or (equal (nth 3 command-line-args) "bootstrap")
327 (equal (nth 4 command-line-args) "bootstrap"))
328 (setcdr load-path nil))
329
330 (remove-hook 'after-load-functions (lambda (f) (garbage-collect)))
331
332 (setq inhibit-load-charset-map nil)
333 (clear-charset-maps)
334 (garbage-collect)
335
336 ;; At this point, we're ready to resume undo recording for scratch.
337 (buffer-enable-undo "*scratch*")
338
339 (when (hash-table-p purify-flag)
340 (let ((strings 0)
341 (vectors 0)
342 (bytecodes 0)
343 (conses 0)
344 (others 0))
345 (maphash (lambda (k v)
346 (cond
347 ((stringp k) (setq strings (1+ strings)))
348 ((vectorp k) (setq vectors (1+ vectors)))
349 ((consp k) (setq conses (1+ conses)))
350 ((byte-code-function-p v) (setq bytecodes (1+ bytecodes)))
351 (t (setq others (1+ others)))))
352 purify-flag)
353 (message "Pure-hashed: %d strings, %d vectors, %d conses, %d bytecodes, %d others"
354 strings vectors conses bytecodes others)))
355
356 ;; Avoid error if user loads some more libraries now and make sure the
357 ;; hash-consing hash table is GC'd.
358 (setq purify-flag nil)
359
360 (if (null (garbage-collect))
361 (setq pure-space-overflow t))
362
363 (if (or (member (nth 3 command-line-args) '("dump" "bootstrap"))
364 (member (nth 4 command-line-args) '("dump" "bootstrap")))
365 (progn
366 (if (memq system-type '(ms-dos windows-nt cygwin))
367 (message "Dumping under the name emacs")
368 (message "Dumping under the name emacs"))
369 (condition-case ()
370 (delete-file "emacs")
371 (file-error nil))
372 ;; We used to dump under the name xemacs, but that occasionally
373 ;; confused people installing Emacs (they'd install the file
374 ;; under the name `xemacs'), and it's inconsistent with every
375 ;; other GNU program's build process.
376 (dump-emacs "emacs" "temacs")
377 (message "%d pure bytes used" pure-bytes-used)
378 ;; Recompute NAME now, so that it isn't set when we dump.
379 (if (not (or (memq system-type '(ms-dos windows-nt))
380 ;; Don't bother adding another name if we're just
381 ;; building bootstrap-emacs.
382 (equal (nth 3 command-line-args) "bootstrap")
383 (equal (nth 4 command-line-args) "bootstrap")))
384 (let ((name (concat "emacs-" emacs-version)))
385 (while (string-match "[^-+_.a-zA-Z0-9]+" name)
386 (setq name (concat (downcase (substring name 0 (match-beginning 0)))
387 "-"
388 (substring name (match-end 0)))))
389 (message "Adding name %s" name)
390 (add-name-to-file "emacs" name t)))
391 (kill-emacs)))
392
393 ;; For machines with CANNOT_DUMP defined in config.h,
394 ;; this file must be loaded each time Emacs is run.
395 ;; So run the startup code now. First, remove `-l loadup' from args.
396
397 (if (and (equal (nth 1 command-line-args) "-l")
398 (equal (nth 2 command-line-args) "loadup"))
399 (setcdr command-line-args (nthcdr 3 command-line-args)))
400
401 (eval top-level)
402
403 \f
404 ;; Local Variables:
405 ;; no-byte-compile: t
406 ;; no-update-autoloads: t
407 ;; End:
408
409 ;;; loadup.el ends here