loadup.el 12 KB

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