loadup.el 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. ;;; loadup.el --- load up standardly loaded Lisp files for Emacs
  2. ;; Copyright (C) 1985-1986, 1992, 1994, 2001-2017 Free Software
  3. ;; Foundation, Inc.
  4. ;; Maintainer: emacs-devel@gnu.org
  5. ;; Keywords: internal
  6. ;; Package: emacs
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This is loaded into a bare Emacs to make a dumpable one.
  20. ;; If you add a file to be loaded here, keep the following points in mind:
  21. ;; i) If the file is no-byte-compile, explicitly load the .el version.
  22. ;; Such files should (where possible) obey the doc-string conventions
  23. ;; expected by make-docfile. They should also be added to the
  24. ;; uncompiled[] list in make-docfile.c.
  25. ;; ii) If the file is dumped with Emacs (on any platform), put the
  26. ;; load statement at the start of a line (leading whitespace is ok).
  27. ;; iii) If the file is _not_ dumped with Emacs, make sure the load
  28. ;; statement is _not_ at the start of a line. See pcase for an example.
  29. ;; These rules are so that src/Makefile can construct lisp.mk automatically.
  30. ;; This ensures both that the Lisp files are compiled (if necessary)
  31. ;; before the emacs executable is dumped, and that they are passed to
  32. ;; make-docfile. (Any that are not processed for DOC will not have
  33. ;; doc strings in the dumped Emacs.)
  34. ;;; Code:
  35. ;; This is used in xdisp.c to determine when bidi reordering is safe.
  36. ;; (It starts non-nil in temacs, but we set it non-nil here anyway, in
  37. ;; case someone loads loadup one more time.) We reset it after
  38. ;; successfully loading charprop.el, which defines the Unicode tables
  39. ;; bidi.c needs for its job.
  40. (setq redisplay--inhibit-bidi t)
  41. ;; Add subdirectories to the load-path for files that might get
  42. ;; autoloaded when bootstrapping.
  43. ;; This is because PATH_DUMPLOADSEARCH is just "../lisp".
  44. (if (or (equal (member "bootstrap" command-line-args) '("bootstrap"))
  45. ;; FIXME this is irritatingly fragile.
  46. (and (stringp (nth 4 command-line-args))
  47. (string-match "^unidata-gen\\(\\.elc?\\)?$"
  48. (nth 4 command-line-args)))
  49. (member (nth 7 command-line-args) '("unidata-gen-file"
  50. "unidata-gen-charprop"))
  51. (if (fboundp 'dump-emacs)
  52. (string-match "src/bootstrap-emacs" (nth 0 command-line-args))
  53. t))
  54. (let ((dir (car load-path)))
  55. ;; We'll probably overflow the pure space.
  56. (setq purify-flag nil)
  57. ;; Value of max-lisp-eval-depth when compiling initially.
  58. ;; During bootstrapping the byte-compiler is run interpreted when
  59. ;; compiling itself, which uses a lot more stack than usual.
  60. (setq max-lisp-eval-depth 2200)
  61. (setq load-path (list (expand-file-name "." dir)
  62. (expand-file-name "emacs-lisp" dir)
  63. (expand-file-name "language" dir)
  64. (expand-file-name "international" dir)
  65. (expand-file-name "textmodes" dir)
  66. (expand-file-name "vc" dir)))))
  67. (if (eq t purify-flag)
  68. ;; Hash consing saved around 11% of pure space in my tests.
  69. (setq purify-flag (make-hash-table :test 'equal :size 80000)))
  70. (message "Using load-path %s" load-path)
  71. ;; This is a poor man's `last', since we haven't loaded subr.el yet.
  72. (if (and (fboundp 'dump-emacs)
  73. (or (equal (member "bootstrap" command-line-args) '("bootstrap"))
  74. (equal (member "dump" command-line-args) '("dump"))))
  75. (progn
  76. ;; To reduce the size of dumped Emacs, we avoid making huge char-tables.
  77. (setq inhibit-load-charset-map t)
  78. ;; --eval gets handled too late.
  79. (defvar load--prefer-newer load-prefer-newer)
  80. (setq load-prefer-newer t)))
  81. ;; We don't want to have any undo records in the dumped Emacs.
  82. (set-buffer "*scratch*")
  83. (setq buffer-undo-list t)
  84. (load "emacs-lisp/byte-run")
  85. (load "emacs-lisp/backquote")
  86. (load "subr")
  87. ;; Do it after subr, since both after-load-functions and add-hook are
  88. ;; implemented in subr.el.
  89. (add-hook 'after-load-functions (lambda (f) (garbage-collect)))
  90. (load "version")
  91. (load "widget")
  92. (load "custom")
  93. (load "emacs-lisp/map-ynp")
  94. (load "international/mule")
  95. (load "international/mule-conf")
  96. (load "env")
  97. (load "format")
  98. (load "bindings")
  99. (load "window") ; Needed here for `replace-buffer-in-windows'.
  100. ;; We are now capable of resizing the mini-windows, so give the
  101. ;; variable its advertised default value (it starts as nil, see
  102. ;; xdisp.c).
  103. (setq resize-mini-windows 'grow-only)
  104. (setq load-source-file-function 'load-with-code-conversion)
  105. (load "files")
  106. ;; Load-time macro-expansion can only take effect after setting
  107. ;; load-source-file-function because of where it is called in lread.c.
  108. (load "emacs-lisp/macroexp")
  109. (if (byte-code-function-p (symbol-function 'macroexpand-all))
  110. nil
  111. ;; Since loaddefs is not yet loaded, macroexp's uses of pcase will simply
  112. ;; fail until pcase is explicitly loaded. This also means that we have to
  113. ;; disable eager macro-expansion while loading pcase.
  114. (let ((macroexp--pending-eager-loads '(skip))) (load "emacs-lisp/pcase"))
  115. ;; Re-load macroexp so as to eagerly macro-expand its uses of pcase.
  116. (let ((max-lisp-eval-depth (* 2 max-lisp-eval-depth)))
  117. (load "emacs-lisp/macroexp")))
  118. (load "cus-face")
  119. (load "faces") ; after here, `defface' may be used.
  120. (load "button")
  121. ;; We don't want to store loaddefs.el in the repository because it is
  122. ;; a generated file; but it is required in order to compile the lisp files.
  123. ;; When bootstrapping, we cannot generate loaddefs.el until an
  124. ;; emacs binary has been built. We therefore compromise and keep
  125. ;; ldefs-boot.el in the repository. This does not need to be updated
  126. ;; as often as the real loaddefs.el would. Bootstrap should always
  127. ;; work with ldefs-boot.el. Therefore, whenever a new autoload cookie
  128. ;; gets added that is necessary during bootstrapping, ldefs-boot.el
  129. ;; should be updated by overwriting it with an up-to-date copy of
  130. ;; loaddefs.el that is not corrupted by local changes.
  131. ;; admin/update_autogen can be used to update ldefs-boot.el periodically.
  132. (condition-case nil (load "loaddefs.el")
  133. ;; In case loaddefs hasn't been generated yet.
  134. (file-error (load "ldefs-boot.el")))
  135. (let ((new (make-hash-table :test 'equal)))
  136. ;; Now that loaddefs has populated definition-prefixes, purify its contents.
  137. (maphash (lambda (k v) (puthash (purecopy k) (purecopy v) new))
  138. definition-prefixes)
  139. (setq definition-prefixes new))
  140. (load "emacs-lisp/nadvice")
  141. (load "emacs-lisp/cl-preloaded")
  142. (load "minibuffer") ;After loaddefs, for define-minor-mode.
  143. (load "obarray") ;abbrev.el is implemented in terms of obarrays.
  144. (load "abbrev") ;lisp-mode.el and simple.el use define-abbrev-table.
  145. (load "simple")
  146. (load "help")
  147. (load "jka-cmpr-hook")
  148. (load "epa-hook")
  149. ;; Any Emacs Lisp source file (*.el) loaded here after can contain
  150. ;; multilingual text.
  151. (load "international/mule-cmds")
  152. (load "case-table")
  153. ;; This file doesn't exist when building a development version of Emacs
  154. ;; from the repository. It is generated just after temacs is built.
  155. (load "international/charprop.el" t)
  156. (if (featurep 'charprop)
  157. (setq redisplay--inhibit-bidi nil))
  158. (load "international/characters")
  159. (load "composite")
  160. ;; Load language-specific files.
  161. (load "language/chinese")
  162. (load "language/cyrillic")
  163. (load "language/indian")
  164. (load "language/sinhala")
  165. (load "language/english")
  166. (load "language/ethiopic")
  167. (load "language/european")
  168. (load "language/czech")
  169. (load "language/slovak")
  170. (load "language/romanian")
  171. (load "language/greek")
  172. (load "language/hebrew")
  173. (load "international/cp51932")
  174. (load "international/eucjp-ms")
  175. (load "language/japanese")
  176. (load "language/korean")
  177. (load "language/lao")
  178. (load "language/tai-viet")
  179. (load "language/thai")
  180. (load "language/tibetan")
  181. (load "language/vietnamese")
  182. (load "language/misc-lang")
  183. (load "language/utf-8-lang")
  184. (load "language/georgian")
  185. (load "language/khmer")
  186. (load "language/burmese")
  187. (load "language/cham")
  188. (load "indent")
  189. (load "emacs-lisp/cl-generic")
  190. (load "frame")
  191. (load "startup")
  192. (load "term/tty-colors")
  193. (load "font-core")
  194. ;; facemenu must be loaded before font-lock, because `facemenu-keymap'
  195. ;; needs to be defined when font-lock is loaded.
  196. (load "facemenu")
  197. (load "emacs-lisp/syntax")
  198. (load "font-lock")
  199. (load "jit-lock")
  200. (load "mouse")
  201. (if (boundp 'x-toolkit-scroll-bars)
  202. (load "scroll-bar"))
  203. (load "select")
  204. (load "emacs-lisp/timer")
  205. (load "isearch")
  206. (load "rfn-eshadow")
  207. (load "menu-bar")
  208. (load "emacs-lisp/lisp")
  209. (load "textmodes/page")
  210. (load "register")
  211. (load "textmodes/paragraphs")
  212. (load "progmodes/prog-mode")
  213. (load "emacs-lisp/lisp-mode")
  214. (load "progmodes/elisp-mode")
  215. (load "textmodes/text-mode")
  216. (load "textmodes/fill")
  217. (load "newcomment")
  218. (load "replace")
  219. (load "emacs-lisp/tabulated-list")
  220. (load "buff-menu")
  221. (if (fboundp 'x-create-frame)
  222. (progn
  223. (load "fringe")
  224. ;; Needed by `imagemagick-register-types'
  225. (load "emacs-lisp/regexp-opt")
  226. (load "image")
  227. (load "international/fontset")
  228. (load "dnd")
  229. (load "tool-bar")))
  230. (if (featurep 'dynamic-setting)
  231. (load "dynamic-setting"))
  232. (if (featurep 'x)
  233. (progn
  234. (load "x-dnd")
  235. (load "term/common-win")
  236. (load "term/x-win")))
  237. (if (or (eq system-type 'windows-nt)
  238. (featurep 'w32))
  239. (progn
  240. (load "term/common-win")
  241. (load "w32-vars")
  242. (load "term/w32-win")
  243. (load "disp-table")
  244. (when (eq system-type 'windows-nt)
  245. (load "w32-fns")
  246. (load "ls-lisp")
  247. (load "dos-w32"))))
  248. (if (eq system-type 'ms-dos)
  249. (progn
  250. (load "dos-w32")
  251. (load "dos-fns")
  252. (load "dos-vars")
  253. ;; Don't load term/common-win: it isn't appropriate for the `pc'
  254. ;; ``window system'', which generally behaves like a terminal.
  255. (load "term/internal")
  256. (load "term/pc-win")
  257. (load "ls-lisp")
  258. (load "disp-table"))) ; needed to setup ibm-pc char set, see internal.el
  259. (if (featurep 'ns)
  260. (progn
  261. (load "term/common-win")
  262. ;; Don't load ucs-normalize.el unless uni-*.el files were
  263. ;; already produced, because it needs uni-*.el files that might
  264. ;; not be built early enough during bootstrap.
  265. (when (featurep 'charprop)
  266. (load "international/mule-util")
  267. (load "international/ucs-normalize")
  268. (load "term/ns-win"))))
  269. (if (fboundp 'x-create-frame)
  270. ;; Do it after loading term/foo-win.el since the value of the
  271. ;; mouse-wheel-*-event vars depends on those files being loaded or not.
  272. (load "mwheel"))
  273. ;; Preload some constants and floating point functions.
  274. (load "emacs-lisp/float-sup")
  275. (load "vc/vc-hooks")
  276. (load "vc/ediff-hook")
  277. (load "uniquify")
  278. (load "electric")
  279. (load "emacs-lisp/eldoc")
  280. (load "cus-start") ;Late to reduce customize-rogue (needs loaddefs.el anyway)
  281. (if (not (eq system-type 'ms-dos))
  282. (load "tooltip"))
  283. ;; This file doesn't exist when building a development version of Emacs
  284. ;; from the repository. It is generated just after temacs is built.
  285. (load "leim/leim-list.el" t)
  286. ;; If you want additional libraries to be preloaded and their
  287. ;; doc strings kept in the DOC file rather than in core,
  288. ;; you may load them with a "site-load.el" file.
  289. ;; But you must also cause them to be scanned when the DOC file
  290. ;; is generated.
  291. (let ((lp load-path))
  292. (load "site-load" t)
  293. ;; We reset load-path after dumping.
  294. ;; For a permanent change in load-path, use configure's
  295. ;; --enable-locallisppath option.
  296. ;; See http://debbugs.gnu.org/16107 for more details.
  297. (or (equal lp load-path)
  298. (message "Warning: Change in load-path due to site-load will be \
  299. lost after dumping")))
  300. ;; Make sure default-directory is unibyte when dumping. This is
  301. ;; because we cannot decode and encode it correctly (since the locale
  302. ;; environment is not, and should not be, set up). default-directory
  303. ;; is used every time we call expand-file-name, which we do in every
  304. ;; file primitive. So the only workable solution to support building
  305. ;; in non-ASCII directories is to manipulate unibyte strings in the
  306. ;; current locale's encoding.
  307. (if (and (member (car (last command-line-args)) '("dump" "bootstrap"))
  308. (fboundp 'dump-emacs)
  309. (multibyte-string-p default-directory))
  310. (error "default-directory must be unibyte when dumping Emacs!"))
  311. ;; Determine which build number to use
  312. ;; based on the executables that now exist.
  313. (if (and (equal (last command-line-args) '("dump"))
  314. (fboundp 'dump-emacs)
  315. (not (eq system-type 'ms-dos)))
  316. (let* ((base (concat "emacs-" emacs-version "."))
  317. (exelen (if (eq system-type 'windows-nt) -4))
  318. (files (file-name-all-completions base default-directory))
  319. (versions (mapcar (function
  320. (lambda (name)
  321. (string-to-number
  322. (substring name (length base) exelen))))
  323. files)))
  324. (setq emacs-repository-version (condition-case nil (emacs-repository-get-version)
  325. (error nil)))
  326. ;; A constant, so we shouldn't change it with `setq'.
  327. (defconst emacs-build-number
  328. (if versions (1+ (apply 'max versions)) 1))))
  329. (message "Finding pointers to doc strings...")
  330. (if (and (fboundp 'dump-emacs)
  331. (equal (last command-line-args) '("dump")))
  332. (Snarf-documentation "DOC")
  333. (condition-case nil
  334. (Snarf-documentation "DOC")
  335. (error nil)))
  336. (message "Finding pointers to doc strings...done")
  337. ;; Note: You can cause additional libraries to be preloaded
  338. ;; by writing a site-init.el that loads them.
  339. ;; See also "site-load" above
  340. (let ((lp load-path))
  341. (load "site-init" t)
  342. (or (equal lp load-path)
  343. (message "Warning: Change in load-path due to site-init will be \
  344. lost after dumping")))
  345. (setq current-load-list nil)
  346. ;; Avoid storing references to build directory in the binary.
  347. (setq custom-current-group-alist nil)
  348. ;; We keep the load-history data in PURE space.
  349. ;; Make sure that the spine of the list is not in pure space because it can
  350. ;; be destructively mutated in lread.c:build_load_history.
  351. (setq load-history (mapcar 'purecopy load-history))
  352. (set-buffer-modified-p nil)
  353. (remove-hook 'after-load-functions (lambda (f) (garbage-collect)))
  354. (if (boundp 'load--prefer-newer)
  355. (progn
  356. (setq load-prefer-newer load--prefer-newer)
  357. (put 'load-prefer-newer 'standard-value load--prefer-newer)
  358. (makunbound 'load--prefer-newer)))
  359. (setq inhibit-load-charset-map nil)
  360. (clear-charset-maps)
  361. (garbage-collect)
  362. ;; At this point, we're ready to resume undo recording for scratch.
  363. (buffer-enable-undo "*scratch*")
  364. (when (hash-table-p purify-flag)
  365. (let ((strings 0)
  366. (vectors 0)
  367. (bytecodes 0)
  368. (conses 0)
  369. (others 0))
  370. (maphash (lambda (k v)
  371. (cond
  372. ((stringp k) (setq strings (1+ strings)))
  373. ((vectorp k) (setq vectors (1+ vectors)))
  374. ((consp k) (setq conses (1+ conses)))
  375. ((byte-code-function-p v) (setq bytecodes (1+ bytecodes)))
  376. (t (setq others (1+ others)))))
  377. purify-flag)
  378. (message "Pure-hashed: %d strings, %d vectors, %d conses, %d bytecodes, %d others"
  379. strings vectors conses bytecodes others)))
  380. ;; Avoid error if user loads some more libraries now and make sure the
  381. ;; hash-consing hash table is GC'd.
  382. (setq purify-flag nil)
  383. (if (null (garbage-collect))
  384. (setq pure-space-overflow t))
  385. ;; Make sure we will attempt bidi reordering henceforth.
  386. (setq redisplay--inhibit-bidi nil)
  387. (if (and (fboundp 'dump-emacs)
  388. (member (car (last command-line-args)) '("dump" "bootstrap")))
  389. (progn
  390. ;; Prevent build-time PATH getting stored in the binary.
  391. ;; Mainly cosmetic, but helpful for Guix. (Bug#20330)
  392. ;; Do this here, rather than earlier, so that the above code
  393. ;; can invoke Git commands and the like.
  394. (setq exec-path nil)
  395. (message "Dumping under the name emacs")
  396. (condition-case ()
  397. (delete-file "emacs")
  398. (file-error nil))
  399. ;; We used to dump under the name xemacs, but that occasionally
  400. ;; confused people installing Emacs (they'd install the file
  401. ;; under the name `xemacs'), and it's inconsistent with every
  402. ;; other GNU program's build process.
  403. (dump-emacs "emacs" "temacs")
  404. (message "%d pure bytes used" pure-bytes-used)
  405. ;; Recompute NAME now, so that it isn't set when we dump.
  406. (if (not (or (eq system-type 'ms-dos)
  407. ;; Don't bother adding another name if we're just
  408. ;; building bootstrap-emacs.
  409. (equal (last command-line-args) '("bootstrap"))))
  410. (let ((name (format "emacs-%s.%d" emacs-version emacs-build-number))
  411. (exe (if (eq system-type 'windows-nt) ".exe" "")))
  412. (while (string-match "[^-+_.a-zA-Z0-9]+" name)
  413. (setq name (concat (downcase (substring name 0 (match-beginning 0)))
  414. "-"
  415. (substring name (match-end 0)))))
  416. (setq name (concat name exe))
  417. (message "Adding name %s" name)
  418. ;; When this runs on Windows, invocation-directory is not
  419. ;; necessarily the current directory.
  420. (add-name-to-file (expand-file-name (concat "emacs" exe)
  421. invocation-directory)
  422. (expand-file-name name invocation-directory)
  423. t)))
  424. (kill-emacs)))
  425. ;; For machines with CANNOT_DUMP defined in config.h,
  426. ;; this file must be loaded each time Emacs is run.
  427. ;; So run the startup code now. First, remove `-l loadup' from args.
  428. (if (and (member (nth 1 command-line-args) '("-l" "--load"))
  429. (equal (nth 2 command-line-args) "loadup"))
  430. (setcdr command-line-args (nthcdr 3 command-line-args)))
  431. (eval top-level)
  432. ;; Local Variables:
  433. ;; no-byte-compile: t
  434. ;; no-update-autoloads: t
  435. ;; End:
  436. ;;; loadup.el ends here