; * lisp/ldefs-boot.el: Update.
[emacs.git] / admin / admin.el
blobd7de42e07823306c093c40eeafed5307fc1b0b62
1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001-2019 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (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.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
20 ;;; Commentary:
22 ;; add-release-logs Add ``Version X released'' change log entries.
23 ;; set-version Change Emacs version number in source tree.
24 ;; set-copyright Change Emacs short copyright string (eg as
25 ;; printed by --version) in source tree.
27 ;;; Code:
29 (defvar add-log-time-format) ; in add-log
31 (defun add-release-logs (root version &optional date)
32 "Add \"Version VERSION released.\" change log entries in ROOT.
33 Also update the etc/HISTORY file.
34 Root must be the root of an Emacs source tree.
35 Optional argument DATE is the release date, default today."
36 (interactive (list (read-directory-name "Emacs root directory: ")
37 (read-string "Version number: "
38 (format "%s.%s" emacs-major-version
39 emacs-minor-version))
40 (read-string "Release date: "
41 (progn (require 'add-log)
42 (funcall add-log-time-format nil t)))))
43 (setq root (expand-file-name root))
44 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
45 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
46 (let ((clog (expand-file-name "ChangeLog" root)))
47 (if (file-exists-p clog)
48 ;; Basic check that a ChangeLog that exists is not your personal one.
49 ;; TODO Perhaps we should move any existing file and unconditionally
50 ;; call make ChangeLog? Or make ChangeLog CHANGELOG=temp and compare
51 ;; with the existing?
52 (with-temp-buffer
53 (insert-file-contents clog)
54 (or (re-search-forward "^[ \t]*Copyright.*Free Software" nil t)
55 (user-error "ChangeLog looks like a personal one - remove it?")))
56 (or
57 (zerop (call-process "make" nil nil nil "-C" root "ChangeLog"))
58 (error "Problem generating ChangeLog"))))
59 (require 'add-log)
60 (or date (setq date (funcall add-log-time-format nil t)))
61 (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
62 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
63 date
64 (or add-log-full-name (user-full-name))
65 (or add-log-mailing-address user-mail-address)
66 version)))
67 (dolist (log logs)
68 (find-file log)
69 (goto-char (point-min))
70 (insert entry)))
71 (let ((histfile (expand-file-name "etc/HISTORY" root)))
72 (unless (file-exists-p histfile)
73 (error "%s not present" histfile))
74 (find-file histfile)
75 (goto-char (point-max))
76 (search-backward "\f")
77 (insert (format "GNU Emacs %s (%s) emacs-%s\n\n" version date version))))
79 (defun set-version-in-file (root file version rx)
80 "Subroutine of `set-version' and `set-copyright'."
81 (find-file (expand-file-name file root))
82 (goto-char (point-min))
83 (setq version (format "%s" version))
84 (unless (re-search-forward rx nil :noerror)
85 (user-error "Version not found in %s" file))
86 (if (not (equal version (match-string 1)))
87 (replace-match version nil nil nil 1)
88 (kill-buffer)
89 (message "No need to update `%s'" file)))
91 (defun set-version (root version)
92 "Set Emacs version to VERSION in relevant files under ROOT.
93 Root must be the root of an Emacs source tree."
94 (interactive (list
95 (read-directory-name "Emacs root directory: " source-directory)
96 (read-string "Version number: " emacs-version)))
97 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
98 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
99 (message "Setting version numbers...")
100 ;; There's also a "version 3" (standing for GPLv3) at the end of
101 ;; `README', but since `set-version-in-file' only replaces the first
102 ;; occurrence, it won't be replaced.
103 (set-version-in-file root "README" version
104 (rx (and "version" (1+ space)
105 (submatch (1+ (in "0-9."))))))
106 (set-version-in-file root "configure.ac" version
107 (rx (and "AC_INIT" (1+ (not (in ?,)))
108 ?, (0+ space)
109 (submatch (1+ (in "0-9."))))))
110 (set-version-in-file root "nt/README.W32" version
111 (rx (and "version" (1+ space)
112 (submatch (1+ (in "0-9."))))))
113 ;; TODO: msdos could easily extract the version number from
114 ;; configure.ac with sed, rather than duplicating the information.
115 (set-version-in-file root "msdos/sed2v2.inp" version
116 (rx (and bol "/^#undef " (1+ not-newline)
117 "define PACKAGE_VERSION" (1+ space) "\""
118 (submatch (1+ (in "0-9."))))))
119 ;; Major version only.
120 (when (string-match "\\([0-9]\\{2,\\}\\)" version)
121 (let ((newmajor (match-string 1 version)))
122 (set-version-in-file root "src/msdos.c" newmajor
123 (rx (and "Vwindow_system_version" (1+ not-newline)
124 ?\( (submatch (1+ (in "0-9"))) ?\))))
125 (set-version-in-file root "etc/refcards/ru-refcard.tex" newmajor
126 "\\\\newcommand{\\\\versionemacs}\\[0\\]\
127 {\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs")))
128 (let* ((oldversion
129 (with-temp-buffer
130 (insert-file-contents (expand-file-name "README" root))
131 (if (re-search-forward "version \\([0-9.]*\\)" nil t)
132 (version-to-list (match-string 1)))))
133 (oldmajor (if oldversion (car oldversion)))
134 (newversion (version-to-list version))
135 (newmajor (car newversion))
136 (newshort (format "%s.%s" newmajor
137 (+ (cadr newversion)
138 (if (eq 2 (length newversion)) 0 1))))
139 (majorbump (and oldversion (not (equal oldmajor newmajor))))
140 (minorbump (and oldversion (not majorbump)
141 (or (not (equal (cadr oldversion) (cadr newversion)))
142 ;; Eg 26.2 -> 26.2.50.
143 (and (> (length newversion)
144 (length oldversion))))))
145 (newsfile (expand-file-name "etc/NEWS" root))
146 (oldnewsfile (expand-file-name (format "etc/NEWS.%s" oldmajor) root)))
147 (unless (> (length newversion) 2) ; pretest or release candidate?
148 (with-temp-buffer
149 (insert-file-contents newsfile)
150 (if (re-search-forward "^\\(+++ *\\|--- *\\)$" nil t)
151 (display-warning 'admin
152 "NEWS file still contains temporary markup.
153 Documentation changes might not have been completed!"))))
154 (when (and majorbump
155 (not (file-exists-p oldnewsfile)))
156 (rename-file newsfile oldnewsfile)
157 (find-file oldnewsfile) ; to prompt you to commit it
158 (copy-file oldnewsfile newsfile)
159 (with-temp-buffer
160 (insert-file-contents newsfile)
161 (re-search-forward "is about changes in Emacs version \\([0-9]+\\)")
162 (replace-match (number-to-string newmajor) nil nil nil 1)
163 (re-search-forward "^See files \\(NEWS\\)")
164 (unless (save-match-data
165 (when (looking-at "\\(\\..*\\), \\(\\.\\.\\.\\|…\\)")
166 (replace-match
167 (format ".%s, NEWS.%s" oldmajor (1- oldmajor))
168 nil nil nil 1)
170 (replace-match (format "NEWS.%s, NEWS" oldmajor) nil nil nil 1)
171 (let ((start (line-beginning-position)))
172 (search-forward "in older Emacs versions")
173 (or (equal start (line-beginning-position))
174 (fill-region start (line-beginning-position 2)))))
175 (re-search-forward "^\f$")
176 (forward-line -1)
177 (let ((start (point)))
178 (goto-char (point-max))
179 (re-search-backward "^\f$" nil nil 2)
180 (delete-region start (line-beginning-position 0)))
181 (write-region nil nil newsfile)))
182 (when (or majorbump minorbump)
183 (find-file newsfile)
184 (goto-char (point-min))
185 (if (re-search-forward (format "^\\* .*in Emacs %s" newshort) nil t)
186 (progn
187 (kill-buffer)
188 (message "No need to update etc/NEWS"))
189 (goto-char (point-min))
190 (re-search-forward "^\f$")
191 (forward-line -1)
192 (dolist (s '("Installation Changes" "Startup Changes" "Changes"
193 "Editing Changes"
194 "Changes in Specialized Modes and Packages"
195 "New Modes and Packages"
196 "Incompatible Lisp Changes"
197 "Lisp Changes"))
198 (insert (format "\n\f\n* %s in Emacs %s\n" s newshort)))
199 (insert (format "\n\f\n* Changes in Emacs %s on \
200 Non-Free Operating Systems\n" newshort)))
201 ;; Because we skip "bump version" commits when merging between branches.
202 ;; Probably doesn't matter in practice, because NEWS changes
203 ;; will only happen on master anyway.
204 (message "Commit any NEWS changes separately")))
205 (message "Setting version numbers...done"))
207 ;; Note this makes some assumptions about form of short copyright.
208 (defun set-copyright (root copyright)
209 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
210 Root must be the root of an Emacs source tree."
211 (interactive (list
212 (read-directory-name "Emacs root directory: " nil nil t)
213 (read-string
214 "Short copyright string: "
215 (format "Copyright (C) %s Free Software Foundation, Inc."
216 (format-time-string "%Y")))))
217 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
218 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
219 (message "Setting copyrights...")
220 (set-version-in-file root "configure.ac" copyright
221 (rx (and bol "copyright" (0+ (not (in ?\")))
222 ?\" (submatch (1+ (not (in ?\")))) ?\")))
223 (set-version-in-file root "msdos/sed2v2.inp" copyright
224 (rx (and bol "/^#undef " (1+ not-newline)
225 "define COPYRIGHT" (1+ space)
226 ?\" (submatch (1+ (not (in ?\")))) ?\")))
227 (set-version-in-file root "lib-src/rcs2log" copyright
228 (rx (and "Copyright" (0+ space) ?= (0+ space)
229 ?\' (submatch (1+ nonl)))))
230 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
231 (setq copyright (match-string 1 copyright))
232 (set-version-in-file root "etc/refcards/ru-refcard.tex" copyright
233 "\\\\newcommand{\\\\cyear}\\[0\\]\
234 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")
235 (set-version-in-file root "etc/refcards/emacsver.tex.in" copyright
236 "\\\\def\\\\year\
237 {\\([0-9]\\{4\\}\\)}.+%.+copyright year"))
238 (message "Setting copyrights...done"))
240 ;;; Various bits of magic for generating the web manuals
242 (defun manual-misc-manuals (root)
243 "Return doc/misc manuals as list of strings.
244 ROOT should be the root of an Emacs source tree."
245 ;; Similar to `make -C doc/misc echo-info', but works if unconfigured,
246 ;; and for INFO_TARGETS rather than INFO_INSTALL.
247 (with-temp-buffer
248 (insert-file-contents (expand-file-name "doc/misc/Makefile.in" root))
249 ;; Should really use expanded value of INFO_TARGETS.
250 (search-forward "INFO_COMMON = ")
251 (let ((start (point)))
252 (end-of-line)
253 (while (and (looking-back "\\\\")
254 (zerop (forward-line 1)))
255 (end-of-line))
256 (append (split-string (replace-regexp-in-string
257 "\\(\\\\\\|\\.info\\)" ""
258 (buffer-substring start (point))))
259 '("efaq-w32")))))
261 ;; TODO report the progress
262 (defun make-manuals (root &optional type)
263 "Generate the web manuals for the Emacs webpage.
264 ROOT should be the root of an Emacs source tree.
265 Interactively with a prefix argument, prompt for TYPE.
266 Optional argument TYPE is type of output (nil means all)."
267 (interactive (let ((root
268 (if noninteractive
269 (or (pop command-line-args-left)
270 default-directory)
271 (read-directory-name "Emacs root directory: "
272 source-directory nil t))))
273 (list root
274 (if current-prefix-arg
275 (completing-read
276 "Type: "
277 (append
278 '("misc" "pdf" "ps")
279 (let (res)
280 (dolist (i '("emacs" "elisp" "eintr") res)
281 (dolist (j '("" "-mono" "-node" "-ps" "-pdf"))
282 (push (concat i j) res))))
283 (manual-misc-manuals root)))))))
284 (let* ((dest (expand-file-name "manual" root))
285 (html-node-dir (expand-file-name "html_node" dest))
286 (html-mono-dir (expand-file-name "html_mono" dest))
287 (ps-dir (expand-file-name "ps" dest))
288 (pdf-dir (expand-file-name "pdf" dest))
289 (emacs (expand-file-name "doc/emacs/emacs.texi" root))
290 (emacs-xtra (expand-file-name "doc/emacs/emacs-xtra.texi" root))
291 (elisp (expand-file-name "doc/lispref/elisp.texi" root))
292 (eintr (expand-file-name "doc/lispintro/emacs-lisp-intro.texi" root))
293 (misc (manual-misc-manuals root)))
294 ;; TODO this makes it non-continuable.
295 ;; Instead, delete the individual dest directory each time.
296 (when (file-directory-p dest)
297 (if (y-or-n-p (format "Directory %s exists, delete it first? " dest))
298 (delete-directory dest t)
299 (user-error "Aborted")))
300 (if (member type '(nil "emacs" "emacs-node"))
301 (manual-html-node emacs (expand-file-name "emacs" html-node-dir)))
302 (if (member type '(nil "emacs" "emacs-mono"))
303 (manual-html-mono emacs (expand-file-name "emacs.html" html-mono-dir)))
304 (when (member type '(nil "emacs" "emacs-pdf" "pdf"))
305 (manual-pdf emacs (expand-file-name "emacs.pdf" pdf-dir))
306 ;; emacs-xtra exists only in pdf/ps format.
307 ;; In other formats it is included in the Emacs manual.
308 (manual-pdf emacs-xtra (expand-file-name "emacs-xtra.pdf" pdf-dir)))
309 (when (member type '(nil "emacs" "emacs-ps" "ps"))
310 (manual-ps emacs (expand-file-name "emacs.ps" ps-dir))
311 (manual-ps emacs-xtra (expand-file-name "emacs-xtra.ps" ps-dir)))
312 (if (member type '(nil "elisp" "elisp-node"))
313 (manual-html-node elisp (expand-file-name "elisp" html-node-dir)))
314 (if (member type '(nil "elisp" "elisp-mono"))
315 (manual-html-mono elisp (expand-file-name "elisp.html" html-mono-dir)))
316 (if (member type '(nil "elisp" "elisp-pdf" "pdf"))
317 (manual-pdf elisp (expand-file-name "elisp.pdf" pdf-dir)))
318 (if (member type '(nil "elisp" "elisp-ps" "ps"))
319 (manual-ps elisp (expand-file-name "elisp.ps" ps-dir)))
320 (if (member type '(nil "eintr" "eintr-node"))
321 (manual-html-node eintr (expand-file-name "eintr" html-node-dir)))
322 (if (member type '(nil "eintr" "eintr-node"))
323 (manual-html-mono eintr (expand-file-name "eintr.html" html-mono-dir)))
324 (if (member type '(nil "eintr" "eintr-pdf" "pdf"))
325 (manual-pdf eintr (expand-file-name "eintr.pdf" pdf-dir)))
326 (if (member type '(nil "eintr" "eintr-ps" "ps"))
327 (manual-ps eintr (expand-file-name "eintr.ps" ps-dir)))
328 ;; Misc manuals
329 (dolist (manual misc)
330 (if (member type `(nil ,manual "misc"))
331 (manual-misc-html manual root html-node-dir html-mono-dir)))
332 (message "Manuals created in %s" dest)))
334 (defconst manual-doctype-string
335 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
336 \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
338 (defconst manual-meta-string
339 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
340 <link rev=\"made\" href=\"mailto:bug-gnu-emacs@gnu.org\">
341 <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
342 <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
343 <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
345 (defconst manual-style-string "<style type=\"text/css\">
346 @import url('/software/emacs/manual.css');\n</style>\n")
348 (defun manual-misc-html (name root html-node-dir html-mono-dir)
349 ;; Hack to deal with the cases where .texi creates a different .info.
350 ;; Blech. TODO Why not just rename the .texi (or .info) files?
351 (let* ((texiname (cond ((equal name "ccmode") "cc-mode")
352 (t name)))
353 (texi (expand-file-name (format "doc/misc/%s.texi" texiname) root)))
354 (manual-html-node texi (expand-file-name name html-node-dir))
355 (manual-html-mono texi (expand-file-name (concat name ".html")
356 html-mono-dir))))
358 (defvar manual-makeinfo (or (getenv "MAKEINFO") "makeinfo")
359 "The `makeinfo' program to use.")
361 (defvar manual-texi2pdf (or (getenv "TEXI2PDF") "texi2pdf")
362 "The `texi2pdf' program to use.")
364 (defvar manual-texi2dvi (or (getenv "TEXI2DVI") "texi2dvi")
365 "The `texi2dvi' program to use.")
367 (defun manual-html-mono (texi-file dest)
368 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
369 This function also edits the HTML files so that they validate as
370 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
371 the @import directive."
372 (make-directory (or (file-name-directory dest) ".") t)
373 (call-process manual-makeinfo nil nil nil
374 "-D" "WWW_GNU_ORG"
375 "-I" (expand-file-name "../emacs"
376 (file-name-directory texi-file))
377 "-I" (expand-file-name "../misc"
378 (file-name-directory texi-file))
379 "--html" "--no-split" texi-file "-o" dest)
380 (with-temp-buffer
381 (insert-file-contents dest)
382 (setq buffer-file-name dest)
383 (manual-html-fix-headers)
384 (manual-html-fix-index-1)
385 (manual-html-fix-index-2 t)
386 (manual-html-fix-node-div)
387 (goto-char (point-max))
388 (re-search-backward "</body>[\n \t]*</html>")
389 ;; Close the div id="content" that fix-index-1 added.
390 (insert "</div>\n\n")
391 (save-buffer)))
393 (defun manual-html-node (texi-file dir)
394 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
395 This function also edits the HTML files so that they validate as
396 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
397 the @import directive."
398 (unless (file-exists-p texi-file)
399 (user-error "Manual file %s not found" texi-file))
400 (make-directory dir t)
401 (call-process manual-makeinfo nil nil nil
402 "-D" "WWW_GNU_ORG"
403 "-I" (expand-file-name "../emacs"
404 (file-name-directory texi-file))
405 "-I" (expand-file-name "../misc"
406 (file-name-directory texi-file))
407 "--html" texi-file "-o" dir)
408 ;; Loop through the node files, fixing them up.
409 (dolist (f (directory-files dir nil "\\.html\\'"))
410 (let (opoint)
411 (with-temp-buffer
412 (insert-file-contents (expand-file-name f dir))
413 (setq buffer-file-name (expand-file-name f dir))
414 (if (looking-at "<meta http-equiv")
415 ;; Ignore those HTML files that are just redirects.
416 (set-buffer-modified-p nil)
417 (manual-html-fix-headers)
418 (if (equal f "index.html")
419 (let (copyright-text)
420 (manual-html-fix-index-1)
421 ;; Move copyright notice to the end.
422 (when (re-search-forward "[ \t]*<p>Copyright &copy;" nil t)
423 (setq opoint (match-beginning 0))
424 (re-search-forward "</blockquote>")
425 (setq copyright-text (buffer-substring opoint (point)))
426 (delete-region opoint (point)))
427 (manual-html-fix-index-2)
428 (if copyright-text
429 (insert copyright-text))
430 ;; Close the div id="content" that fix-index-1 added.
431 (insert "\n</div>\n"))
432 ;; For normal nodes, give the header div a blue bg.
433 (manual-html-fix-node-div t))
434 (save-buffer))))))
436 (defun manual-pdf (texi-file dest)
437 "Run texi2pdf on TEXI-FILE, emitting PDF output to DEST."
438 (make-directory (or (file-name-directory dest) ".") t)
439 (let ((default-directory (file-name-directory texi-file)))
440 (call-process manual-texi2pdf nil nil nil
441 "-I" "../emacs" "-I" "../misc"
442 texi-file "-o" dest)))
444 (defun manual-ps (texi-file dest)
445 "Generate a PostScript version of TEXI-FILE as DEST."
446 (make-directory (or (file-name-directory dest) ".") t)
447 (let ((dvi-dest (concat (file-name-sans-extension dest) ".dvi"))
448 (default-directory (file-name-directory texi-file)))
449 ;; FIXME: Use `texi2dvi --ps'? --xfq
450 (call-process manual-texi2dvi nil nil nil
451 "-I" "../emacs" "-I" "../misc"
452 texi-file "-o" dvi-dest)
453 (call-process "dvips" nil nil nil dvi-dest "-o" dest)
454 (delete-file dvi-dest)
455 (call-process "gzip" nil nil nil dest)))
457 (defun manual-html-fix-headers ()
458 "Fix up HTML headers for the Emacs manual in the current buffer."
459 (let ((texi5 (search-forward "<!DOCTYPE" nil t))
460 opoint)
461 ;; Texinfo 5 supplies a DOCTYPE.
462 (or texi5
463 (insert manual-doctype-string))
464 (search-forward "<head>\n")
465 (insert manual-meta-string)
466 (search-forward "<meta")
467 (setq opoint (match-beginning 0))
468 (unless texi5
469 (search-forward "<!--")
470 (goto-char (match-beginning 0))
471 (delete-region opoint (point))
472 (search-forward "<meta http-equiv=\"Content-Style")
473 (setq opoint (match-beginning 0)))
474 (search-forward "</head>")
475 (goto-char (match-beginning 0))
476 (delete-region opoint (point))
477 (insert manual-style-string)
478 ;; Remove Texinfo 5 hard-coding bgcolor, text, link, vlink, alink.
479 (when (re-search-forward "<body lang=\"[^\"]+\"" nil t)
480 (setq opoint (point))
481 (search-forward ">")
482 (if (> (point) (1+ opoint))
483 (delete-region opoint (1- (point))))
484 (search-backward "</head"))))
486 ;; Texinfo 5 changed these from class = "node" to "header", yay.
487 (defun manual-html-fix-node-div (&optional split)
488 "Fix up HTML \"node\" divs in the current buffer."
489 (let (opoint div-end type)
490 (while (re-search-forward "<div class=\"\\(node\\|header\\)\"\\(>\\)" nil t)
491 (setq type (match-string 1))
492 ;; NB it is this that makes the bg of non-header cells in the
493 ;; index tables be blue. Is that intended?
494 ;; Also, if you don't remove the <hr>, the color of the first
495 ;; row in the table will be wrong.
496 ;; This all seems rather odd to me...
497 (replace-match " style=\"background-color:#DDDDFF\">" t t nil 2)
498 (setq opoint (point))
499 (when (or split (equal type "node"))
500 ;; In Texinfo 4, the <hr> (and anchor) comes after the <div>.
501 (re-search-forward "</div>")
502 (setq div-end (if (equal type "node")
503 (match-beginning 0)
504 (line-end-position 2)))
505 (goto-char opoint)
506 (if (search-forward "<hr>" div-end 'move)
507 (replace-match "" t t)
508 (if split (forward-line -1))))
509 ;; In Texinfo 5, the <hr> (and anchor) comes before the <div> (?).
510 ;; Except in split output, where it comes on the line after
511 ;; the <div>. But only sometimes. I have no clue what the
512 ;; logic of where it goes is.
513 (when (equal type "header")
514 (goto-char opoint)
515 (when (re-search-backward "^<hr>$" (line-beginning-position -3) t)
516 (replace-match "")
517 (goto-char opoint))))))
520 (defun manual-html-fix-index-1 ()
521 "Remove the h1 header, and the short and long contents lists.
522 Also start a \"content\" div."
523 (let (opoint)
524 (re-search-forward "<body.*>\n")
525 (setq opoint (match-end 0))
526 ;; FIXME? Fragile if a Texinfo 5 document does not use @top.
527 (or (re-search-forward "<h1 class=\"top\"" nil t) ; Texinfo 5
528 (search-forward "<h2 class=\""))
529 (goto-char (match-beginning 0))
530 (delete-region opoint (point))
531 ;; NB caller must close this div.
532 (insert "<div id=\"content\" class=\"inner\">\n\n")))
534 (defun manual-html-fix-index-2 (&optional table-workaround)
535 "Replace the index list in the current buffer with a HTML table.
536 Leave point after the table."
537 (if (re-search-forward "<table class=\"menu\"\\(.*\\)>" nil t)
538 ;; Texinfo 5 already uses a table. Tweak it a bit.
539 (let (opoint done)
540 (replace-match " style=\"float:left\" width=\"100%\"" nil t nil 1)
541 (forward-line 1)
542 (while (not done)
543 (cond ((re-search-forward "<tr><td.*&bull; \\(<a.*</a>\\)\
544 :</td><td>&nbsp;&nbsp;</td><td[^>]*>\\(.*\\)" (line-end-position) t)
545 (replace-match (format "<tr><td%s>\\1</td>\n<td>\\2"
546 (if table-workaround
547 " bgcolor=\"white\"" "")))
548 (search-forward "</td></tr>")
549 (forward-line 1))
550 ((looking-at "<tr><th.*<pre class=\"menu-comment\">\n")
551 (replace-match "<tr><th colspan=\"2\" align=\"left\" \
552 style=\"text-align:left\">")
553 (search-forward "</pre></th></tr>")
554 (replace-match "</th></tr>\n"))
555 ;; Not all manuals have the detailed menu.
556 ;; If it is there, split it into a separate table.
557 ((re-search-forward "<tr>.*The Detailed Node Listing *"
558 (line-end-position) t)
559 (setq opoint (match-beginning 0))
560 (while (and (looking-at " *&mdash;")
561 (zerop (forward-line 1))))
562 (delete-region opoint (point))
563 (insert "</table>\n\n\
564 <h2>Detailed Node Listing</h2>\n\n<p>")
565 ;; FIXME Fragile!
566 ;; The Emacs and Elisp manual have some text at the
567 ;; start of the detailed menu that is not part of the menu.
568 ;; Other manuals do not.
569 (if (re-search-forward "in one step:" (line-end-position 3) t)
570 (forward-line 1))
571 (insert "</p>\n")
572 (search-forward "</pre></th></tr>")
573 (delete-region (match-beginning 0) (match-end 0))
574 (forward-line -1)
575 (or (looking-at "^$") (error "Parse error 1"))
576 (forward-line -1)
577 (if (looking-at "^$") (error "Parse error 2"))
578 (forward-line -1)
579 (or (looking-at "^$") (error "Parse error 3"))
580 (forward-line 1)
581 (insert "<table class=\"menu\" style=\"float:left\" width=\"100%\">\n\
582 <tr><th colspan=\"2\" align=\"left\" style=\"text-align:left\">\n")
583 (forward-line 1)
584 (insert "</th></tr>")
585 (forward-line 1))
586 ((looking-at ".*</table")
587 (forward-line 1)
588 (setq done t)))))
589 (let (done open-td tag desc)
590 ;; Convert the list that Makeinfo made into a table.
591 (or (search-forward "<ul class=\"menu\">" nil t)
592 ;; FIXME? The following search seems dangerously lax.
593 (search-forward "<ul>"))
594 (replace-match "<table style=\"float:left\" width=\"100%\">")
595 (forward-line 1)
596 (while (not done)
597 (cond
598 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
599 (looking-at "<li>\\(<a.+</a>\\)$"))
600 (setq tag (match-string 1))
601 (setq desc (match-string 2))
602 (replace-match "" t t)
603 (when open-td
604 (save-excursion
605 (forward-char -1)
606 (skip-chars-backward " ")
607 (delete-region (point) (line-end-position))
608 (insert "</td>\n </tr>")))
609 (insert " <tr>\n ")
610 (if table-workaround
611 ;; This works around a Firefox bug in the mono file.
612 (insert "<td bgcolor=\"white\">")
613 (insert "<td>"))
614 (insert tag "</td>\n <td>" (or desc ""))
615 (setq open-td t))
616 ((eq (char-after) ?\n)
617 (delete-char 1)
618 ;; Negate the following `forward-line'.
619 (forward-line -1))
620 ((looking-at "<!-- ")
621 (search-forward "-->"))
622 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
623 (replace-match " </td></tr></table>\n
624 <h3>Detailed Node Listing</h3>\n\n" t t)
625 (search-forward "<p>")
626 ;; FIXME Fragile!
627 ;; The Emacs and Elisp manual have some text at the
628 ;; start of the detailed menu that is not part of the menu.
629 ;; Other manuals do not.
630 (if (looking-at "Here are some other nodes")
631 (search-forward "<p>"))
632 (goto-char (match-beginning 0))
633 (skip-chars-backward "\n ")
634 (setq open-td nil)
635 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
636 ((looking-at "</li></ul>")
637 (replace-match "" t t))
638 ((looking-at "<p>")
639 (replace-match "" t t)
640 (when open-td
641 (insert " </td></tr>")
642 (setq open-td nil))
643 (insert " <tr>
644 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
645 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t)
646 (replace-match " </th></tr>")))
647 ((looking-at "[ \t]*</ul>[ \t]*$")
648 (replace-match
649 (if open-td
650 " </td></tr>\n</table>"
651 "</table>") t t)
652 (setq done t))
654 (if (eobp)
655 (error "Parse error in %s"
656 (file-name-nondirectory buffer-file-name)))
657 (unless open-td
658 (setq done t))))
659 (forward-line 1)))))
662 (defconst make-manuals-dist-output-variables
663 `(("@\\(top_\\)?srcdir@" . ".") ; top_srcdir is wrong, but not used
664 ("^\\(\\(?:texinfo\\|buildinfo\\|emacs\\)dir *=\\).*" . "\\1 .")
665 ("^\\(clean:.*\\)" . "\\1 infoclean")
666 ("@MAKEINFO@" . "makeinfo")
667 ("@MKDIR_P@" . "mkdir -p")
668 ("@INFO_EXT@" . ".info")
669 ("@INFO_OPTS@" . "")
670 ("@SHELL@" . "/bin/bash")
671 ("@prefix@" . "/usr/local")
672 ("@datarootdir@" . "${prefix}/share")
673 ("@datadir@" . "${datarootdir}")
674 ("@PACKAGE_TARNAME@" . "emacs")
675 ("@docdir@" . "${datarootdir}/doc/${PACKAGE_TARNAME}")
676 ("@\\(dvi\\|html\\|pdf\\|ps\\)dir@" . "${docdir}")
677 ("@GZIP_PROG@" . "gzip")
678 ("@INSTALL@" . "install -c")
679 ("@INSTALL_DATA@" . "${INSTALL} -m 644")
680 ("@configure_input@" . "")
681 ("@AM_DEFAULT_VERBOSITY@" . "0")
682 ("@AM_V@" . "${V}")
683 ("@AM_DEFAULT_V@" . "${AM_DEFAULT_VERBOSITY}"))
684 "Alist of (REGEXP . REPLACEMENT) pairs for `make-manuals-dist'.")
686 (defun make-manuals-dist--1 (root type)
687 "Subroutine of `make-manuals-dist'."
688 (let* ((dest (expand-file-name "manual" root))
689 (default-directory (progn (make-directory dest t)
690 (file-name-as-directory dest)))
691 (version (with-temp-buffer
692 (insert-file-contents "../doc/emacs/emacsver.texi")
693 (re-search-forward "@set EMACSVER \\([0-9.]+\\)")
694 (match-string 1)))
695 (stem (format "emacs-%s-%s" (if (equal type "emacs") "manual" type)
696 version))
697 (tarfile (format "%s.tar" stem)))
698 (message "Doing %s..." type)
699 (if (file-directory-p stem)
700 (delete-directory stem t))
701 (make-directory stem)
702 (setq stem (file-name-as-directory stem))
703 (copy-file "../doc/misc/texinfo.tex" stem)
704 (unless (equal type "emacs")
705 (copy-file "../doc/emacs/emacsver.texi" stem)
706 (copy-file "../doc/emacs/docstyle.texi" stem))
707 (dolist (file (directory-files (format "../doc/%s" type) t))
708 (if (or (string-match-p "\\(\\.texi\\'\\|/README\\'\\)" file)
709 (and (equal type "lispintro")
710 (string-match-p "\\.\\(eps\\|pdf\\)\\'" file)))
711 (copy-file file stem)))
712 (with-temp-buffer
713 (let ((outvars make-manuals-dist-output-variables))
714 (push `("@version@" . ,version) outvars)
715 (insert-file-contents (format "../doc/%s/Makefile.in" type))
716 (dolist (cons outvars)
717 (while (re-search-forward (car cons) nil t)
718 (replace-match (cdr cons) t))
719 (goto-char (point-min))))
720 (let (ats)
721 (while (re-search-forward "@[a-zA-Z_]+@" nil t)
722 (setq ats t)
723 (message "Unexpanded: %s" (match-string 0)))
724 (if ats (error "Unexpanded configure variables in Makefile?")))
725 (write-region nil nil (expand-file-name (format "%sMakefile" stem))
726 nil 'silent))
727 (call-process "tar" nil nil nil "-cf" tarfile stem)
728 (delete-directory stem t)
729 (message "...created %s" tarfile)))
731 ;; Does anyone actually use these tarfiles?
732 (defun make-manuals-dist (root &optional type)
733 "Make the standalone manual source tarfiles for the Emacs webpage.
734 ROOT should be the root of an Emacs source tree.
735 Interactively with a prefix argument, prompt for TYPE.
736 Optional argument TYPE is type of output (nil means all)."
737 (interactive (let ((root
738 (if noninteractive
739 (or (pop command-line-args-left)
740 default-directory)
741 (read-directory-name "Emacs root directory: "
742 source-directory nil t))))
743 (list root
744 (if current-prefix-arg
745 (completing-read
746 "Type: "
747 '("emacs" "lispref" "lispintro" "misc"))))))
748 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
749 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
750 (dolist (m '("emacs" "lispref" "lispintro" "misc"))
751 (if (member type (list nil m))
752 (make-manuals-dist--1 root m))))
755 ;; Stuff to check new `defcustom's got :version tags.
756 ;; Adapted from check-declare.el.
758 (defun cusver-find-files (root &optional old)
759 "Find .el files beneath directory ROOT that contain `defcustom's.
760 If optional OLD is non-nil, also include `defvar's."
761 (process-lines find-program root
762 "-name" "*.el"
763 "-exec" grep-program
764 "-l" "-E" (format "^[ \\t]*\\(def%s"
765 (if old "(custom|var)"
766 "custom"
768 "{}" "+"))
770 (defvar cusver-new-version (format "%s.%s" emacs-major-version
771 (1+ emacs-minor-version))
772 "Version number that new `defcustom's should have.")
774 (defun cusver-scan (file &optional old)
775 "Scan FILE for `defcustom' calls.
776 Return a list with elements of the form (VAR . VER),
777 This means that FILE contains a defcustom for variable VAR, with
778 a :version tag having value VER (may be nil).
779 If optional argument OLD is non-nil, also scan for `defvar's."
780 (let ((m (format "Scanning %s..." file))
781 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
782 (if old "\\(custom\\|var\\)" "\\(custom\\|group\\)")))
783 alist var ver form glist grp)
784 (message "%s" m)
785 (with-temp-buffer
786 (insert-file-contents file)
787 ;; FIXME we could theoretically be inside a string.
788 (while (re-search-forward re nil :noerror)
789 (goto-char (match-beginning 1))
790 (if (and (setq form (ignore-errors (read (current-buffer))))
791 (setq var (car-safe (cdr-safe form)))
792 ;; Exclude macros, eg (defcustom ,varname ...).
793 (symbolp var))
794 (progn
795 ;; FIXME It should be cus-test-apropos that does this.
796 (and (not old)
797 (equal "custom" (match-string 2))
798 (not (memq :type form))
799 (display-warning
800 'custom (format-message "Missing type in: `%s'" form)))
801 (setq ver (car (cdr-safe (memq :version form))))
802 (if (equal "group" (match-string 2))
803 ;; Group :version could be old.
804 (if (equal ver cusver-new-version)
805 (setq glist (cons (cons var ver) glist)))
806 ;; If it specifies a group and the whole group has a
807 ;; version. use that.
808 (unless ver
809 (setq grp (car (cdr-safe (memq :group form))))
810 (and grp
811 (setq grp (car (cdr-safe grp))) ; (quote foo) -> foo
812 (setq ver (assq grp glist))))
813 (setq alist (cons (cons var ver) alist))))
814 (if form (format-message "Malformed defcustom: `%s'" form)))))
815 (message "%sdone" m)
816 alist))
818 (defun cusver-scan-cus-start (file)
819 "Scan cus-start.el and return an alist with elements (VAR . VER)."
820 (if (file-readable-p file)
821 (with-temp-buffer
822 (insert-file-contents file)
823 (when (search-forward "(let ((all '(" nil t)
824 (backward-char 1)
825 (let (var ver alist)
826 (dolist (elem (ignore-errors (read (current-buffer))))
827 (when (symbolp (setq var (car-safe elem)))
828 (or (stringp (setq ver (nth 3 elem)))
829 (setq ver nil))
830 (setq alist (cons (cons var ver) alist))))
831 alist)))))
833 (define-button-type 'cusver-xref 'action #'cusver-goto-xref)
835 (defun cusver-goto-xref (button)
836 "Jump to a Lisp file for the BUTTON at point."
837 (let ((file (button-get button 'file))
838 (var (button-get button 'var)))
839 (if (not (file-readable-p file))
840 (message "Cannot read `%s'" file)
841 (with-current-buffer (find-file-noselect file)
842 (goto-char (point-min))
843 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
844 (message "Unable to locate defcustom"))
845 (pop-to-buffer (current-buffer))))))
847 ;; You should probably at least do a grep over the old directory
848 ;; to check the results of this look sensible.
849 ;; TODO Check cus-start if something moved from C to Lisp.
850 ;; TODO Handle renamed things with aliases to the old names.
851 (defun cusver-check (newdir olddir version)
852 "Check that `defcustom's have :version tags where needed.
853 NEWDIR is the current lisp/ directory, OLDDIR is that from the
854 previous release, VERSION is the new version number. A
855 `defcustom' that is only in NEWDIR should have a :version tag.
856 We exclude cases where a `defvar' exists in OLDDIR, since just
857 converting a `defvar' to a `defcustom' does not require
858 a :version bump.
860 Note that a :version tag should also be added if the value of a defcustom
861 changes (in a non-trivial way). This function does not check for that."
862 (interactive (list (read-directory-name "New Lisp directory: " nil nil t)
863 (read-directory-name "Old Lisp directory: " nil nil t)
864 (number-to-string
865 (read-number "New version number: "
866 (string-to-number cusver-new-version)))))
867 (or (file-directory-p (setq newdir (expand-file-name newdir)))
868 (user-error "Directory `%s' not found" newdir))
869 (or (file-directory-p (setq olddir (expand-file-name olddir)))
870 (user-error "Directory `%s' not found" olddir))
871 (setq cusver-new-version version)
872 (let* ((newfiles (progn (message "Finding new files with `defcustom's...")
873 (cusver-find-files newdir)))
874 (oldfiles (progn (message "Finding old files with `defcustom's...")
875 (cusver-find-files olddir t)))
876 (newcus (progn (message "Reading new `defcustom's...")
877 (mapcar
878 (lambda (file)
879 (cons file (cusver-scan file))) newfiles)))
880 oldcus result thisfile file)
881 (message "Reading old `defcustom's...")
882 (dolist (file oldfiles)
883 (setq oldcus (append oldcus (cusver-scan file t))))
884 (setq oldcus (append oldcus (cusver-scan-cus-start
885 (expand-file-name "cus-start.el" olddir))))
886 ;; newcus has elements (FILE (VAR VER) ... ).
887 ;; oldcus just (VAR . VER).
888 (message "Checking for version tags...")
889 (dolist (new newcus)
890 (setq file (car new)
891 thisfile
892 (let (missing var)
893 (dolist (cons (cdr new))
894 (or (cdr cons)
895 (assq (setq var (car cons)) oldcus)
896 (push var missing)))
897 (if missing
898 (cons file missing))))
899 (if thisfile
900 (setq result (cons thisfile result))))
901 (message "Checking for version tags... done")
902 (if (not result)
903 (message "No missing :version tags")
904 (pop-to-buffer "*cusver*")
905 (erase-buffer)
906 (insert (substitute-command-keys
907 "These `defcustom's might be missing :version tags:\n\n"))
908 (dolist (elem result)
909 (let* ((str (file-relative-name (car elem) newdir))
910 (strlen (length str)))
911 (dolist (var (cdr elem))
912 (insert (format "%s: %s\n" str var))
913 (make-text-button (+ (line-beginning-position 0) strlen 2)
914 (line-end-position 0)
915 'file (car elem)
916 'var var
917 'help-echo "Mouse-2: visit this definition"
918 :type 'cusver-xref)))))))
920 (provide 'admin)
922 ;;; admin.el ends here
924 ;; Local Variables:
925 ;; coding: utf-8
926 ;; End: