Record autoloads till emacs dump
[emacs.git] / admin / ldefs-clean.el
blobc227a163604d58c8c4923fccb50d35dc962765b2
1 ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 ;; This file is part of GNU Emacs.
5 ;; GNU Emacs is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
18 ;;; Commentary:
20 ;; This file takes the output from the "generate-ldefs-boot" make
21 ;; target, takes the relevant autoload forms, removes everything else
22 ;; and adds some comments.
24 (defun ldefs-clean-uniquify-region-lines (beg end)
25 "Remove duplicate adjacent lines in region."
26 (save-excursion
27 (goto-char beg)
28 (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
29 (replace-match "\\1"))))
31 (defun ldefs-clean-uniquify-buffer-lines ()
32 "Remove duplicate adjacent lines in the current buffer."
33 (interactive)
34 (ldefs-clean-uniquify-region-lines (point-min) (point-max)))
36 (defun ldefs-clean-up ()
37 "Clean up output from build and turn it into ldefs-boot-auto.el."
38 (interactive)
39 (goto-char (point-max))
40 ;; We need to record autoloads till the point that emacs (as opposed
41 ;; to bootstrap-emacs) is dumped. After this point, we are not
42 ;; bootstrapping any more.
43 (search-backward "-l loadup dump")
44 (beginning-of-line)
45 (delete-region (point) (point-max))
46 (keep-lines "(autoload" (point-min) (point-max))
47 (sort-lines nil (point-min) (point-max))
48 (ldefs-clean-uniquify-buffer-lines)
49 (goto-char (point-min))
50 (insert
51 ";; This file is autogenerated by admin/ldefs-clean.el
52 ;; Do not edit
54 (goto-char (point-max))
55 (insert
56 ";; Local Variables:
57 ;; no-byte-compile: t
58 ;; no-update-autoloads: t
59 ;; End:"))
62 (defun ldefs-clean ()
63 (find-file "lisp/ldefs-boot-auto.temp")
64 (ldefs-clean-up)
65 (write-file "ldefs-boot-auto.el"))