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