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