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