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