loadup.el 13.2 KB
Newer Older
1
;;; loadup.el --- load up standardly loaded Lisp files for Emacs
Eric S. Raymond's avatar
Eric S. Raymond committed
2

3
;; Copyright (C) 1985-1986, 1992, 1994, 2001-2012
4
;;   Free Software Foundation, Inc.
Eric S. Raymond's avatar
Eric S. Raymond committed
5

Eric S. Raymond's avatar
Eric S. Raymond committed
6
;; Maintainer: FSF
Eric S. Raymond's avatar
Eric S. Raymond committed
7
;; Keywords: internal
8
;; Package: emacs
Eric S. Raymond's avatar
Eric S. Raymond committed
9

Jim Blandy's avatar
Jim Blandy committed
10 11
;; This file is part of GNU Emacs.

12
;; GNU Emacs is free software: you can redistribute it and/or modify
Jim Blandy's avatar
Jim Blandy committed
13
;; it under the terms of the GNU General Public License as published by
14 15
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
Jim Blandy's avatar
Jim Blandy committed
16 17 18 19 20 21 22

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; 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/>.
Jim Blandy's avatar
Jim Blandy committed
24

Eric S. Raymond's avatar
Eric S. Raymond committed
25 26 27 28
;;; Commentary:

;; This is loaded into a bare Emacs to make a dumpable one.

Glenn Morris's avatar
Glenn Morris committed
29 30 31
;; If you add/remove Lisp files to be loaded here, consider the
;; following issues:

32 33
;; i) Any file loaded on any platform should appear in $lisp in src/lisp.mk.
;; Use the .el or .elc version as appropriate.
Glenn Morris's avatar
Glenn Morris committed
34

35 36 37 38
;; This ensures both that the Lisp files are compiled (if necessary)
;; before the emacs executable is dumped, and that they are passed to
;; make-docfile.  (Any that are not processed for DOC will not have
;; doc strings in the dumped Emacs.)  Because of this:
Glenn Morris's avatar
Glenn Morris committed
39

40
;; ii) If the file is loaded uncompiled, it should (where possible)
Glenn Morris's avatar
Glenn Morris committed
41 42
;; obey the doc-string conventions expected by make-docfile.

Eric S. Raymond's avatar
Eric S. Raymond committed
43 44
;;; Code:

Glenn Morris's avatar
Glenn Morris committed
45 46
;; Add subdirectories to the load-path for files that might get
;; autoloaded when bootstrapping.
47
(if (or (equal (nth 3 command-line-args) "bootstrap")
48
	(equal (nth 4 command-line-args) "bootstrap")
49 50
	(equal (nth 3 command-line-args) "unidata-gen.el")
	(equal (nth 4 command-line-args) "unidata-gen-files")
Glenn Morris's avatar
Glenn Morris committed
51
	;; In case CANNOT_DUMP.
Glenn Morris's avatar
Glenn Morris committed
52
	(string-match "src/bootstrap-emacs" (nth 0 command-line-args)))
53
    (let ((dir (car load-path)))
54 55
      ;; We'll probably overflow the pure space.
      (setq purify-flag nil)
56 57 58 59 60
      (setq load-path (list dir
			    (expand-file-name "emacs-lisp" dir)
			    (expand-file-name "language" dir)
			    (expand-file-name "international" dir)
			    (expand-file-name "textmodes" dir)))))
61

Stefan Monnier's avatar
Stefan Monnier committed
62 63
(if (eq t purify-flag)
    ;; Hash consing saved around 11% of pure space in my tests.
64
    (setq purify-flag (make-hash-table :test 'equal :size 70000)))
Stefan Monnier's avatar
Stefan Monnier committed
65

66 67
(message "Using load-path %s" load-path)

68 69 70 71 72 73
(if (or (member (nth 3 command-line-args) '("dump" "bootstrap"))
	(member (nth 4 command-line-args) '("dump" "bootstrap")))
    ;; To reduce the size of dumped Emacs, we avoid making huge
    ;; char-tables.
    (setq inhibit-load-charset-map t))

74
;; We don't want to have any undo records in the dumped Emacs.
75 76
(set-buffer "*scratch*")
(setq buffer-undo-list t)
Jim Blandy's avatar
Jim Blandy committed
77

78
(load "emacs-lisp/byte-run")
79
(load "emacs-lisp/backquote")
Jim Blandy's avatar
Jim Blandy committed
80
(load "subr")
81

82 83
;; Do it after subr, since both after-load-functions and add-hook are
;; implemented in subr.el.
84
(add-hook 'after-load-functions (lambda (f) (garbage-collect)))
85

86
(load "version")
87

88 89
(load "widget")
(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)
Jim Blandy's avatar
Jim Blandy committed
99
(load "files")
100

101
(load "cus-face")
102 103
(load "faces")  ; after here, `defface' may be used.

104 105 106
(load "button")
(load "startup")

107 108 109 110 111 112
(condition-case nil
    ;; Don't get confused if someone compiled this by mistake.
    (load "loaddefs.el")
  ;; In case loaddefs hasn't been generated yet.
  (file-error (load "ldefs-boot.el")))

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 122 123 124
;; Any Emacs Lisp source file (*.el) loaded here after can contain
;; multilingual text.
(load "international/mule-cmds")
(load "case-table")
Glenn Morris's avatar
Glenn Morris committed
125 126
;; This file doesn't exist when building a development version of Emacs
;; from the repository.  It is generated just after temacs is built.
127
(load "international/charprop.el" t)
128 129
(load "international/characters")
(load "composite")
130

131
;; Load language-specific files.
Karl Heuer's avatar
Karl Heuer committed
132 133 134
(load "language/chinese")
(load "language/cyrillic")
(load "language/indian")
135
(load "language/sinhala")
136
(load "language/english")
Karl Heuer's avatar
Karl Heuer committed
137 138
(load "language/ethiopic")
(load "language/european")
139 140
(load "language/czech")
(load "language/slovak")
Dan Nicolaescu's avatar
Dan Nicolaescu committed
141
(load "language/romanian")
Karl Heuer's avatar
Karl Heuer committed
142 143 144 145
(load "language/greek")
(load "language/hebrew")
(load "language/japanese")
(load "language/korean")
Kenichi Handa's avatar
Kenichi Handa committed
146
(load "language/lao")
Kenichi Handa's avatar
Kenichi Handa committed
147
(load "language/tai-viet")
Karl Heuer's avatar
Karl Heuer committed
148
(load "language/thai")
149
(load "language/tibetan")
Karl Heuer's avatar
Karl Heuer committed
150 151
(load "language/vietnamese")
(load "language/misc-lang")
152 153
(load "language/utf-8-lang")
(load "language/georgian")
154
(load "language/khmer")
155
(load "language/burmese")
Kenichi Handa's avatar
Kenichi Handa committed
156
(load "language/cham")
157

Jim Blandy's avatar
Jim Blandy committed
158
(load "indent")
159
(load "frame")
160
(load "term/tty-colors")
Colin Walters's avatar
Colin Walters committed
161
(load "font-core")
162 163
;; facemenu must be loaded before font-lock, because `facemenu-keymap'
;; needs to be defined when font-lock is loaded.
164
(load "facemenu")
165 166 167
(load "emacs-lisp/syntax")
(load "font-lock")
(load "jit-lock")
168

169 170 171
(if (fboundp 'track-mouse)
    (progn
      (load "mouse")
172
      (and (boundp 'x-toolkit-scroll-bars)
173
	   (load "scroll-bar"))
174
      (load "select")))
175
(load "emacs-lisp/timer")
176
(load "isearch")
Luc Teirlinck's avatar
Luc Teirlinck committed
177
(load "rfn-eshadow")
178

Richard M. Stallman's avatar
Richard M. Stallman committed
179
(load "menu-bar")
180 181
(load "emacs-lisp/lisp")
(load "textmodes/page")
Jim Blandy's avatar
Jim Blandy committed
182
(load "register")
183 184 185 186
(load "textmodes/paragraphs")
(load "emacs-lisp/lisp-mode")
(load "textmodes/text-mode")
(load "textmodes/fill")
187
(load "newcomment")
188

Jim Blandy's avatar
Jim Blandy committed
189
(load "replace")
190
(load "emacs-lisp/tabulated-list")
Jim Blandy's avatar
Jim Blandy committed
191
(load "buff-menu")
192 193 194

(if (fboundp 'x-create-frame)
    (progn
195
      (load "fringe")
196 197
      ;; Needed by `imagemagick-register-types'
      (load "emacs-lisp/regexp-opt")
198 199 200 201
      (load "image")
      (load "international/fontset")
      (load "dnd")
      (load "tool-bar")))
202

203 204
(if (featurep 'dynamic-setting)
    (load "dynamic-setting"))
205

206
(if (featurep 'x)
207
    (progn
208
      (load "x-dnd")
209
      (load "term/common-win")
210
      (load "term/x-win")))
211

212 213
(if (eq system-type 'windows-nt)
    (progn
214
      (load "w32-vars")
215
      (load "term/common-win")
216
      (load "term/w32-win")
217
      (load "ls-lisp")
Eli Zaretskii's avatar
Eli Zaretskii committed
218
      (load "disp-table")
Geoff Voelker's avatar
Geoff Voelker committed
219
      (load "dos-w32")
220
      (load "w32-fns")))
221 222
(if (eq system-type 'ms-dos)
    (progn
Geoff Voelker's avatar
Geoff Voelker committed
223
      (load "dos-w32")
224
      (load "dos-fns")
225
      (load "dos-vars")
Eli Zaretskii's avatar
Eli Zaretskii committed
226 227 228 229
      ;; Don't load term/common-win: it isn't appropriate for the `pc'
      ;; ``window system'', which generally behaves like a terminal.
      (load "term/pc-win")
      (load "ls-lisp")
230
      (load "disp-table"))) ; needed to setup ibm-pc char set, see internal.el
Dan Nicolaescu's avatar
Dan Nicolaescu committed
231
(if (featurep 'ns)
Glenn Morris's avatar
Glenn Morris committed
232 233 234
    (progn
      (load "term/common-win")
      (load "term/ns-win")))
235 236 237 238
(if (fboundp 'x-create-frame)
    ;; Do it after loading term/foo-win.el since the value of the
    ;; mouse-wheel-*-event vars depends on those files being loaded or not.
    (load "mwheel"))
239 240
;; Preload some constants and floating point functions.
(load "emacs-lisp/float-sup")
241

242 243
(load "vc/vc-hooks")
(load "vc/ediff-hook")
244
(if (fboundp 'x-show-tip) (load "tooltip"))
245

Jim Blandy's avatar
Jim Blandy committed
246 247 248 249
;If you want additional libraries to be preloaded and their
;doc strings kept in the DOC file rather than in core,
;you may load them with a "site-load.el" file.
;But you must also cause them to be scanned when the DOC file
Dan Nicolaescu's avatar
Dan Nicolaescu committed
250
;is generated.
Richard M. Stallman's avatar
Richard M. Stallman committed
251
;For other systems, you must edit ../src/Makefile.in.
252
(load "site-load" t)
Jim Blandy's avatar
Jim Blandy committed
253

254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
;; ¡¡¡ Big Ugly Hack !!!
;; src/boostrap-emacs is mostly used to compile .el files, so it needs
;; macroexp, bytecomp, cconv, and byte-opt to be fast.  Generally this is done
;; by compiling those files first, but this only makes a difference if those
;; files are not preloaded.  As it so happens, macroexp.el tends to be
;; accidentally preloaded in src/boostrap-emacs because cl.el and cl-macs.el
;; require it.  So lets unload it here, if needed, to make sure the
;; byte-compiled version is used.
(if (or (not (fboundp 'macroexpand-all))
        (byte-code-function-p (symbol-function 'macroexpand-all)))
    nil
  (fmakunbound 'macroexpand-all)
  (setq features (delq 'macroexp features))
  (autoload 'macroexpand-all "macroexp"))

269 270
;; Determine which last version number to use
;; based on the executables that now exist.
271 272 273
(if (and (or (equal (nth 3 command-line-args) "dump")
	     (equal (nth 4 command-line-args) "dump"))
	 (not (eq system-type 'ms-dos)))
274
    (let* ((base (concat "emacs-" emacs-version "."))
275 276
	   (files (file-name-all-completions base default-directory))
	   (versions (mapcar (function (lambda (name)
277
					 (string-to-number (substring name (length base)))))
278
			     files)))
Glenn Morris's avatar
Glenn Morris committed
279 280
      (setq emacs-bzr-version (condition-case nil (emacs-bzr-get-version)
                              (error nil)))
281 282 283 284
      ;; `emacs-version' is a constant, so we shouldn't change it with `setq'.
      (defconst emacs-version
	(format "%s.%d"
		emacs-version (if versions (1+ (apply 'max versions)) 1)))))
285

Jim Blandy's avatar
Jim Blandy committed
286 287

(message "Finding pointers to doc strings...")
288 289
(if (or (equal (nth 3 command-line-args) "dump")
	(equal (nth 4 command-line-args) "dump"))
Jim Blandy's avatar
Jim Blandy committed
290 291 292 293 294
    (let ((name emacs-version))
      (while (string-match "[^-+_.a-zA-Z0-9]+" name)
	(setq name (concat (downcase (substring name 0 (match-beginning 0)))
			   "-"
			   (substring name (match-end 0)))))
295
      (if (memq system-type '(ms-dos windows-nt))
Morten Welinder's avatar
Morten Welinder committed
296
	  (setq name (expand-file-name
297
		      (if (fboundp 'x-create-frame) "DOC-X" "DOC") "../etc"))
298 299 300 301
	(setq name (concat (expand-file-name "../etc/DOC-") name))
	(if (file-exists-p name)
	    (delete-file name))
	(copy-file (expand-file-name "../etc/DOC") name t))
Roland McGrath's avatar
Roland McGrath committed
302
      (Snarf-documentation (file-name-nondirectory name)))
303 304 305
    (condition-case nil
	(Snarf-documentation "DOC")
      (error nil)))
Jim Blandy's avatar
Jim Blandy committed
306 307
(message "Finding pointers to doc strings...done")

308 309 310
;; Note: You can cause additional libraries to be preloaded
;; by writing a site-init.el that loads them.
;; See also "site-load" above.
Jim Blandy's avatar
Jim Blandy committed
311
(load "site-init" t)
312
(setq current-load-list nil)
313

314
;; We keep the load-history data in PURE space.
315 316 317 318
;; Make sure that the spine of the list is not in pure space because it can
;; be destructively mutated in lread.c:build_load_history.
(setq load-history (mapcar 'purecopy load-history))

319
(set-buffer-modified-p nil)
320

321 322 323 324 325
;; reset the load-path.  See lread.c:init_lread why.
(if (or (equal (nth 3 command-line-args) "bootstrap")
	(equal (nth 4 command-line-args) "bootstrap"))
    (setcdr load-path nil))

326
(remove-hook 'after-load-functions (lambda (f) (garbage-collect)))
327

328
(setq inhibit-load-charset-map nil)
329
(clear-charset-maps)
Jim Blandy's avatar
Jim Blandy committed
330 331
(garbage-collect)

332
;; At this point, we're ready to resume undo recording for scratch.
Jim Blandy's avatar
Jim Blandy committed
333 334
(buffer-enable-undo "*scratch*")

335 336 337
(when (hash-table-p purify-flag)
  (let ((strings 0)
        (vectors 0)
338
        (bytecodes 0)
339 340 341 342 343 344 345
        (conses 0)
        (others 0))
    (maphash (lambda (k v)
               (cond
                ((stringp k) (setq strings (1+ strings)))
                ((vectorp k) (setq vectors (1+ vectors)))
                ((consp k)   (setq conses  (1+ conses)))
346
                ((byte-code-function-p v) (setq bytecodes (1+ bytecodes)))
347 348
                (t           (setq others  (1+ others)))))
             purify-flag)
349 350
    (message "Pure-hashed: %d strings, %d vectors, %d conses, %d bytecodes, %d others"
             strings vectors conses bytecodes others)))
351

Stefan Monnier's avatar
Stefan Monnier committed
352 353 354 355
;; Avoid error if user loads some more libraries now and make sure the
;; hash-consing hash table is GC'd.
(setq purify-flag nil)

356 357 358
(if (null (garbage-collect))
    (setq pure-space-overflow t))

359 360
(if (or (member (nth 3 command-line-args) '("dump" "bootstrap"))
	(member (nth 4 command-line-args) '("dump" "bootstrap")))
Dan Nicolaescu's avatar
Dan Nicolaescu committed
361
    (progn
362 363 364
      (if (memq system-type '(ms-dos windows-nt cygwin))
          (message "Dumping under the name emacs")
        (message "Dumping under the name emacs"))
Jim Blandy's avatar
Jim Blandy committed
365
      (condition-case ()
366
	  (delete-file "emacs")
Jim Blandy's avatar
Jim Blandy committed
367
	(file-error nil))
368 369 370
      ;; We used to dump under the name xemacs, but that occasionally
      ;; confused people installing Emacs (they'd install the file
      ;; under the name `xemacs'), and it's inconsistent with every
Karl Heuer's avatar
Karl Heuer committed
371
      ;; other GNU program's build process.
372
      (dump-emacs "emacs" "temacs")
Richard M. Stallman's avatar
Richard M. Stallman committed
373
      (message "%d pure bytes used" pure-bytes-used)
Jim Blandy's avatar
Jim Blandy committed
374
      ;; Recompute NAME now, so that it isn't set when we dump.
375
      (if (not (or (memq system-type '(ms-dos windows-nt))
376 377 378 379
                   ;; Don't bother adding another name if we're just
                   ;; building bootstrap-emacs.
                   (equal (nth 3 command-line-args) "bootstrap")
                   (equal (nth 4 command-line-args) "bootstrap")))
380 381 382 383 384
	  (let ((name (concat "emacs-" emacs-version)))
	    (while (string-match "[^-+_.a-zA-Z0-9]+" name)
	      (setq name (concat (downcase (substring name 0 (match-beginning 0)))
				 "-"
				 (substring name (match-end 0)))))
385
            (message "Adding name %s" name)
386
	    (add-name-to-file "emacs" name t)))
Jim Blandy's avatar
Jim Blandy committed
387 388 389 390
      (kill-emacs)))

;; For machines with CANNOT_DUMP defined in config.h,
;; this file must be loaded each time Emacs is run.
391
;; So run the startup code now.  First, remove `-l loadup' from args.
Jim Blandy's avatar
Jim Blandy committed
392

393 394 395 396 397
(if (and (equal (nth 1 command-line-args) "-l")
	 (equal (nth 2 command-line-args) "loadup"))
    (setcdr command-line-args (nthcdr 3 command-line-args)))

(eval top-level)
Eric S. Raymond's avatar
Eric S. Raymond committed
398

399

Stefan Monnier's avatar
Stefan Monnier committed
400 401 402 403
;; Local Variables:
;; no-byte-compile: t
;; no-update-autoloads: t
;; End:
Kenichi Handa's avatar
Kenichi Handa committed
404

Eric S. Raymond's avatar
Eric S. Raymond committed
405
;;; loadup.el ends here