loadup.el 16 KB

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